[go: nahoru, domu]

blob: 1bf01c3e24cf277dbfb0ad9ced49a19a05e9b8b5 [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 Liu292429d2023-02-10 19:24:4114#include "ui/gfx/geometry/rect_f.h"
Bo Liueb64cd12023-01-27 23:14:2915
16namespace cc {
17class UIResourceLayer;
18}
19
20namespace cc::slim {
21
22// Layer which to draws the contents of a single UIResource.
23class 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 Liu292429d2023-02-10 19:24:4130 void SetUIResourceId(cc::UIResourceId id);
Bo Liueb64cd12023-01-27 23:14:2931
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 Liu292429d2023-02-10 19:24:4147 // Layer implementation.
48 void SetLayerTree(LayerTree* tree) override;
49
Bo Liueb64cd12023-01-27 23:14:2950 protected:
Bo Liu292429d2023-02-10 19:24:4151 FRIEND_TEST_ALL_PREFIXES(SlimLayerTest, UIResourceLayerProperties);
52
Bo Liueb64cd12023-01-27 23:14:2953 explicit UIResourceLayer(scoped_refptr<cc::UIResourceLayer> cc_layer);
54 ~UIResourceLayer() override;
55
Bo Liu292429d2023-02-10 19:24:4156 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 Liueb64cd12023-01-27 23:14:2963 private:
64 cc::UIResourceLayer* cc_layer() const;
Bo Liu292429d2023-02-10 19:24:4165 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 Liueb64cd12023-01-27 23:14:2972};
73
74} // namespace cc::slim
75
76#endif // CC_SLIM_UI_RESOURCE_LAYER_H_