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 | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 14 | #include "ui/gfx/geometry/rect_f.h" |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 15 | |
| 16 | namespace cc { |
| 17 | class UIResourceLayer; |
| 18 | } |
| 19 | |
| 20 | namespace cc::slim { |
| 21 | |
| 22 | // Layer which to draws the contents of a single UIResource. |
| 23 | class COMPONENT_EXPORT(CC_SLIM) UIResourceLayer : public Layer { |
| 24 | public: |
| 25 | static scoped_refptr<UIResourceLayer> Create(); |
| 26 | |
| 27 | // Sets the resource. If they don't exist already, the shared UI resource and |
| 28 | // ID are generated and cached in a map in the associated UIResourceManager. |
| 29 | // Currently, this resource will never be released by the UIResourceManager. |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 30 | void SetUIResourceId(cc::UIResourceId id); |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 31 | |
| 32 | // An alternative way of setting the resource where an ID is used directly. If |
| 33 | // you use this method, you are responsible for updating the ID if the layer |
| 34 | // moves between compositors. |
| 35 | void SetBitmap(const SkBitmap& bitmap); |
| 36 | |
| 37 | // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). |
| 38 | void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right); |
| 39 | |
| 40 | // Sets an opacity value per vertex. It will be multiplied by the layer |
| 41 | // opacity value. |
| 42 | void SetVertexOpacity(float bottom_left, |
| 43 | float top_left, |
| 44 | float top_right, |
| 45 | float bottom_right); |
| 46 | |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 47 | // Layer implementation. |
| 48 | void SetLayerTree(LayerTree* tree) override; |
| 49 | |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 50 | protected: |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 51 | FRIEND_TEST_ALL_PREFIXES(SlimLayerTest, UIResourceLayerProperties); |
| 52 | |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 53 | explicit UIResourceLayer(scoped_refptr<cc::UIResourceLayer> cc_layer); |
| 54 | ~UIResourceLayer() override; |
| 55 | |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 56 | cc::UIResourceId resource_id() const { return resource_id_; } |
| 57 | auto uv_top_left() const { return uv_.origin(); } |
| 58 | auto uv_bottom_right() const { return uv_.bottom_right(); } |
| 59 | const auto& vertex_opacity() const { return vertex_opacity_; } |
| 60 | |
| 61 | bool HasDrawableContent() const override; |
| 62 | |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 63 | private: |
| 64 | cc::UIResourceLayer* cc_layer() const; |
Bo Liu | 292429d | 2023-02-10 19:24:41 | [diff] [blame^] | 65 | void RefreshResource(); |
| 66 | void SetUIResourceIdInternal(cc::UIResourceId resource_id); |
| 67 | |
| 68 | cc::UIResourceId resource_id_ = 0; |
| 69 | SkBitmap bitmap_; |
| 70 | gfx::RectF uv_; |
| 71 | float vertex_opacity_[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
Bo Liu | eb64cd1 | 2023-01-27 23:14:29 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace cc::slim |
| 75 | |
| 76 | #endif // CC_SLIM_UI_RESOURCE_LAYER_H_ |