Chromium Code Reviews| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); | |
|
hush (inactive)
2014/09/20 02:15:53
what is the purpose of this?
setFrameData() is onl
boliu
2014/09/20 02:20:21
All resources *must* be returned to child. This pu
| |
| 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 Loading... | |
| 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 Loading... | |
| 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"; |
|
hush (inactive)
2014/09/20 02:15:53
this means in production code we will continue wit
boliu
2014/09/20 02:20:21
Yes. This shouldn't happen anymore since we tear d
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |