diff --git a/cc/paint/BUILD.gn b/cc/paint/BUILD.gn index 7aaadb9b6ff96e..8cb71417fd2c08 100644 --- a/cc/paint/BUILD.gn +++ b/cc/paint/BUILD.gn @@ -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", diff --git a/cc/paint/decode_stashing_image_provider.cc b/cc/paint/decode_stashing_image_provider.cc new file mode 100644 index 00000000000000..8b8c462970785b --- /dev/null +++ b/cc/paint/decode_stashing_image_provider.cc @@ -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 diff --git a/cc/paint/decode_stashing_image_provider.h b/cc/paint/decode_stashing_image_provider.h new file mode 100644 index 00000000000000..6ca0a75210fb9d --- /dev/null +++ b/cc/paint/decode_stashing_image_provider.h @@ -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 decoded_images_; + + DISALLOW_COPY_AND_ASSIGN(DecodeStashingImageProvider); +}; + +} // namespace cc + +#endif // CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_ diff --git a/cc/paint/scoped_raster_flags.cc b/cc/paint/scoped_raster_flags.cc index deb5ee8ca4589b..bd6b75b97b93a2 100644 --- a/cc/paint/scoped_raster_flags.cc +++ b/cc/paint/scoped_raster_flags.cc @@ -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, diff --git a/cc/paint/scoped_raster_flags.h b/cc/paint/scoped_raster_flags.h index 159b4d488244a2..ad2ab88753e24e 100644 --- a/cc/paint/scoped_raster_flags.h +++ b/cc/paint/scoped_raster_flags.h @@ -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" @@ -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 decoded_images_; - - DISALLOW_COPY_AND_ASSIGN(DecodeStashingImageProvider); - }; - void DecodeImageShader(const SkMatrix& ctm); void DecodeRecordShader(const SkMatrix& ctm); void AdjustStrokeIfNeeded(const SkMatrix& ctm);