[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.cc b/cc/slim/ui_resource_layer.cc
new file mode 100644
index 0000000..97c2a6e2
--- /dev/null
+++ b/cc/slim/ui_resource_layer.cc
@@ -0,0 +1,52 @@
+// 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.
+
+#include "cc/slim/ui_resource_layer.h"
+
+#include <utility>
+
+#include "cc/layers/ui_resource_layer.h"
+#include "components/viz/common/quads/compositor_render_pass.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+
+namespace cc::slim {
+
+// static
+scoped_refptr<UIResourceLayer> UIResourceLayer::Create() {
+  scoped_refptr<cc::UIResourceLayer> cc_layer;
+  cc_layer = cc::UIResourceLayer::Create();
+  return base::AdoptRef(new UIResourceLayer(std::move(cc_layer)));
+}
+
+UIResourceLayer::UIResourceLayer(scoped_refptr<cc::UIResourceLayer> cc_layer)
+    : Layer(std::move(cc_layer)) {}
+
+UIResourceLayer::~UIResourceLayer() = default;
+
+cc::UIResourceLayer* UIResourceLayer::cc_layer() const {
+  return static_cast<cc::UIResourceLayer*>(cc_layer_.get());
+}
+
+void UIResourceLayer::SetUIResourceId(int id) {
+  cc_layer()->SetUIResourceId(id);
+}
+
+void UIResourceLayer::SetBitmap(const SkBitmap& bitmap) {
+  cc_layer()->SetBitmap(bitmap);
+}
+
+void UIResourceLayer::SetUV(const gfx::PointF& top_left,
+                            const gfx::PointF& bottom_right) {
+  cc_layer()->SetUV(top_left, bottom_right);
+}
+
+void UIResourceLayer::SetVertexOpacity(float bottom_left,
+                                       float top_left,
+                                       float top_right,
+                                       float bottom_right) {
+  cc_layer()->SetVertexOpacity(bottom_left, top_left, top_right, bottom_right);
+}
+
+}  // namespace cc::slim