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

Side by Side Diff: android_webview/browser/hardware_renderer.cc

Issue 2729523005: HardwareRenderer should use CompositorFrameSinkSupport (Closed)
Patch Set: c Created 3 years, 9 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
« no previous file with comments | « android_webview/browser/hardware_renderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/hardware_renderer.h" 5 #include "android_webview/browser/hardware_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/aw_gl_surface.h" 9 #include "android_webview/browser/aw_gl_surface.h"
10 #include "android_webview/browser/aw_render_thread_context_provider.h" 10 #include "android_webview/browser/aw_render_thread_context_provider.h"
11 #include "android_webview/browser/parent_compositor_draw_constraints.h" 11 #include "android_webview/browser/parent_compositor_draw_constraints.h"
12 #include "android_webview/browser/render_thread_manager.h" 12 #include "android_webview/browser/render_thread_manager.h"
13 #include "android_webview/browser/surfaces_instance.h" 13 #include "android_webview/browser/surfaces_instance.h"
14 #include "android_webview/public/browser/draw_gl.h" 14 #include "android_webview/public/browser/draw_gl.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
18 #include "cc/surfaces/compositor_frame_sink_support.h"
18 #include "cc/surfaces/local_surface_id_allocator.h" 19 #include "cc/surfaces/local_surface_id_allocator.h"
19 #include "cc/surfaces/surface_factory.h"
20 #include "cc/surfaces/surface_manager.h" 20 #include "cc/surfaces/surface_manager.h"
21 #include "ui/gfx/transform.h" 21 #include "ui/gfx/transform.h"
22 #include "ui/gl/gl_bindings.h" 22 #include "ui/gl/gl_bindings.h"
23 23
24 namespace android_webview { 24 namespace android_webview {
25 25
26 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) 26 HardwareRenderer::HardwareRenderer(RenderThreadManager* state)
27 : render_thread_manager_(state), 27 : render_thread_manager_(state),
28 last_egl_context_(eglGetCurrentContext()), 28 last_egl_context_(eglGetCurrentContext()),
29 surfaces_(SurfacesInstance::GetOrCreateInstance()), 29 surfaces_(SurfacesInstance::GetOrCreateInstance()),
30 frame_sink_id_(surfaces_->AllocateFrameSinkId()), 30 frame_sink_id_(surfaces_->AllocateFrameSinkId()),
31 local_surface_id_allocator_( 31 local_surface_id_allocator_(
32 base::MakeUnique<cc::LocalSurfaceIdAllocator>()), 32 base::MakeUnique<cc::LocalSurfaceIdAllocator>()),
33 surface_factory_(new cc::SurfaceFactory(frame_sink_id_,
34 surfaces_->GetSurfaceManager(),
35 this)),
36 last_committed_compositor_frame_sink_id_(0u), 33 last_committed_compositor_frame_sink_id_(0u),
37 last_submitted_compositor_frame_sink_id_(0u) { 34 last_submitted_compositor_frame_sink_id_(0u) {
38 DCHECK(last_egl_context_); 35 DCHECK(last_egl_context_);
39 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 36 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
40 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, 37 CreateNewCompositorFrameSinkSupport();
41 this);
42 } 38 }
43 39
44 HardwareRenderer::~HardwareRenderer() { 40 HardwareRenderer::~HardwareRenderer() {
45 // Must reset everything before |surface_factory_| to ensure all 41 // Must reset everything before |surface_factory_| to ensure all
46 // resources are returned before resetting. 42 // resources are returned before resetting.
47 if (child_id_.is_valid()) 43 if (child_id_.is_valid())
48 DestroySurface(); 44 DestroySurface();
49 surface_factory_.reset(); 45 support_.reset();
50 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient(
51 frame_sink_id_);
52 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 46 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
53 47
54 // Reset draw constraints. 48 // Reset draw constraints.
55 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( 49 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT(
56 ParentCompositorDrawConstraints()); 50 ParentCompositorDrawConstraints());
57 for (auto& child_frame : child_frame_queue_) { 51 for (auto& child_frame : child_frame_queue_) {
58 child_frame->WaitOnFutureIfNeeded(); 52 child_frame->WaitOnFutureIfNeeded();
59 ReturnChildFrame(std::move(child_frame)); 53 ReturnChildFrame(std::move(child_frame));
60 } 54 }
61 } 55 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // during "kModeSync" stage (which does not allow GL) might result in extra 102 // during "kModeSync" stage (which does not allow GL) might result in extra
109 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid 103 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid
110 // unnecessary kModeProcess. 104 // unnecessary kModeProcess.
111 if (child_frame_.get() && child_frame_->frame.get()) { 105 if (child_frame_.get() && child_frame_->frame.get()) {
112 if (!compositor_id_.Equals(child_frame_->compositor_id) || 106 if (!compositor_id_.Equals(child_frame_->compositor_id) ||
113 last_submitted_compositor_frame_sink_id_ != 107 last_submitted_compositor_frame_sink_id_ !=
114 child_frame_->compositor_frame_sink_id) { 108 child_frame_->compositor_frame_sink_id) {
115 if (child_id_.is_valid()) 109 if (child_id_.is_valid())
116 DestroySurface(); 110 DestroySurface();
117 111
118 // This will return all the resources to the previous compositor. 112 CreateNewCompositorFrameSinkSupport();
119 surface_factory_->Reset();
120 compositor_id_ = child_frame_->compositor_id; 113 compositor_id_ = child_frame_->compositor_id;
121 last_submitted_compositor_frame_sink_id_ = 114 last_submitted_compositor_frame_sink_id_ =
122 child_frame_->compositor_frame_sink_id; 115 child_frame_->compositor_frame_sink_id;
123 } 116 }
124 117
125 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = 118 std::unique_ptr<cc::CompositorFrame> child_compositor_frame =
126 std::move(child_frame_->frame); 119 std::move(child_frame_->frame);
127 120
128 gfx::Size frame_size = 121 gfx::Size frame_size =
129 child_compositor_frame->render_pass_list.back()->output_rect.size(); 122 child_compositor_frame->render_pass_list.back()->output_rect.size();
130 bool size_changed = frame_size != frame_size_; 123 bool size_changed = frame_size != frame_size_;
131 frame_size_ = frame_size; 124 frame_size_ = frame_size;
132 if (!child_id_.is_valid() || size_changed) { 125 if (!child_id_.is_valid() || size_changed) {
133 if (child_id_.is_valid()) 126 if (child_id_.is_valid())
134 DestroySurface(); 127 DestroySurface();
135 AllocateSurface(); 128 AllocateSurface();
136 } 129 }
137 130
138 surface_factory_->SubmitCompositorFrame(child_id_, 131 support_->SubmitCompositorFrame(child_id_,
139 std::move(*child_compositor_frame), 132 std::move(*child_compositor_frame));
140 cc::SurfaceFactory::DrawCallback());
141 } 133 }
142 134
143 gfx::Transform transform(gfx::Transform::kSkipInitialization); 135 gfx::Transform transform(gfx::Transform::kSkipInitialization);
144 transform.matrix().setColMajorf(draw_info->transform); 136 transform.matrix().setColMajorf(draw_info->transform);
145 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); 137 transform.Translate(scroll_offset_.x(), scroll_offset_.y());
146 138
147 gfx::Size viewport(draw_info->width, draw_info->height); 139 gfx::Size viewport(draw_info->width, draw_info->height);
148 // Need to post the new transform matrix back to child compositor 140 // Need to post the new transform matrix back to child compositor
149 // because there is no onDraw during a Render Thread animation, and child 141 // because there is no onDraw during a Render Thread animation, and child
150 // compositor might not have the tiles rasterized as the animation goes on. 142 // compositor might not have the tiles rasterized as the animation goes on.
(...skipping 17 matching lines...) Expand all
168 void HardwareRenderer::AllocateSurface() { 160 void HardwareRenderer::AllocateSurface() {
169 DCHECK(!child_id_.is_valid()); 161 DCHECK(!child_id_.is_valid());
170 child_id_ = local_surface_id_allocator_->GenerateId(); 162 child_id_ = local_surface_id_allocator_->GenerateId();
171 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); 163 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_));
172 } 164 }
173 165
174 void HardwareRenderer::DestroySurface() { 166 void HardwareRenderer::DestroySurface() {
175 DCHECK(child_id_.is_valid()); 167 DCHECK(child_id_.is_valid());
176 168
177 // Submit an empty frame to force any existing resources to be returned. 169 // Submit an empty frame to force any existing resources to be returned.
178 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), 170 support_->SubmitCompositorFrame(child_id_, cc::CompositorFrame());
179 cc::SurfaceFactory::DrawCallback());
180 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); 171 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_));
181 surface_factory_->EvictSurface(); 172 support_->EvictFrame();
182 child_id_ = cc::LocalSurfaceId(); 173 child_id_ = cc::LocalSurfaceId();
183 } 174 }
184 175
185 void HardwareRenderer::ReturnResources( 176 void HardwareRenderer::DidReceiveCompositorFrameAck() {}
177
178 void HardwareRenderer::OnBeginFrame(const cc::BeginFrameArgs& args) {
179 // TODO(tansell): Hook this up.
180 }
181
182 void HardwareRenderer::ReclaimResources(
186 const cc::ReturnedResourceArray& resources) { 183 const cc::ReturnedResourceArray& resources) {
187 ReturnResourcesToCompositor(resources, compositor_id_, 184 ReturnResourcesToCompositor(resources, compositor_id_,
188 last_submitted_compositor_frame_sink_id_); 185 last_submitted_compositor_frame_sink_id_);
189 } 186 }
190 187
191 void HardwareRenderer::SetBeginFrameSource( 188 void HardwareRenderer::WillDrawSurface(
192 cc::BeginFrameSource* begin_frame_source) { 189 const cc::LocalSurfaceId& local_surface_id,
193 // TODO(tansell): Hook this up. 190 const gfx::Rect& damage_rect) {}
194 }
195 191
196 // static 192 // static
197 ChildFrameQueue HardwareRenderer::WaitAndPruneFrameQueue( 193 ChildFrameQueue HardwareRenderer::WaitAndPruneFrameQueue(
198 ChildFrameQueue* child_frames_ptr) { 194 ChildFrameQueue* child_frames_ptr) {
199 ChildFrameQueue& child_frames = *child_frames_ptr; 195 ChildFrameQueue& child_frames = *child_frames_ptr;
200 ChildFrameQueue pruned_frames; 196 ChildFrameQueue pruned_frames;
201 197
202 // First find the last non-empty frame. 198 // First find the last non-empty frame.
203 int last_non_empty_index = -1; 199 int last_non_empty_index = -1;
204 for (size_t i = 0; i < child_frames.size(); ++i) { 200 for (size_t i = 0; i < child_frames.size(); ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void HardwareRenderer::ReturnResourcesToCompositor( 244 void HardwareRenderer::ReturnResourcesToCompositor(
249 const cc::ReturnedResourceArray& resources, 245 const cc::ReturnedResourceArray& resources,
250 const CompositorID& compositor_id, 246 const CompositorID& compositor_id,
251 uint32_t compositor_frame_sink_id) { 247 uint32_t compositor_frame_sink_id) {
252 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) 248 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_)
253 return; 249 return;
254 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, 250 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id,
255 compositor_frame_sink_id); 251 compositor_frame_sink_id);
256 } 252 }
257 253
254 void HardwareRenderer::CreateNewCompositorFrameSinkSupport() {
255 support_.reset();
256 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>(
257 this, surfaces_->GetSurfaceManager(), frame_sink_id_, false /* is_root */,
258 false /* handles_frame_sink_id_invalidation */,
259 true /* needs_sync_points */);
260 }
261
258 } // namespace android_webview 262 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/hardware_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698