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

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

Issue 585093003: aw: Block child compositor if frame is not consumed by parent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove extra blank line Created 6 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
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 "android_webview/browser/aw_gl_surface.h" 7 #include "android_webview/browser/aw_gl_surface.h"
8 #include "android_webview/browser/deferred_gpu_command_service.h" 8 #include "android_webview/browser/deferred_gpu_command_service.h"
9 #include "android_webview/browser/parent_output_surface.h" 9 #include "android_webview/browser/parent_output_surface.h"
10 #include "android_webview/browser/shared_renderer_state.h" 10 #include "android_webview/browser/shared_renderer_state.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 settings.single_thread_proxy_scheduler = false; 99 settings.single_thread_proxy_scheduler = false;
100 100
101 layer_tree_host_ = 101 layer_tree_host_ =
102 cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings, NULL); 102 cc::LayerTreeHost::CreateSingleThreaded(this, this, NULL, settings, NULL);
103 layer_tree_host_->SetRootLayer(root_layer_); 103 layer_tree_host_->SetRootLayer(root_layer_);
104 layer_tree_host_->SetLayerTreeHostClientReady(); 104 layer_tree_host_->SetLayerTreeHostClientReady();
105 layer_tree_host_->set_has_transparent_background(true); 105 layer_tree_host_->set_has_transparent_background(true);
106 } 106 }
107 107
108 HardwareRenderer::~HardwareRenderer() { 108 HardwareRenderer::~HardwareRenderer() {
109 SetFrameData();
110
109 // Must reset everything before |resource_collection_| to ensure all 111 // Must reset everything before |resource_collection_| to ensure all
110 // resources are returned before resetting |resource_collection_| client. 112 // resources are returned before resetting |resource_collection_| client.
111 layer_tree_host_.reset(); 113 layer_tree_host_.reset();
112 root_layer_ = NULL; 114 root_layer_ = NULL;
113 delegated_layer_ = NULL; 115 delegated_layer_ = NULL;
114 frame_provider_ = NULL; 116 frame_provider_ = NULL;
115 #if DCHECK_IS_ON 117 #if DCHECK_IS_ON
116 // Check collection is empty. 118 // Check collection is empty.
117 cc::ReturnedResourceArray returned_resources; 119 cc::ReturnedResourceArray returned_resources;
118 resource_collection_->TakeUnusedResourcesForChildCompositor( 120 resource_collection_->TakeUnusedResourcesForChildCompositor(
(...skipping 11 matching lines...) Expand all
130 void HardwareRenderer::DidBeginMainFrame() { 132 void HardwareRenderer::DidBeginMainFrame() {
131 // This is called after OutputSurface is created, but before the impl frame 133 // This is called after OutputSurface is created, but before the impl frame
132 // starts. We set the draw constraints here. 134 // starts. We set the draw constraints here.
133 DCHECK(output_surface_); 135 DCHECK(output_surface_);
134 DCHECK(viewport_clip_valid_for_dcheck_); 136 DCHECK(viewport_clip_valid_for_dcheck_);
135 output_surface_->SetExternalStencilTest(stencil_enabled_); 137 output_surface_->SetExternalStencilTest(stencil_enabled_);
136 output_surface_->SetDrawConstraints(viewport_, clip_); 138 output_surface_->SetDrawConstraints(viewport_, clip_);
137 } 139 }
138 140
139 void HardwareRenderer::CommitFrame() { 141 void HardwareRenderer::CommitFrame() {
140 scoped_ptr<DrawGLInput> input = shared_renderer_state_->PassDrawGLInput(); 142 if (committed_input_.get()) {
143 TRACE_EVENT_INSTANT0("android_webview",
144 "EarlyOut_PreviousFrameUnconsumed",
145 TRACE_EVENT_SCOPE_THREAD);
146 return;
147 }
148
149 committed_input_ = shared_renderer_state_->PassDrawGLInput();
141 // Happens with empty global visible rect. 150 // Happens with empty global visible rect.
142 if (!input.get()) 151 if (!committed_input_.get())
143 return; 152 return;
144 153
145 DCHECK(!input->frame.gl_frame_data); 154 DCHECK(!committed_input_->frame.gl_frame_data);
146 DCHECK(!input->frame.software_frame_data); 155 DCHECK(!committed_input_->frame.software_frame_data);
147 156
148 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the 157 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the
149 // renderer frame, assuming that the browser compositor will scale 158 // renderer frame, assuming that the browser compositor will scale
150 // it back up to device scale. But on Android we put our browser layers in 159 // it back up to device scale. But on Android we put our browser layers in
151 // physical pixels and set our browser CC device_scale_factor to 1, so this 160 // physical pixels and set our browser CC device_scale_factor to 1, so this
152 // suppresses the transform. 161 // suppresses the transform.
153 input->frame.delegated_frame_data->device_scale_factor = 1.0f; 162 committed_input_->frame.delegated_frame_data->device_scale_factor = 1.0f;
163 }
154 164
165 void HardwareRenderer::SetFrameData() {
166 if (!committed_input_.get())
167 return;
168
169 scoped_ptr<DrawGLInput> input = committed_input_.Pass();
155 gfx::Size frame_size = 170 gfx::Size frame_size =
156 input->frame.delegated_frame_data->render_pass_list.back() 171 input->frame.delegated_frame_data->render_pass_list.back()
157 ->output_rect.size(); 172 ->output_rect.size();
158 bool size_changed = frame_size != frame_size_; 173 bool size_changed = frame_size != frame_size_;
159 frame_size_ = frame_size; 174 frame_size_ = frame_size;
160 scroll_offset_ = input->scroll_offset; 175 scroll_offset_ = input->scroll_offset;
161 176
162 if (!frame_provider_ || size_changed) { 177 if (!frame_provider_ || size_changed) {
163 if (delegated_layer_) { 178 if (delegated_layer_) {
164 delegated_layer_->RemoveFromParent(); 179 delegated_layer_->RemoveFromParent();
(...skipping 13 matching lines...) Expand all
178 } 193 }
179 194
180 void HardwareRenderer::DrawGL(bool stencil_enabled, 195 void HardwareRenderer::DrawGL(bool stencil_enabled,
181 int framebuffer_binding_ext, 196 int framebuffer_binding_ext,
182 AwDrawGLInfo* draw_info) { 197 AwDrawGLInfo* draw_info) {
183 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); 198 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL");
184 199
185 // We need to watch if the current Android context has changed and enforce 200 // We need to watch if the current Android context has changed and enforce
186 // a clean-up in the compositor. 201 // a clean-up in the compositor.
187 EGLContext current_context = eglGetCurrentContext(); 202 EGLContext current_context = eglGetCurrentContext();
188 if (!current_context) { 203 DCHECK(current_context) << "DrawGL called without EGLContext";
189 DLOG(ERROR) << "DrawGL called without EGLContext";
190 return;
191 }
192 204
193 // TODO(boliu): Handle context loss. 205 // TODO(boliu): Handle context loss.
194 if (last_egl_context_ != current_context) 206 if (last_egl_context_ != current_context)
195 DLOG(WARNING) << "EGLContextChanged"; 207 DLOG(WARNING) << "EGLContextChanged";
196 208
209 SetFrameData();
197 gfx::Transform transform(gfx::Transform::kSkipInitialization); 210 gfx::Transform transform(gfx::Transform::kSkipInitialization);
198 transform.matrix().setColMajorf(draw_info->transform); 211 transform.matrix().setColMajorf(draw_info->transform);
199 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); 212 transform.Translate(scroll_offset_.x(), scroll_offset_.y());
200 213
201 // Need to post the new transform matrix back to child compositor 214 // Need to post the new transform matrix back to child compositor
202 // because there is no onDraw during a Render Thread animation, and child 215 // because there is no onDraw during a Render Thread animation, and child
203 // compositor might not have the tiles rasterized as the animation goes on. 216 // compositor might not have the tiles rasterized as the animation goes on.
204 ParentCompositorDrawConstraints draw_constraints( 217 ParentCompositorDrawConstraints draw_constraints(
205 draw_info->is_layer, transform, gfx::Rect(viewport_)); 218 draw_info->is_layer, transform, gfx::Rect(viewport_));
206 if (!draw_constraints_.Equals(draw_constraints)) { 219 if (!draw_constraints_.Equals(draw_constraints)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 259 }
247 260
248 void HardwareRenderer::UnusedResourcesAreAvailable() { 261 void HardwareRenderer::UnusedResourcesAreAvailable() {
249 cc::ReturnedResourceArray returned_resources; 262 cc::ReturnedResourceArray returned_resources;
250 resource_collection_->TakeUnusedResourcesForChildCompositor( 263 resource_collection_->TakeUnusedResourcesForChildCompositor(
251 &returned_resources); 264 &returned_resources);
252 shared_renderer_state_->InsertReturnedResources(returned_resources); 265 shared_renderer_state_->InsertReturnedResources(returned_resources);
253 } 266 }
254 267
255 } // namespace android_webview 268 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/hardware_renderer.h ('k') | android_webview/browser/shared_renderer_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698