Skip to content

Commit

Permalink
Move DecodeStashingImageProvider into its own file.
Browse files Browse the repository at this point in the history
This lets it be used outside of ScopedImageFlags. OOP raster will use
this more generally during serialization.

Bug: 777628
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: Ie1bd3dda646d6094601050263560578d4a96b09f
Reviewed-on: https://chromium-review.googlesource.com/815897
Reviewed-by: vmpstr <vmpstr@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523216}
  • Loading branch information
Eric Karl authored and Commit Bot committed Dec 11, 2017
1 parent bf71398 commit f579c56
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 43 deletions.
2 changes: 2 additions & 0 deletions cc/paint/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import("//testing/libfuzzer/fuzzer_test.gni")
cc_component("paint") {
output_name = "cc_paint"
sources = [
"decode_stashing_image_provider.cc",
"decode_stashing_image_provider.h",
"decoded_draw_image.cc",
"decoded_draw_image.h",
"discardable_image_map.cc",
Expand Down
28 changes: 28 additions & 0 deletions cc/paint/decode_stashing_image_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/paint/decode_stashing_image_provider.h"

namespace cc {
DecodeStashingImageProvider::DecodeStashingImageProvider(
ImageProvider* source_provider)
: source_provider_(source_provider) {
DCHECK(source_provider_);
}
DecodeStashingImageProvider::~DecodeStashingImageProvider() = default;

ImageProvider::ScopedDecodedDrawImage
DecodeStashingImageProvider::GetDecodedDrawImage(const DrawImage& draw_image) {
auto decode = source_provider_->GetDecodedDrawImage(draw_image);
if (!decode)
return ScopedDecodedDrawImage();

// No need to add any destruction callback to the returned image. The images
// decoded here match the lifetime of this provider.
auto image_to_return = ScopedDecodedDrawImage(decode.decoded_image());
decoded_images_->push_back(std::move(decode));
return image_to_return;
}

} // namespace cc
34 changes: 34 additions & 0 deletions cc/paint/decode_stashing_image_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_
#define CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_

#include "base/containers/stack_container.h"
#include "cc/paint/image_provider.h"

namespace cc {
// An ImageProvider that passes decode requests through to the
// |source_provider| but keeps the decode cached throughtout its lifetime,
// instead of passing the ref to the caller.
class DecodeStashingImageProvider : public ImageProvider {
public:
// |source_provider| must outlive this class.
explicit DecodeStashingImageProvider(ImageProvider* source_provider);
~DecodeStashingImageProvider() override;

// ImageProvider implementation.
ScopedDecodedDrawImage GetDecodedDrawImage(
const DrawImage& draw_image) override;

private:
ImageProvider* source_provider_;
base::StackVector<ScopedDecodedDrawImage, 1> decoded_images_;

DISALLOW_COPY_AND_ASSIGN(DecodeStashingImageProvider);
};

} // namespace cc

#endif // CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_
22 changes: 0 additions & 22 deletions cc/paint/scoped_raster_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@
#include "cc/paint/paint_image_builder.h"

namespace cc {
ScopedRasterFlags::DecodeStashingImageProvider::DecodeStashingImageProvider(
ImageProvider* source_provider)
: source_provider_(source_provider) {
DCHECK(source_provider_);
}
ScopedRasterFlags::DecodeStashingImageProvider::~DecodeStashingImageProvider() =
default;

ImageProvider::ScopedDecodedDrawImage
ScopedRasterFlags::DecodeStashingImageProvider::GetDecodedDrawImage(
const DrawImage& draw_image) {
auto decode = source_provider_->GetDecodedDrawImage(draw_image);
if (!decode)
return ScopedDecodedDrawImage();

// No need to add any destruction callback to the returned image. The images
// decoded here match the lifetime of this provider.
auto image_to_return = ScopedDecodedDrawImage(decode.decoded_image());
decoded_images_->push_back(std::move(decode));
return image_to_return;
}

ScopedRasterFlags::ScopedRasterFlags(const PaintFlags* flags,
ImageProvider* image_provider,
const SkMatrix& ctm,
Expand Down
22 changes: 1 addition & 21 deletions cc/paint/scoped_raster_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "base/containers/stack_container.h"
#include "base/macros.h"
#include "cc/paint/image_provider.h"
#include "cc/paint/decode_stashing_image_provider.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/paint_flags.h"

Expand All @@ -34,26 +34,6 @@ class CC_PAINT_EXPORT ScopedRasterFlags {
}

private:
// An ImageProvider that passes decode requests through to the
// |source_provider| but keeps the decode cached throughtout its lifetime,
// instead of passing the ref to the caller.
class DecodeStashingImageProvider : public ImageProvider {
public:
// |source_provider| must outlive this class.
explicit DecodeStashingImageProvider(ImageProvider* source_provider);
~DecodeStashingImageProvider() override;

// ImageProvider implementation.
ScopedDecodedDrawImage GetDecodedDrawImage(
const DrawImage& draw_image) override;

private:
ImageProvider* source_provider_;
base::StackVector<ScopedDecodedDrawImage, 1> decoded_images_;

DISALLOW_COPY_AND_ASSIGN(DecodeStashingImageProvider);
};

void DecodeImageShader(const SkMatrix& ctm);
void DecodeRecordShader(const SkMatrix& ctm);
void AdjustStrokeIfNeeded(const SkMatrix& ctm);
Expand Down

0 comments on commit f579c56

Please sign in to comment.