Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1130)

Side by Side Diff: content/renderer/android/synchronous_compositor_output_surface.h

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: android-vulkan Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
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 CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
6 #define CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
7
8 #include <stddef.h>
9
10 #include <memory>
11
12 #include "base/callback.h"
13 #include "base/cancelable_callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/threading/thread_checker.h"
18 #include "cc/output/compositor_frame.h"
19 #include "cc/output/managed_memory_policy.h"
20 #include "cc/output/output_surface.h"
21 #include "cc/surfaces/display_client.h"
22 #include "cc/surfaces/surface_factory_client.h"
23 #include "ipc/ipc_message.h"
24 #include "ui/gfx/transform.h"
25
26 namespace cc {
27 class ContextProvider;
28 class CompositorFrameMetadata;
29 class Display;
30 class SurfaceFactory;
31 class SurfaceIdAllocator;
32 class SurfaceManager;
33 }
34
35 namespace IPC {
36 class Message;
37 class Sender;
38 }
39
40 namespace content {
41
42 class FrameSwapMessageQueue;
43 class SynchronousCompositorRegistry;
44 class WebGraphicsContext3DCommandBufferImpl;
45
46 class SynchronousCompositorOutputSurfaceClient {
47 public:
48 virtual void DidActivatePendingTree() = 0;
49 virtual void Invalidate() = 0;
50 virtual void SwapBuffers(uint32_t output_surface_id,
51 cc::CompositorFrame frame) = 0;
52
53 protected:
54 virtual ~SynchronousCompositorOutputSurfaceClient() {}
55 };
56
57 // Specialization of the output surface that adapts it to implement the
58 // content::SynchronousCompositor public API. This class effects an "inversion
59 // of control" - enabling drawing to be orchestrated by the embedding
60 // layer, instead of driven by the compositor internals - hence it holds two
61 // 'client' pointers (|client_| in the OutputSurface baseclass and
62 // |delegate_|) which represent the consumers of the two roles in plays.
63 // This class can be created only on the main thread, but then becomes pinned
64 // to a fixed thread when BindToClient is called.
65 class SynchronousCompositorOutputSurface
66 : NON_EXPORTED_BASE(public cc::OutputSurface),
67 public cc::SurfaceFactoryClient {
68 public:
69 SynchronousCompositorOutputSurface(
70 scoped_refptr<cc::ContextProvider> context_provider,
71 scoped_refptr<cc::ContextProvider> worker_context_provider,
72 int routing_id,
73 uint32_t output_surface_id,
74 std::unique_ptr<cc::BeginFrameSource> begin_frame_source,
75 SynchronousCompositorRegistry* registry,
76 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue);
77 ~SynchronousCompositorOutputSurface() override;
78
79 void SetSyncClient(SynchronousCompositorOutputSurfaceClient* compositor);
80 bool OnMessageReceived(const IPC::Message& message);
81
82 // OutputSurface.
83 bool BindToClient(cc::OutputSurfaceClient* surface_client) override;
84 void DetachFromClient() override;
85 void Reshape(const gfx::Size& size,
86 float scale_factor,
87 const gfx::ColorSpace& color_space,
88 bool has_alpha) override;
89 void SwapBuffers(cc::CompositorFrame frame) override;
90 void Invalidate() override;
91 void BindFramebuffer() override;
92 uint32_t GetFramebufferCopyTextureFormat() override;
93
94 // Partial SynchronousCompositor API implementation.
95 void DemandDrawHw(const gfx::Size& viewport_size,
96 const gfx::Rect& viewport_rect_for_tile_priority,
97 const gfx::Transform& transform_for_tile_priority);
98 void DemandDrawSw(SkCanvas* canvas);
99
100 // SurfaceFactoryClient implementation.
101 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
102 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override;
103
104 private:
105 class SoftwareOutputSurface;
106
107 void InvokeComposite(const gfx::Transform& transform,
108 const gfx::Rect& viewport);
109 bool Send(IPC::Message* message);
110 void DidActivatePendingTree();
111 void DeliverMessages();
112 bool CalledOnValidThread() const;
113
114 void CancelFallbackTick();
115 void FallbackTickFired();
116
117 // IPC handlers.
118 void SetMemoryPolicy(size_t bytes_limit);
119 void OnReclaimResources(uint32_t output_surface_id,
120 const cc::ReturnedResourceArray& resources);
121
122 const int routing_id_;
123 const uint32_t output_surface_id_;
124 SynchronousCompositorRegistry* const registry_; // Not owned.
125 IPC::Sender* const sender_; // Not owned.
126 bool registered_ = false;
127
128 // Not owned.
129 SynchronousCompositorOutputSurfaceClient* sync_client_ = nullptr;
130
131 // Only valid (non-NULL) during a DemandDrawSw() call.
132 SkCanvas* current_sw_canvas_ = nullptr;
133
134 cc::ManagedMemoryPolicy memory_policy_;
135 bool in_software_draw_ = false;
136 bool did_swap_ = false;
137 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_;
138
139 base::CancelableClosure fallback_tick_;
140 bool fallback_tick_pending_ = false;
141 bool fallback_tick_running_ = false;
142
143 class StubDisplayClient : public cc::DisplayClient {
144 void DisplayOutputSurfaceLost() override {}
145 void DisplayWillDrawAndSwap(
146 bool will_draw_and_swap,
147 const cc::RenderPassList& render_passes) override {}
148 void DisplayDidDrawAndSwap() override {}
149 };
150
151 // TODO(danakj): These don't to be stored in unique_ptrs when OutputSurface
152 // is owned/destroyed on the compositor thread.
153 std::unique_ptr<cc::SurfaceManager> surface_manager_;
154 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
155 cc::SurfaceId delegated_surface_id_;
156 // Uses surface_manager_.
157 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
158 StubDisplayClient display_client_;
159 // Uses surface_manager_.
160 std::unique_ptr<cc::Display> display_;
161 // Owned by |display_|.
162 SoftwareOutputSurface* software_output_surface_ = nullptr;
163 std::unique_ptr<cc::BeginFrameSource> begin_frame_source_;
164
165 base::ThreadChecker thread_checker_;
166
167 DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorOutputSurface);
168 };
169
170 } // namespace content
171
172 #endif // CONTENT_RENDERER_ANDROID_SYNCHRONOUS_COMPOSITOR_OUTPUT_SURFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698