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

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

Issue 2096493002: Make cc::CompositorFrames movable [Part 1 of 2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make CompositorFrameMetadata movable Created 4 years, 6 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
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"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 TRACE_EVENT0("android_webview", "CommitFrame"); 103 TRACE_EVENT0("android_webview", "CommitFrame");
104 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT(); 104 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT();
105 std::unique_ptr<ChildFrame> child_frame = 105 std::unique_ptr<ChildFrame> child_frame =
106 render_thread_manager_->PassFrameOnRT(); 106 render_thread_manager_->PassFrameOnRT();
107 if (!child_frame.get()) 107 if (!child_frame.get())
108 return; 108 return;
109 109
110 last_committed_output_surface_id_ = child_frame->output_surface_id; 110 last_committed_output_surface_id_ = child_frame->output_surface_id;
111 ReturnResourcesInChildFrame(); 111 ReturnResourcesInChildFrame();
112 child_frame_ = std::move(child_frame); 112 child_frame_ = std::move(child_frame);
113 DCHECK(child_frame_->frame.get()); 113 DCHECK(child_frame_->frame);
114 DCHECK(!child_frame_->frame->gl_frame_data); 114 DCHECK(!child_frame_->frame->gl_frame_data);
115 } 115 }
116 116
117 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, 117 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info,
118 const ScopedAppGLStateRestore& gl_state) { 118 const ScopedAppGLStateRestore& gl_state) {
119 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); 119 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL");
120 120
121 // We need to watch if the current Android context has changed and enforce 121 // We need to watch if the current Android context has changed and enforce
122 // a clean-up in the compositor. 122 // a clean-up in the compositor.
123 EGLContext current_context = eglGetCurrentContext(); 123 EGLContext current_context = eglGetCurrentContext();
124 DCHECK(current_context) << "DrawGL called without EGLContext"; 124 DCHECK(current_context) << "DrawGL called without EGLContext";
125 125
126 // TODO(boliu): Handle context loss. 126 // TODO(boliu): Handle context loss.
127 if (last_egl_context_ != current_context) 127 if (last_egl_context_ != current_context)
128 DLOG(WARNING) << "EGLContextChanged"; 128 DLOG(WARNING) << "EGLContextChanged";
129 129
130 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it 130 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it
131 // during "kModeSync" stage (which does not allow GL) might result in extra 131 // during "kModeSync" stage (which does not allow GL) might result in extra
132 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid 132 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid
133 // unnecessary kModeProcess. 133 // unnecessary kModeProcess.
134 if (child_frame_.get() && child_frame_->frame.get()) { 134 if (child_frame_.get() && child_frame_->frame) {
135 if (!compositor_id_.Equals(child_frame_->compositor_id) || 135 if (!compositor_id_.Equals(child_frame_->compositor_id) ||
136 last_submitted_output_surface_id_ != child_frame_->output_surface_id) { 136 last_submitted_output_surface_id_ != child_frame_->output_surface_id) {
137 if (!root_id_.is_null()) 137 if (!root_id_.is_null())
138 surface_factory_->Destroy(root_id_); 138 surface_factory_->Destroy(root_id_);
139 if (!child_id_.is_null()) 139 if (!child_id_.is_null())
140 surface_factory_->Destroy(child_id_); 140 surface_factory_->Destroy(child_id_);
141 141
142 root_id_ = cc::SurfaceId(); 142 root_id_ = cc::SurfaceId();
143 child_id_ = cc::SurfaceId(); 143 child_id_ = cc::SurfaceId();
144 144
145 // This will return all the resources to the previous compositor. 145 // This will return all the resources to the previous compositor.
146 surface_factory_.reset(); 146 surface_factory_.reset();
147 compositor_id_ = child_frame_->compositor_id; 147 compositor_id_ = child_frame_->compositor_id;
148 last_submitted_output_surface_id_ = child_frame_->output_surface_id; 148 last_submitted_output_surface_id_ = child_frame_->output_surface_id;
149 surface_factory_.reset( 149 surface_factory_.reset(
150 new cc::SurfaceFactory(surface_manager_.get(), this)); 150 new cc::SurfaceFactory(surface_manager_.get(), this));
151 } 151 }
152 152
153 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = 153 std::unique_ptr<cc::CompositorFrame> child_compositor_frame(
154 std::move(child_frame_->frame); 154 new cc::CompositorFrame);
155 *child_compositor_frame = std::move(*child_frame_->frame);
155 156
156 // On Android we put our browser layers in physical pixels and set our 157 // On Android we put our browser layers in physical pixels and set our
157 // browser CC device_scale_factor to 1, so suppress the transform between 158 // browser CC device_scale_factor to 1, so suppress the transform between
158 // DIP and pixels. 159 // DIP and pixels.
159 child_compositor_frame->delegated_frame_data->device_scale_factor = 1.0f; 160 child_compositor_frame->delegated_frame_data->device_scale_factor = 1.0f;
160 161
161 gfx::Size frame_size = 162 gfx::Size frame_size =
162 child_compositor_frame->delegated_frame_data->render_pass_list.back() 163 child_compositor_frame->delegated_frame_data->render_pass_list.back()
163 ->output_rect.size(); 164 ->output_rect.size();
164 bool size_changed = frame_size != frame_size_; 165 bool size_changed = frame_size != frame_size_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 quad_state->opacity = 1.f; 212 quad_state->opacity = 1.f;
212 213
213 cc::SurfaceDrawQuad* surface_quad = 214 cc::SurfaceDrawQuad* surface_quad =
214 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 215 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
215 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), 216 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds),
216 gfx::Rect(quad_state->quad_layer_bounds), child_id_); 217 gfx::Rect(quad_state->quad_layer_bounds), child_id_);
217 218
218 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( 219 std::unique_ptr<cc::DelegatedFrameData> delegated_frame(
219 new cc::DelegatedFrameData); 220 new cc::DelegatedFrameData);
220 delegated_frame->render_pass_list.push_back(std::move(render_pass)); 221 delegated_frame->render_pass_list.push_back(std::move(render_pass));
221 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); 222 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame());
222 frame->delegated_frame_data = std::move(delegated_frame); 223 frame->delegated_frame_data = std::move(delegated_frame);
223 224
224 if (root_id_.is_null()) { 225 if (root_id_.is_null()) {
225 root_id_ = surface_id_allocator_->GenerateId(); 226 root_id_ = surface_id_allocator_->GenerateId();
226 surface_factory_->Create(root_id_); 227 surface_factory_->Create(root_id_);
227 display_->SetSurfaceId(root_id_, 1.f); 228 display_->SetSurfaceId(root_id_, 1.f);
228 } 229 }
229 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame), 230 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame),
230 cc::SurfaceFactory::DrawCallback()); 231 cc::SurfaceFactory::DrawCallback());
231 232
(...skipping 14 matching lines...) Expand all
246 cc::BeginFrameSource* begin_frame_source) { 247 cc::BeginFrameSource* begin_frame_source) {
247 // TODO(tansell): Hook this up. 248 // TODO(tansell): Hook this up.
248 } 249 }
249 250
250 void HardwareRenderer::SetBackingFrameBufferObject( 251 void HardwareRenderer::SetBackingFrameBufferObject(
251 int framebuffer_binding_ext) { 252 int framebuffer_binding_ext) {
252 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); 253 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext);
253 } 254 }
254 255
255 void HardwareRenderer::ReturnResourcesInChildFrame() { 256 void HardwareRenderer::ReturnResourcesInChildFrame() {
256 if (child_frame_.get() && child_frame_->frame.get()) { 257 if (child_frame_.get() && child_frame_->frame) {
257 cc::ReturnedResourceArray resources_to_return; 258 cc::ReturnedResourceArray resources_to_return;
258 cc::TransferableResource::ReturnResources( 259 cc::TransferableResource::ReturnResources(
259 child_frame_->frame->delegated_frame_data->resource_list, 260 child_frame_->frame->delegated_frame_data->resource_list,
260 &resources_to_return); 261 &resources_to_return);
261 262
262 // The child frame's compositor id is not necessarily same as 263 // The child frame's compositor id is not necessarily same as
263 // compositor_id_. 264 // compositor_id_.
264 ReturnResourcesToCompositor(resources_to_return, 265 ReturnResourcesToCompositor(resources_to_return,
265 child_frame_->compositor_id, 266 child_frame_->compositor_id,
266 child_frame_->output_surface_id); 267 child_frame_->output_surface_id);
267 } 268 }
268 child_frame_.reset(); 269 child_frame_.reset();
269 } 270 }
270 271
271 void HardwareRenderer::ReturnResourcesToCompositor( 272 void HardwareRenderer::ReturnResourcesToCompositor(
272 const cc::ReturnedResourceArray& resources, 273 const cc::ReturnedResourceArray& resources,
273 const CompositorID& compositor_id, 274 const CompositorID& compositor_id,
274 uint32_t output_surface_id) { 275 uint32_t output_surface_id) {
275 if (output_surface_id != last_committed_output_surface_id_) 276 if (output_surface_id != last_committed_output_surface_id_)
276 return; 277 return;
277 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, 278 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id,
278 output_surface_id); 279 output_surface_id);
279 } 280 }
280 281
281 } // namespace android_webview 282 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698