[go: nahoru, domu]

blob: eba2a9ec8bbcdefb4b0f69f0f15227a24af174ca [file] [log] [blame]
Bo Liueb64cd12023-01-27 23:14:291// 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 Liu292429d2023-02-10 19:24:419#include "base/gtest_prod_util.h"
10#include "cc/resources/ui_resource_client.h"
Bo Liueb64cd12023-01-27 23:14:2911#include "cc/slim/layer.h"
12#include "third_party/skia/include/core/SkBitmap.h"
13#include "ui/gfx/geometry/point_f.h"
Bo Liueb64cd12023-01-27 23:14:2914
15namespace cc::slim {
16
17// Layer which to draws the contents of a single UIResource.
18class 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 Liu292429d2023-02-10 19:24:4125 void SetUIResourceId(cc::UIResourceId id);
Bo Liueb64cd12023-01-27 23:14:2926
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 Liu292429d2023-02-10 19:24:4142 // Layer implementation.
43 void SetLayerTree(LayerTree* tree) override;
44
Bo Liueb64cd12023-01-27 23:14:2945 protected:
Bo Liu292429d2023-02-10 19:24:4146 FRIEND_TEST_ALL_PREFIXES(SlimLayerTest, UIResourceLayerProperties);
47
Bo Liu149c1892024-02-13 22:16:2548 UIResourceLayer();
Bo Liueb64cd12023-01-27 23:14:2949 ~UIResourceLayer() override;
50
Bo Liu292429d2023-02-10 19:24:4151 cc::UIResourceId resource_id() const { return resource_id_; }
Bo Liub1943c42023-04-05 18:01:3252 auto uv_top_left() const { return uv_top_left_; }
53 auto uv_bottom_right() const { return uv_bottom_right_; }
Bo Liu292429d2023-02-10 19:24:4154 const auto& vertex_opacity() const { return vertex_opacity_; }
55
56 bool HasDrawableContent() const override;
Bo Liu84fe45d2023-02-21 16:33:3757 void AppendQuads(viz::CompositorRenderPass& render_pass,
Bo Liu4fdd8be2023-02-24 16:37:5558 FrameData& data,
Bo Liuc94996e2023-03-13 15:56:2459 const gfx::Transform& transform_to_root,
60 const gfx::Transform& transform_to_target,
Bo Liudca1a9182023-03-03 19:27:4261 const gfx::Rect* clip_in_target,
Bo Liue5dbd7c2023-03-14 16:58:4962 const gfx::Rect& visible_rect,
63 float opacity) override;
Bo Liu292429d2023-02-10 19:24:4164
Bo Liueb64cd12023-01-27 23:14:2965 private:
Bo Liu292429d2023-02-10 19:24:4166 void RefreshResource();
67 void SetUIResourceIdInternal(cc::UIResourceId resource_id);
68
69 cc::UIResourceId resource_id_ = 0;
70 SkBitmap bitmap_;
Bo Liub1943c42023-04-05 18:01:3271 gfx::PointF uv_top_left_;
72 gfx::PointF uv_bottom_right_{1.0f, 1.0f};
Bo Liu292429d2023-02-10 19:24:4173 float vertex_opacity_[4] = {1.0f, 1.0f, 1.0f, 1.0f};
Bo Liueb64cd12023-01-27 23:14:2974};
75
76} // namespace cc::slim
77
78#endif // CC_SLIM_UI_RESOURCE_LAYER_H_