[go: nahoru, domu]

Add cc/slim compositor wrapping cc

Initial version contains only wrappers for cc types.
The types and method names are copied from cc types.

LayerTree and FrameSink are pure virtual interfaces with a CcWrapper
subclass implementations that just forwards calls. Note lower_case
accessor methods that are normally inlined are virtual as well; did not
update these method names to avoid unnecessary churn later.

Different Layer types directly wrap cc Layer types instead of having
pure interfaces and implementation subclasses. This is to avoid diamond
inheritance. Consider something like SolidColorLayerCcWrapper, which
needs to inherit from LayerCcWrapper and SolidColorLayer (pure
interface); both of these inherit from Layer (pure interface). Virtual
inheritance is needed to avoid 2 copies of Layer, but then it's no
longer possible to downcast using dynamic_cast without RTTI.

Layer has its own implementation to keep track of parent/child
relationship. This is to avoid modifying cc types when implementing
things like Layer::parent.

There are some implementation taken from parts of the Android browser
compositor client. The implementations in Android browser compositor
will be deleted when transitioning to slim compositor. These include:
* TopControlsSwapPromise taken from delegated_frame_host_android.cc
* Parameters for constructing AsyncLayerTreeFrameSink and
  cc::LayerTreeHost taken from compositor_impl_android.cc

Bug: 1408128
Change-Id: I19ef13373c55b4f8623caf023e31b818593efa72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4189553
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Auto-Submit: Bo Liu <boliu@chromium.org>
Commit-Queue: Bo Liu <boliu@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/main@{#1098173}
diff --git a/cc/slim/ui_resource_layer.h b/cc/slim/ui_resource_layer.h
new file mode 100644
index 0000000..3053746
--- /dev/null
+++ b/cc/slim/ui_resource_layer.h
@@ -0,0 +1,54 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_SLIM_UI_RESOURCE_LAYER_H_
+#define CC_SLIM_UI_RESOURCE_LAYER_H_
+
+#include "base/component_export.h"
+#include "cc/slim/layer.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/geometry/point_f.h"
+
+namespace cc {
+class UIResourceLayer;
+}
+
+namespace cc::slim {
+
+// Layer which to draws the contents of a single UIResource.
+class COMPONENT_EXPORT(CC_SLIM) UIResourceLayer : public Layer {
+ public:
+  static scoped_refptr<UIResourceLayer> Create();
+
+  // Sets the resource. If they don't exist already, the shared UI resource and
+  // ID are generated and cached in a map in the associated UIResourceManager.
+  // Currently, this resource will never be released by the UIResourceManager.
+  void SetUIResourceId(int id);
+
+  // An alternative way of setting the resource where an ID is used directly. If
+  // you use this method, you are responsible for updating the ID if the layer
+  // moves between compositors.
+  void SetBitmap(const SkBitmap& bitmap);
+
+  // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1).
+  void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right);
+
+  // Sets an opacity value per vertex. It will be multiplied by the layer
+  // opacity value.
+  void SetVertexOpacity(float bottom_left,
+                        float top_left,
+                        float top_right,
+                        float bottom_right);
+
+ protected:
+  explicit UIResourceLayer(scoped_refptr<cc::UIResourceLayer> cc_layer);
+  ~UIResourceLayer() override;
+
+ private:
+  cc::UIResourceLayer* cc_layer() const;
+};
+
+}  // namespace cc::slim
+
+#endif  // CC_SLIM_UI_RESOURCE_LAYER_H_