Add paint_worklet_input_ to cc::PaintImage
When Blink paints, it will create an Image if it is by CSS Paint.
When this image is embedded in a display item list and passed to cc,
it would be a cc::PaintImage.
This CL makes a cc::PaintImage keeps a scoped_refptr to a PaintWorkletInput,
which contains all the input parameters that are necessary to execute
JS paint callbacks. Note that the PaintWorkletInput is a pure interface,
so for testing purpose, we create a class TestPaintWorkletInput.
Bug: 907897
Change-Id: I5f8562eaaf747fc6da723de11f0d668027f4469d
Reviewed-on: https://chromium-review.googlesource.com/c/1348259
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Reviewed-by: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614064}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index 1c7b04e..4c0382a62 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -297,7 +297,6 @@
"trees/layer_tree_impl.h",
"trees/layer_tree_mutator.cc",
"trees/layer_tree_mutator.h",
- "trees/layer_tree_painter.h",
"trees/layer_tree_settings.cc",
"trees/layer_tree_settings.h",
"trees/managed_memory_policy.cc",
@@ -496,6 +495,8 @@
"test/test_occlusion_tracker.h",
"test/test_options_provider.cc",
"test/test_options_provider.h",
+ "test/test_paint_worklet_input.cc",
+ "test/test_paint_worklet_input.h",
"test/test_skcanvas.cc",
"test/test_skcanvas.h",
"test/test_task_graph_runner.cc",
diff --git a/cc/paint/BUILD.gn b/cc/paint/BUILD.gn
index 21c6b8b..725747a 100644
--- a/cc/paint/BUILD.gn
+++ b/cc/paint/BUILD.gn
@@ -31,6 +31,7 @@
"image_provider.h",
"image_transfer_cache_entry.cc",
"image_transfer_cache_entry.h",
+ "layer_tree_painter.h",
"paint_cache.cc",
"paint_cache.h",
"paint_canvas.h",
diff --git a/cc/paint/discardable_image_map_unittest.cc b/cc/paint/discardable_image_map_unittest.cc
index 32ec754..ba62110 100644
--- a/cc/paint/discardable_image_map_unittest.cc
+++ b/cc/paint/discardable_image_map_unittest.cc
@@ -18,6 +18,7 @@
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_recording_source.h"
#include "cc/test/skia_common.h"
+#include "cc/test/test_paint_worklet_input.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkGraphics.h"
@@ -881,6 +882,19 @@
ImageAnalysisState::kAnimatedImages);
}
+TEST_F(DiscardableImageMapTest, BuildPaintWorkletImage) {
+ gfx::SizeF size(100, 50);
+ scoped_refptr<TestPaintWorkletInput> input =
+ base::MakeRefCounted<TestPaintWorkletInput>(size);
+ PaintImage paint_image = PaintImageBuilder::WithDefault()
+ .set_id(1)
+ .set_paint_worklet_input(std::move(input))
+ .TakePaintImage();
+ EXPECT_TRUE(paint_image.paint_worklet_input());
+ EXPECT_EQ(paint_image.width(), size.width());
+ EXPECT_EQ(paint_image.height(), size.height());
+}
+
TEST_F(DiscardableImageMapTest, DecodingModeHintsBasic) {
gfx::Rect visible_rect(100, 100);
PaintImage unspecified_image =
diff --git a/cc/paint/layer_tree_painter.h b/cc/paint/layer_tree_painter.h
new file mode 100644
index 0000000..e8065c8
--- /dev/null
+++ b/cc/paint/layer_tree_painter.h
@@ -0,0 +1,34 @@
+// Copyright 2018 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_LAYER_TREE_PAINTER_H_
+#define CC_PAINT_LAYER_TREE_PAINTER_H_
+
+#include "base/memory/ref_counted.h"
+#include "cc/cc_export.h"
+#include "ui/gfx/geometry/size_f.h"
+
+namespace cc {
+
+// TODO(xidachen): this class should be in its own file.
+class CC_EXPORT PaintWorkletInput
+ : public base::RefCountedThreadSafe<PaintWorkletInput> {
+ public:
+ virtual gfx::SizeF GetSize() const = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<PaintWorkletInput>;
+ virtual ~PaintWorkletInput() = default;
+};
+
+class CC_EXPORT LayerTreePainter {
+ public:
+ virtual ~LayerTreePainter() {}
+
+ // TODO(xidachen) add a PaintWorkletPaint function.
+};
+
+} // namespace cc
+
+#endif // CC_PAINT_LAYER_TREE_PAINTER_H_
diff --git a/cc/paint/paint_image.h b/cc/paint/paint_image.h
index 0684c2d8..e4c8c04 100644
--- a/cc/paint/paint_image.h
+++ b/cc/paint/paint_image.h
@@ -9,8 +9,10 @@
#include "base/gtest_prod_util.h"
#include "base/logging.h"
+#include "base/memory/scoped_refptr.h"
#include "cc/paint/frame_metadata.h"
#include "cc/paint/image_animation_count.h"
+#include "cc/paint/layer_tree_painter.h"
#include "cc/paint/paint_export.h"
#include "third_party/skia/include/core/SkImage.h"
#include "ui/gfx/geometry/rect.h"
@@ -173,13 +175,31 @@
PaintImage::ContentId content_id() const { return content_id_; }
// TODO(vmpstr): Don't get the SkImage here if you don't need to.
- uint32_t unique_id() const { return GetSkImage()->uniqueID(); }
- explicit operator bool() const { return !!GetSkImage(); }
- bool IsLazyGenerated() const { return GetSkImage()->isLazyGenerated(); }
- bool IsTextureBacked() const { return GetSkImage()->isTextureBacked(); }
- int width() const { return GetSkImage()->width(); }
- int height() const { return GetSkImage()->height(); }
- SkColorSpace* color_space() const { return GetSkImage()->colorSpace(); }
+ uint32_t unique_id() const {
+ return paint_worklet_input_ ? 0 : GetSkImage()->uniqueID();
+ }
+ explicit operator bool() const {
+ return paint_worklet_input_ || !!GetSkImage();
+ }
+ bool IsLazyGenerated() const {
+ return paint_worklet_input_ ? false : GetSkImage()->isLazyGenerated();
+ }
+ bool IsTextureBacked() const {
+ return paint_worklet_input_ ? false : GetSkImage()->isTextureBacked();
+ }
+ int width() const {
+ return paint_worklet_input_
+ ? static_cast<int>(paint_worklet_input_->GetSize().width())
+ : GetSkImage()->width();
+ }
+ int height() const {
+ return paint_worklet_input_
+ ? static_cast<int>(paint_worklet_input_->GetSize().height())
+ : GetSkImage()->height();
+ }
+ SkColorSpace* color_space() const {
+ return paint_worklet_input_ ? nullptr : GetSkImage()->colorSpace();
+ }
// Returns the color type of this image.
SkColorType GetColorType() const;
@@ -198,6 +218,10 @@
sk_sp<SkImage> GetSkImageForFrame(size_t index,
GeneratorClientId client_id) const;
+ PaintWorkletInput* paint_worklet_input() {
+ return paint_worklet_input_.get();
+ }
+
std::string ToString() const;
private:
@@ -260,6 +284,9 @@
// skia's cache.
// 2) Ensures that accesses to it are thread-safe.
sk_sp<SkImage> cached_sk_image_;
+
+ // The input parameters that are needed to execute the JS paint callback.
+ scoped_refptr<PaintWorkletInput> paint_worklet_input_;
};
} // namespace cc
diff --git a/cc/paint/paint_image_builder.cc b/cc/paint/paint_image_builder.cc
index d6741c1..d8b3199f 100644
--- a/cc/paint/paint_image_builder.cc
+++ b/cc/paint/paint_image_builder.cc
@@ -45,6 +45,7 @@
DCHECK(!paint_image_.paint_record_);
DCHECK(!paint_image_.paint_image_generator_);
DCHECK(!paint_image_.sk_image_->isLazyGenerated());
+ DCHECK(!paint_image_.paint_worklet_input_);
// TODO(khushalsagar): Assert that we don't have an animated image type
// here. The only case where this is possible is DragImage. There are 2 use
// cases going through that path, re-orienting the image and for use by the
@@ -55,11 +56,17 @@
} else if (paint_image_.paint_record_) {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_image_generator_);
+ DCHECK(!paint_image_.paint_worklet_input_);
// TODO(khushalsagar): Assert that we don't have an animated image type
// here.
} else if (paint_image_.paint_image_generator_) {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_record_);
+ DCHECK(!paint_image_.paint_worklet_input_);
+ } else if (paint_image_.paint_worklet_input_) {
+ DCHECK(!paint_image_.sk_image_);
+ DCHECK(!paint_image_.paint_record_);
+ DCHECK(!paint_image_.paint_image_generator_);
}
if (paint_image_.ShouldAnimate()) {
diff --git a/cc/paint/paint_image_builder.h b/cc/paint/paint_image_builder.h
index d127050..52e7ec8 100644
--- a/cc/paint/paint_image_builder.h
+++ b/cc/paint/paint_image_builder.h
@@ -98,6 +98,11 @@
paint_image_.decoding_mode_ = decoding_mode;
return std::move(*this);
}
+ PaintImageBuilder&& set_paint_worklet_input(
+ scoped_refptr<PaintWorkletInput> input) {
+ paint_image_.paint_worklet_input_ = std::move(input);
+ return std::move(*this);
+ }
PaintImage TakePaintImage();
diff --git a/cc/test/test_paint_worklet_input.cc b/cc/test/test_paint_worklet_input.cc
new file mode 100644
index 0000000..85a8671
--- /dev/null
+++ b/cc/test/test_paint_worklet_input.cc
@@ -0,0 +1,13 @@
+// Copyright 2018 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/test/test_paint_worklet_input.h"
+
+namespace cc {
+
+gfx::SizeF TestPaintWorkletInput::GetSize() const {
+ return container_size_;
+}
+
+} // namespace cc
diff --git a/cc/test/test_paint_worklet_input.h b/cc/test/test_paint_worklet_input.h
new file mode 100644
index 0000000..2b06b32e
--- /dev/null
+++ b/cc/test/test_paint_worklet_input.h
@@ -0,0 +1,27 @@
+// Copyright 2018 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_TEST_TEST_PAINT_WORKLET_INPUT_H_
+#define CC_TEST_TEST_PAINT_WORKLET_INPUT_H_
+
+#include "cc/paint/layer_tree_painter.h"
+
+namespace cc {
+
+class TestPaintWorkletInput : public PaintWorkletInput {
+ public:
+ explicit TestPaintWorkletInput(const gfx::SizeF& size)
+ : container_size_(size) {}
+ gfx::SizeF GetSize() const override;
+
+ protected:
+ ~TestPaintWorkletInput() override = default;
+
+ private:
+ gfx::SizeF container_size_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_PAINT_WORKLET_INPUT_H_
diff --git a/cc/trees/layer_tree_painter.h b/cc/trees/layer_tree_painter.h
deleted file mode 100644
index f857074..0000000
--- a/cc/trees/layer_tree_painter.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 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_TREES_LAYER_TREE_PAINTER_H_
-#define CC_TREES_LAYER_TREE_PAINTER_H_
-
-#include "cc/cc_export.h"
-
-namespace cc {
-
-class PaintWorkletInput {
- public:
- virtual ~PaintWorkletInput() {}
-};
-
-class CC_EXPORT LayerTreePainter {
- public:
- virtual ~LayerTreePainter() {}
-
- // TODO(xidachen) add a PaintWorkletPaint function.
-};
-
-} // namespace cc
-
-#endif // CC_TREES_LAYER_TREE_PAINTER_H_