Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CC_SLIM_UI_RESOURCE_LAYER_H_ |
| 6 | #define CC_SLIM_UI_RESOURCE_LAYER_H_ |
| 7 | |
| 8 | #include "base/component_export.h" |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 9 | #include "base/gtest_prod_util.h" |
| 10 | #include "cc/resources/ui_resource_client.h" |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 11 | #include "cc/slim/layer.h" |
| 12 | #include "third_party/skia/include/core/SkBitmap.h" |
| 13 | #include "ui/gfx/geometry/point_f.h" |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 14 | |
| 15 | namespace cc::slim { |
| 16 | |
| 17 | // Layer which to draws the contents of a single UIResource. |
| 18 | class COMPONENT_EXPORT(CC_SLIM) UIResourceLayer : public Layer { |
| 19 | public: |
| 20 | static scoped_refptr<UIResourceLayer> Create(); |
| 21 | |
| 22 | // Sets the resource. If they don't exist already, the shared UI resource and |
| 23 | // ID are generated and cached in a map in the associated UIResourceManager. |
| 24 | // Currently, this resource will never be released by the UIResourceManager. |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 25 | void SetUIResourceId(cc::UIResourceId id); |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 26 | |
| 27 | // An alternative way of setting the resource where an ID is used directly. If |
| 28 | // you use this method, you are responsible for updating the ID if the layer |
| 29 | // moves between compositors. |
| 30 | void SetBitmap(const SkBitmap& bitmap); |
| 31 | |
| 32 | // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). |
| 33 | void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right); |
| 34 | |
| 35 | // Sets an opacity value per vertex. It will be multiplied by the layer |
| 36 | // opacity value. |
| 37 | void SetVertexOpacity(float bottom_left, |
| 38 | float top_left, |
| 39 | float top_right, |
| 40 | float bottom_right); |
| 41 | |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 42 | // Layer implementation. |
| 43 | void SetLayerTree(LayerTree* tree) override; |
| 44 | |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 45 | protected: |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 46 | FRIEND_TEST_ALL_PREFIXES(SlimLayerTest, UIResourceLayerProperties); |
| 47 | |
Bo Liu | 149c189 | 2024-02-13 22:16:25 | [diff] [blame] | 48 | UIResourceLayer(); |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 49 | ~UIResourceLayer() override; |
| 50 | |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 51 | cc::UIResourceId resource_id() const { return resource_id_; } |
Bo Liu | b1943c4 | 2023-04-05 18:01:32 | [diff] [blame] | 52 | auto uv_top_left() const { return uv_top_left_; } |
| 53 | auto uv_bottom_right() const { return uv_bottom_right_; } |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 54 | const auto& vertex_opacity() const { return vertex_opacity_; } |
| 55 | |
| 56 | bool HasDrawableContent() const override; |
Bo Liu | 84fe45d | 2023-02-21 16:33:37 | [diff] [blame] | 57 | void AppendQuads(viz::CompositorRenderPass& render_pass, |
Bo Liu | 4fdd8be | 2023-02-24 16:37:55 | [diff] [blame] | 58 | FrameData& data, |
Bo Liu | c94996e | 2023-03-13 15:56:24 | [diff] [blame] | 59 | const gfx::Transform& transform_to_root, |
| 60 | const gfx::Transform& transform_to_target, |
Bo Liu | dca1a918 | 2023-03-03 19:27:42 | [diff] [blame] | 61 | const gfx::Rect* clip_in_target, |
Bo Liu | e5dbd7c | 2023-03-14 16:58:49 | [diff] [blame] | 62 | const gfx::Rect& visible_rect, |
| 63 | float opacity) override; |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 64 | |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 65 | private: |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 66 | void RefreshResource(); |
| 67 | void SetUIResourceIdInternal(cc::UIResourceId resource_id); |
| 68 | |
| 69 | cc::UIResourceId resource_id_ = 0; |
| 70 | SkBitmap bitmap_; |
Bo Liu | b1943c4 | 2023-04-05 18:01:32 | [diff] [blame] | 71 | gfx::PointF uv_top_left_; |
| 72 | gfx::PointF uv_bottom_right_{1.0f, 1.0f}; |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame] | 73 | float vertex_opacity_[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace cc::slim |
| 77 | |
| 78 | #endif // CC_SLIM_UI_RESOURCE_LAYER_H_ |