 Chromium Code Reviews
 Chromium Code Reviews Issue 1001643004:
  Remove android webview rendering cruft  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1001643004:
  Remove android webview rendering cruft  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 settings.single_thread_proxy_scheduler = false; | 102 settings.single_thread_proxy_scheduler = false; | 
| 103 | 103 | 
| 104 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded( | 104 layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded( | 
| 105 this, this, nullptr, nullptr, settings, nullptr, nullptr); | 105 this, this, nullptr, nullptr, settings, nullptr, nullptr); | 
| 106 layer_tree_host_->SetRootLayer(root_layer_); | 106 layer_tree_host_->SetRootLayer(root_layer_); | 
| 107 layer_tree_host_->SetLayerTreeHostClientReady(); | 107 layer_tree_host_->SetLayerTreeHostClientReady(); | 
| 108 layer_tree_host_->set_has_transparent_background(true); | 108 layer_tree_host_->set_has_transparent_background(true); | 
| 109 } | 109 } | 
| 110 | 110 | 
| 111 HardwareRenderer::~HardwareRenderer() { | 111 HardwareRenderer::~HardwareRenderer() { | 
| 112 SetFrameData(); | |
| 113 | |
| 114 // Must reset everything before |resource_collection_| to ensure all | 112 // Must reset everything before |resource_collection_| to ensure all | 
| 115 // resources are returned before resetting |resource_collection_| client. | 113 // resources are returned before resetting |resource_collection_| client. | 
| 116 layer_tree_host_.reset(); | 114 layer_tree_host_.reset(); | 
| 117 root_layer_ = NULL; | 115 root_layer_ = NULL; | 
| 118 delegated_layer_ = NULL; | 116 delegated_layer_ = NULL; | 
| 119 frame_provider_ = NULL; | 117 frame_provider_ = NULL; | 
| 120 #if DCHECK_IS_ON() | 118 #if DCHECK_IS_ON() | 
| 121 // Check collection is empty. | 119 // Check collection is empty. | 
| 122 cc::ReturnedResourceArray returned_resources; | 120 cc::ReturnedResourceArray returned_resources; | 
| 123 resource_collection_->TakeUnusedResourcesForChildCompositor( | 121 resource_collection_->TakeUnusedResourcesForChildCompositor( | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 137 // starts. We set the draw constraints here. | 135 // starts. We set the draw constraints here. | 
| 138 DCHECK(output_surface_); | 136 DCHECK(output_surface_); | 
| 139 DCHECK(viewport_clip_valid_for_dcheck_); | 137 DCHECK(viewport_clip_valid_for_dcheck_); | 
| 140 output_surface_->SetExternalStencilTest(stencil_enabled_); | 138 output_surface_->SetExternalStencilTest(stencil_enabled_); | 
| 141 output_surface_->SetDrawConstraints(viewport_, clip_); | 139 output_surface_->SetDrawConstraints(viewport_, clip_); | 
| 142 } | 140 } | 
| 143 | 141 | 
| 144 void HardwareRenderer::CommitFrame() { | 142 void HardwareRenderer::CommitFrame() { | 
| 145 TRACE_EVENT0("android_webview", "CommitFrame"); | 143 TRACE_EVENT0("android_webview", "CommitFrame"); | 
| 146 scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); | 144 scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); | 
| 147 if (committed_frame_.get()) { | 145 scoped_ptr<cc::CompositorFrame> frame = | 
| 148 TRACE_EVENT_INSTANT0("android_webview", | 146 shared_renderer_state_->PassCompositorFrameOnRT(); | 
| 149 "EarlyOut_PreviousFrameUnconsumed", | |
| 150 TRACE_EVENT_SCOPE_THREAD); | |
| 151 shared_renderer_state_->DidSkipCommitFrameOnRT(); | |
| 152 return; | |
| 153 } | |
| 154 | |
| 155 committed_frame_ = shared_renderer_state_->PassCompositorFrameOnRT(); | |
| 156 // Happens with empty global visible rect. | 147 // Happens with empty global visible rect. | 
| 
hush (inactive)
2015/03/13 18:45:17
Remove this comment here? because an empty globall
 
boliu
2015/03/18 02:02:22
Removed comment, but still need that check. We wan
 | |
| 157 if (!committed_frame_.get()) | 148 if (!frame.get()) | 
| 158 return; | 149 return; | 
| 159 | 150 | 
| 160 DCHECK(!committed_frame_->gl_frame_data); | 151 DCHECK(!frame->gl_frame_data); | 
| 161 DCHECK(!committed_frame_->software_frame_data); | 152 DCHECK(!frame->software_frame_data); | 
| 162 | 153 | 
| 163 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 154 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 
| 164 // renderer frame, assuming that the browser compositor will scale | 155 // renderer frame, assuming that the browser compositor will scale | 
| 165 // it back up to device scale. But on Android we put our browser layers in | 156 // it back up to device scale. But on Android we put our browser layers in | 
| 166 // physical pixels and set our browser CC device_scale_factor to 1, so this | 157 // physical pixels and set our browser CC device_scale_factor to 1, so this | 
| 167 // suppresses the transform. | 158 // suppresses the transform. | 
| 168 committed_frame_->delegated_frame_data->device_scale_factor = 1.0f; | 159 frame->delegated_frame_data->device_scale_factor = 1.0f; | 
| 169 } | |
| 170 | 160 | 
| 171 void HardwareRenderer::SetFrameData() { | |
| 172 if (!committed_frame_.get()) | |
| 173 return; | |
| 174 | |
| 175 scoped_ptr<cc::CompositorFrame> frame = committed_frame_.Pass(); | |
| 176 gfx::Size frame_size = | 161 gfx::Size frame_size = | 
| 177 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 162 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 
| 178 bool size_changed = frame_size != frame_size_; | 163 bool size_changed = frame_size != frame_size_; | 
| 179 frame_size_ = frame_size; | 164 frame_size_ = frame_size; | 
| 180 | 165 | 
| 181 if (!frame_provider_.get() || size_changed) { | 166 if (!frame_provider_.get() || size_changed) { | 
| 182 if (delegated_layer_.get()) { | 167 if (delegated_layer_.get()) { | 
| 183 delegated_layer_->RemoveFromParent(); | 168 delegated_layer_->RemoveFromParent(); | 
| 184 } | 169 } | 
| 185 | 170 | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 203 | 188 | 
| 204 // We need to watch if the current Android context has changed and enforce | 189 // We need to watch if the current Android context has changed and enforce | 
| 205 // a clean-up in the compositor. | 190 // a clean-up in the compositor. | 
| 206 EGLContext current_context = eglGetCurrentContext(); | 191 EGLContext current_context = eglGetCurrentContext(); | 
| 207 DCHECK(current_context) << "DrawGL called without EGLContext"; | 192 DCHECK(current_context) << "DrawGL called without EGLContext"; | 
| 208 | 193 | 
| 209 // TODO(boliu): Handle context loss. | 194 // TODO(boliu): Handle context loss. | 
| 210 if (last_egl_context_ != current_context) | 195 if (last_egl_context_ != current_context) | 
| 211 DLOG(WARNING) << "EGLContextChanged"; | 196 DLOG(WARNING) << "EGLContextChanged"; | 
| 212 | 197 | 
| 213 SetFrameData(); | |
| 214 if (shared_renderer_state_->ForceCommitOnRT()) { | |
| 215 CommitFrame(); | |
| 216 SetFrameData(); | |
| 217 } | |
| 218 | |
| 219 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 198 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 
| 220 transform.matrix().setColMajorf(draw_info->transform); | 199 transform.matrix().setColMajorf(draw_info->transform); | 
| 221 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 200 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 
| 222 | 201 | 
| 223 // Need to post the new transform matrix back to child compositor | 202 // Need to post the new transform matrix back to child compositor | 
| 224 // because there is no onDraw during a Render Thread animation, and child | 203 // because there is no onDraw during a Render Thread animation, and child | 
| 225 // compositor might not have the tiles rasterized as the animation goes on. | 204 // compositor might not have the tiles rasterized as the animation goes on. | 
| 226 ParentCompositorDrawConstraints draw_constraints( | 205 ParentCompositorDrawConstraints draw_constraints( | 
| 227 draw_info->is_layer, transform, gfx::Rect(viewport_)); | 206 draw_info->is_layer, transform, gfx::Rect(viewport_)); | 
| 228 | 207 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 } | 247 } | 
| 269 | 248 | 
| 270 void HardwareRenderer::UnusedResourcesAreAvailable() { | 249 void HardwareRenderer::UnusedResourcesAreAvailable() { | 
| 271 cc::ReturnedResourceArray returned_resources; | 250 cc::ReturnedResourceArray returned_resources; | 
| 272 resource_collection_->TakeUnusedResourcesForChildCompositor( | 251 resource_collection_->TakeUnusedResourcesForChildCompositor( | 
| 273 &returned_resources); | 252 &returned_resources); | 
| 274 shared_renderer_state_->InsertReturnedResourcesOnRT(returned_resources); | 253 shared_renderer_state_->InsertReturnedResourcesOnRT(returned_resources); | 
| 275 } | 254 } | 
| 276 | 255 | 
| 277 } // namespace android_webview | 256 } // namespace android_webview | 
| OLD | NEW |