| 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/child_frame.h" | 
| 8 #include "android_webview/browser/deferred_gpu_command_service.h" | 9 #include "android_webview/browser/deferred_gpu_command_service.h" | 
|  | 10 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 
| 9 #include "android_webview/browser/parent_output_surface.h" | 11 #include "android_webview/browser/parent_output_surface.h" | 
| 10 #include "android_webview/browser/shared_renderer_state.h" | 12 #include "android_webview/browser/shared_renderer_state.h" | 
| 11 #include "android_webview/public/browser/draw_gl.h" | 13 #include "android_webview/public/browser/draw_gl.h" | 
| 12 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" | 
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" | 
| 14 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" | 
| 15 #include "cc/layers/delegated_frame_provider.h" | 17 #include "cc/layers/delegated_frame_provider.h" | 
| 16 #include "cc/layers/delegated_renderer_layer.h" | 18 #include "cc/layers/delegated_renderer_layer.h" | 
| 17 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" | 
| 18 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102   settings.single_thread_proxy_scheduler = false; | 104   settings.single_thread_proxy_scheduler = false; | 
| 103 | 105 | 
| 104   layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded( | 106   layer_tree_host_ = cc::LayerTreeHost::CreateSingleThreaded( | 
| 105       this, this, nullptr, nullptr, settings, nullptr, nullptr); | 107       this, this, nullptr, nullptr, settings, nullptr, nullptr); | 
| 106   layer_tree_host_->SetRootLayer(root_layer_); | 108   layer_tree_host_->SetRootLayer(root_layer_); | 
| 107   layer_tree_host_->SetLayerTreeHostClientReady(); | 109   layer_tree_host_->SetLayerTreeHostClientReady(); | 
| 108   layer_tree_host_->set_has_transparent_background(true); | 110   layer_tree_host_->set_has_transparent_background(true); | 
| 109 } | 111 } | 
| 110 | 112 | 
| 111 HardwareRenderer::~HardwareRenderer() { | 113 HardwareRenderer::~HardwareRenderer() { | 
| 112   SetFrameData(); |  | 
| 113 |  | 
| 114   // Must reset everything before |resource_collection_| to ensure all | 114   // Must reset everything before |resource_collection_| to ensure all | 
| 115   // resources are returned before resetting |resource_collection_| client. | 115   // resources are returned before resetting |resource_collection_| client. | 
| 116   layer_tree_host_.reset(); | 116   layer_tree_host_.reset(); | 
| 117   root_layer_ = NULL; | 117   root_layer_ = NULL; | 
| 118   delegated_layer_ = NULL; | 118   delegated_layer_ = NULL; | 
| 119   frame_provider_ = NULL; | 119   frame_provider_ = NULL; | 
| 120 #if DCHECK_IS_ON() | 120 #if DCHECK_IS_ON() | 
| 121   // Check collection is empty. | 121   // Check collection is empty. | 
| 122   cc::ReturnedResourceArray returned_resources; | 122   cc::ReturnedResourceArray returned_resources; | 
| 123   resource_collection_->TakeUnusedResourcesForChildCompositor( | 123   resource_collection_->TakeUnusedResourcesForChildCompositor( | 
| 124       &returned_resources); | 124       &returned_resources); | 
| 125   DCHECK_EQ(0u, returned_resources.size()); | 125   DCHECK_EQ(0u, returned_resources.size()); | 
| 126 #endif  // DCHECK_IS_ON() | 126 #endif  // DCHECK_IS_ON() | 
| 127 | 127 | 
| 128   resource_collection_->SetClient(NULL); | 128   resource_collection_->SetClient(NULL); | 
| 129 | 129 | 
| 130   // Reset draw constraints. | 130   // Reset draw constraints. | 
| 131   shared_renderer_state_->UpdateDrawConstraintsOnRT( | 131   shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( | 
| 132       ParentCompositorDrawConstraints()); | 132       ParentCompositorDrawConstraints()); | 
| 133 } | 133 } | 
| 134 | 134 | 
| 135 void HardwareRenderer::DidBeginMainFrame() { | 135 void HardwareRenderer::DidBeginMainFrame() { | 
| 136   // This is called after OutputSurface is created, but before the impl frame | 136   // This is called after OutputSurface is created, but before the impl frame | 
| 137   // starts. We set the draw constraints here. | 137   // starts. We set the draw constraints here. | 
| 138   DCHECK(output_surface_); | 138   DCHECK(output_surface_); | 
| 139   DCHECK(viewport_clip_valid_for_dcheck_); | 139   DCHECK(viewport_clip_valid_for_dcheck_); | 
| 140   output_surface_->SetExternalStencilTest(stencil_enabled_); | 140   output_surface_->SetExternalStencilTest(stencil_enabled_); | 
| 141   output_surface_->SetDrawConstraints(viewport_, clip_); | 141   output_surface_->SetDrawConstraints(viewport_, clip_); | 
| 142 } | 142 } | 
| 143 | 143 | 
| 144 void HardwareRenderer::CommitFrame() { | 144 void HardwareRenderer::CommitFrame() { | 
| 145   TRACE_EVENT0("android_webview", "CommitFrame"); | 145   TRACE_EVENT0("android_webview", "CommitFrame"); | 
| 146   scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); | 146   scroll_offset_ = shared_renderer_state_->GetScrollOffsetOnRT(); | 
| 147   if (committed_frame_.get()) { | 147   { | 
| 148     TRACE_EVENT_INSTANT0("android_webview", | 148     scoped_ptr<ChildFrame> child_frame = | 
| 149                          "EarlyOut_PreviousFrameUnconsumed", | 149         shared_renderer_state_->PassCompositorFrameOnRT(); | 
| 150                          TRACE_EVENT_SCOPE_THREAD); | 150     if (!child_frame.get()) | 
| 151     shared_renderer_state_->DidSkipCommitFrameOnRT(); | 151       return; | 
| 152     return; | 152     child_frame_ = child_frame.Pass(); | 
| 153   } | 153   } | 
| 154 | 154 | 
| 155   committed_frame_ = shared_renderer_state_->PassCompositorFrameOnRT(); | 155   scoped_ptr<cc::CompositorFrame> frame = child_frame_->frame.Pass(); | 
| 156   // Happens with empty global visible rect. | 156   DCHECK(frame.get()); | 
| 157   if (!committed_frame_.get()) | 157   DCHECK(!frame->gl_frame_data); | 
| 158     return; | 158   DCHECK(!frame->software_frame_data); | 
| 159 |  | 
| 160   DCHECK(!committed_frame_->gl_frame_data); |  | 
| 161   DCHECK(!committed_frame_->software_frame_data); |  | 
| 162 | 159 | 
| 163   // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 160   // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 
| 164   // renderer frame, assuming that the browser compositor will scale | 161   // 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 | 162   // 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 | 163   // physical pixels and set our browser CC device_scale_factor to 1, so this | 
| 167   // suppresses the transform. | 164   // suppresses the transform. | 
| 168   committed_frame_->delegated_frame_data->device_scale_factor = 1.0f; | 165   frame->delegated_frame_data->device_scale_factor = 1.0f; | 
| 169 } |  | 
| 170 | 166 | 
| 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 = | 167   gfx::Size frame_size = | 
| 177       frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 168       frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 
| 178   bool size_changed = frame_size != frame_size_; | 169   bool size_changed = frame_size != frame_size_; | 
| 179   frame_size_ = frame_size; | 170   frame_size_ = frame_size; | 
| 180 | 171 | 
| 181   if (!frame_provider_.get() || size_changed) { | 172   if (!frame_provider_.get() || size_changed) { | 
| 182     if (delegated_layer_.get()) { | 173     if (delegated_layer_.get()) { | 
| 183       delegated_layer_->RemoveFromParent(); | 174       delegated_layer_->RemoveFromParent(); | 
| 184     } | 175     } | 
| 185 | 176 | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 203 | 194 | 
| 204   // We need to watch if the current Android context has changed and enforce | 195   // We need to watch if the current Android context has changed and enforce | 
| 205   // a clean-up in the compositor. | 196   // a clean-up in the compositor. | 
| 206   EGLContext current_context = eglGetCurrentContext(); | 197   EGLContext current_context = eglGetCurrentContext(); | 
| 207   DCHECK(current_context) << "DrawGL called without EGLContext"; | 198   DCHECK(current_context) << "DrawGL called without EGLContext"; | 
| 208 | 199 | 
| 209   // TODO(boliu): Handle context loss. | 200   // TODO(boliu): Handle context loss. | 
| 210   if (last_egl_context_ != current_context) | 201   if (last_egl_context_ != current_context) | 
| 211     DLOG(WARNING) << "EGLContextChanged"; | 202     DLOG(WARNING) << "EGLContextChanged"; | 
| 212 | 203 | 
| 213   SetFrameData(); |  | 
| 214   if (shared_renderer_state_->ForceCommitOnRT()) { |  | 
| 215     CommitFrame(); |  | 
| 216     SetFrameData(); |  | 
| 217   } |  | 
| 218 |  | 
| 219   gfx::Transform transform(gfx::Transform::kSkipInitialization); | 204   gfx::Transform transform(gfx::Transform::kSkipInitialization); | 
| 220   transform.matrix().setColMajorf(draw_info->transform); | 205   transform.matrix().setColMajorf(draw_info->transform); | 
| 221   transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 206   transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 
| 222 | 207 | 
| 223   // Need to post the new transform matrix back to child compositor | 208   // Need to post the new transform matrix back to child compositor | 
| 224   // because there is no onDraw during a Render Thread animation, and child | 209   // 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. | 210   // compositor might not have the tiles rasterized as the animation goes on. | 
| 226   ParentCompositorDrawConstraints draw_constraints( | 211   ParentCompositorDrawConstraints draw_constraints( | 
| 227       draw_info->is_layer, transform, gfx::Rect(viewport_)); | 212       draw_info->is_layer, transform, gfx::Rect(viewport_)); | 
| 228 | 213   if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { | 
| 229   draw_constraints_ = draw_constraints; | 214     shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( | 
| 230   shared_renderer_state_->PostExternalDrawConstraintsToChildCompositorOnRT( | 215         draw_constraints); | 
| 231       draw_constraints); | 216   } | 
| 232 | 217 | 
| 233   if (!delegated_layer_.get()) | 218   if (!delegated_layer_.get()) | 
| 234     return; | 219     return; | 
| 235 | 220 | 
| 236   viewport_.SetSize(draw_info->width, draw_info->height); | 221   viewport_.SetSize(draw_info->width, draw_info->height); | 
| 237   layer_tree_host_->SetViewportSize(viewport_); | 222   layer_tree_host_->SetViewportSize(viewport_); | 
| 238   clip_.SetRect(draw_info->clip_left, | 223   clip_.SetRect(draw_info->clip_left, | 
| 239                 draw_info->clip_top, | 224                 draw_info->clip_top, | 
| 240                 draw_info->clip_right - draw_info->clip_left, | 225                 draw_info->clip_right - draw_info->clip_left, | 
| 241                 draw_info->clip_bottom - draw_info->clip_top); | 226                 draw_info->clip_bottom - draw_info->clip_top); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 268 } | 253 } | 
| 269 | 254 | 
| 270 void HardwareRenderer::UnusedResourcesAreAvailable() { | 255 void HardwareRenderer::UnusedResourcesAreAvailable() { | 
| 271   cc::ReturnedResourceArray returned_resources; | 256   cc::ReturnedResourceArray returned_resources; | 
| 272   resource_collection_->TakeUnusedResourcesForChildCompositor( | 257   resource_collection_->TakeUnusedResourcesForChildCompositor( | 
| 273       &returned_resources); | 258       &returned_resources); | 
| 274   shared_renderer_state_->InsertReturnedResourcesOnRT(returned_resources); | 259   shared_renderer_state_->InsertReturnedResourcesOnRT(returned_resources); | 
| 275 } | 260 } | 
| 276 | 261 | 
| 277 }  // namespace android_webview | 262 }  // namespace android_webview | 
| OLD | NEW | 
|---|