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/hardware_renderer_proxy.h" |
9 #include "android_webview/browser/parent_output_surface.h" | 10 #include "android_webview/browser/parent_output_surface.h" |
10 #include "android_webview/browser/shared_renderer_state.h" | |
11 #include "android_webview/public/browser/draw_gl.h" | 11 #include "android_webview/public/browser/draw_gl.h" |
12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "cc/layers/delegated_frame_provider.h" | 15 #include "cc/layers/delegated_frame_provider.h" |
16 #include "cc/layers/delegated_renderer_layer.h" | 16 #include "cc/layers/delegated_renderer_layer.h" |
17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
18 #include "cc/output/compositor_frame.h" | 18 #include "cc/output/compositor_frame.h" |
19 #include "cc/output/output_surface.h" | 19 #include "cc/output/output_surface.h" |
20 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 DCHECK(context.get()); | 66 DCHECK(context.get()); |
67 | 67 |
68 return webkit::gpu::ContextProviderInProcess::Create( | 68 return webkit::gpu::ContextProviderInProcess::Create( |
69 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 69 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
70 context.Pass(), attributes), | 70 context.Pass(), attributes), |
71 "Parent-Compositor"); | 71 "Parent-Compositor"); |
72 } | 72 } |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 HardwareRenderer::HardwareRenderer(SharedRendererState* state) | 76 HardwareRenderer::HardwareRenderer(HardwareRendererProxy* proxy) |
77 : shared_renderer_state_(state), | 77 : proxy_(proxy), |
78 last_egl_context_(eglGetCurrentContext()), | 78 last_egl_context_(eglGetCurrentContext()), |
79 stencil_enabled_(false), | 79 stencil_enabled_(false), |
80 viewport_clip_valid_for_dcheck_(false), | 80 viewport_clip_valid_for_dcheck_(false), |
81 gl_surface_(new AwGLSurface), | 81 gl_surface_(new AwGLSurface), |
82 root_layer_(cc::Layer::Create()), | 82 root_layer_(cc::Layer::Create()), |
83 resource_collection_(new cc::DelegatedFrameResourceCollection), | 83 resource_collection_(new cc::DelegatedFrameResourceCollection), |
84 output_surface_(NULL) { | 84 output_surface_(NULL) { |
85 DCHECK(last_egl_context_); | 85 DCHECK(last_egl_context_); |
86 | 86 |
87 resource_collection_->SetClient(this); | 87 resource_collection_->SetClient(this); |
(...skipping 30 matching lines...) Expand all Loading... |
118 // Check collection is empty. | 118 // Check collection is empty. |
119 cc::ReturnedResourceArray returned_resources; | 119 cc::ReturnedResourceArray returned_resources; |
120 resource_collection_->TakeUnusedResourcesForChildCompositor( | 120 resource_collection_->TakeUnusedResourcesForChildCompositor( |
121 &returned_resources); | 121 &returned_resources); |
122 DCHECK_EQ(0u, returned_resources.size()); | 122 DCHECK_EQ(0u, returned_resources.size()); |
123 #endif // DCHECK_IS_ON | 123 #endif // DCHECK_IS_ON |
124 | 124 |
125 resource_collection_->SetClient(NULL); | 125 resource_collection_->SetClient(NULL); |
126 | 126 |
127 // Reset draw constraints. | 127 // Reset draw constraints. |
128 shared_renderer_state_->UpdateDrawConstraints( | 128 proxy_->SetParentCompositorDrawConstraints(ParentCompositorDrawConstraints()); |
129 ParentCompositorDrawConstraints()); | |
130 } | 129 } |
131 | 130 |
132 void HardwareRenderer::DidBeginMainFrame() { | 131 void HardwareRenderer::DidBeginMainFrame() { |
133 // This is called after OutputSurface is created, but before the impl frame | 132 // This is called after OutputSurface is created, but before the impl frame |
134 // starts. We set the draw constraints here. | 133 // starts. We set the draw constraints here. |
135 DCHECK(output_surface_); | 134 DCHECK(output_surface_); |
136 DCHECK(viewport_clip_valid_for_dcheck_); | 135 DCHECK(viewport_clip_valid_for_dcheck_); |
137 output_surface_->SetExternalStencilTest(stencil_enabled_); | 136 output_surface_->SetExternalStencilTest(stencil_enabled_); |
138 output_surface_->SetDrawConstraints(viewport_, clip_); | 137 output_surface_->SetDrawConstraints(viewport_, clip_); |
139 } | 138 } |
140 | 139 |
141 void HardwareRenderer::CommitFrame() { | 140 void HardwareRenderer::CommitFrame() { |
142 scroll_offset_ = shared_renderer_state_->GetScrollOffset(); | 141 scroll_offset_ = proxy_->GetScrollOffset(); |
143 if (committed_frame_.get()) { | 142 if (committed_frame_.get()) { |
144 TRACE_EVENT_INSTANT0("android_webview", | 143 TRACE_EVENT_INSTANT0("android_webview", |
145 "EarlyOut_PreviousFrameUnconsumed", | 144 "EarlyOut_PreviousFrameUnconsumed", |
146 TRACE_EVENT_SCOPE_THREAD); | 145 TRACE_EVENT_SCOPE_THREAD); |
147 shared_renderer_state_->DidSkipCommitFrame(); | 146 proxy_->DidSkipCommitFrame(); |
148 return; | 147 return; |
149 } | 148 } |
150 | 149 |
151 committed_frame_ = shared_renderer_state_->PassCompositorFrame(); | 150 committed_frame_ = proxy_->PassCompositorFrame(); |
152 // Happens with empty global visible rect. | 151 // Happens with empty global visible rect. |
153 if (!committed_frame_.get()) | 152 if (!committed_frame_.get()) |
154 return; | 153 return; |
155 | 154 |
156 DCHECK(!committed_frame_->gl_frame_data); | 155 DCHECK(!committed_frame_->gl_frame_data); |
157 DCHECK(!committed_frame_->software_frame_data); | 156 DCHECK(!committed_frame_->software_frame_data); |
158 | 157 |
159 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 158 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the |
160 // renderer frame, assuming that the browser compositor will scale | 159 // renderer frame, assuming that the browser compositor will scale |
161 // it back up to device scale. But on Android we put our browser layers in | 160 // it back up to device scale. But on Android we put our browser layers in |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // We need to watch if the current Android context has changed and enforce | 199 // We need to watch if the current Android context has changed and enforce |
201 // a clean-up in the compositor. | 200 // a clean-up in the compositor. |
202 EGLContext current_context = eglGetCurrentContext(); | 201 EGLContext current_context = eglGetCurrentContext(); |
203 DCHECK(current_context) << "DrawGL called without EGLContext"; | 202 DCHECK(current_context) << "DrawGL called without EGLContext"; |
204 | 203 |
205 // TODO(boliu): Handle context loss. | 204 // TODO(boliu): Handle context loss. |
206 if (last_egl_context_ != current_context) | 205 if (last_egl_context_ != current_context) |
207 DLOG(WARNING) << "EGLContextChanged"; | 206 DLOG(WARNING) << "EGLContextChanged"; |
208 | 207 |
209 SetFrameData(); | 208 SetFrameData(); |
210 if (shared_renderer_state_->ForceCommit()) { | 209 if (proxy_->ForceCommit()) { |
211 CommitFrame(); | 210 CommitFrame(); |
212 SetFrameData(); | 211 SetFrameData(); |
213 } | 212 } |
214 | 213 |
215 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 214 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
216 transform.matrix().setColMajorf(draw_info->transform); | 215 transform.matrix().setColMajorf(draw_info->transform); |
217 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 216 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); |
218 | 217 |
219 // Need to post the new transform matrix back to child compositor | 218 // Need to post the new transform matrix back to child compositor |
220 // because there is no onDraw during a Render Thread animation, and child | 219 // because there is no onDraw during a Render Thread animation, and child |
221 // compositor might not have the tiles rasterized as the animation goes on. | 220 // compositor might not have the tiles rasterized as the animation goes on. |
222 ParentCompositorDrawConstraints draw_constraints( | 221 ParentCompositorDrawConstraints draw_constraints( |
223 draw_info->is_layer, transform, gfx::Rect(viewport_)); | 222 draw_info->is_layer, transform, gfx::Rect(viewport_)); |
224 | 223 |
225 draw_constraints_ = draw_constraints; | 224 draw_constraints_ = draw_constraints; |
226 shared_renderer_state_->PostExternalDrawConstraintsToChildCompositor( | 225 proxy_->PostExternalDrawConstraintsToChildCompositor(draw_constraints); |
227 draw_constraints); | |
228 | 226 |
229 if (!delegated_layer_.get()) | 227 if (!delegated_layer_.get()) |
230 return; | 228 return; |
231 | 229 |
232 viewport_.SetSize(draw_info->width, draw_info->height); | 230 viewport_.SetSize(draw_info->width, draw_info->height); |
233 layer_tree_host_->SetViewportSize(viewport_); | 231 layer_tree_host_->SetViewportSize(viewport_); |
234 clip_.SetRect(draw_info->clip_left, | 232 clip_.SetRect(draw_info->clip_left, |
235 draw_info->clip_top, | 233 draw_info->clip_top, |
236 draw_info->clip_right - draw_info->clip_left, | 234 draw_info->clip_right - draw_info->clip_left, |
237 draw_info->clip_bottom - draw_info->clip_top); | 235 draw_info->clip_bottom - draw_info->clip_top); |
(...skipping 20 matching lines...) Expand all Loading... |
258 scoped_ptr<ParentOutputSurface> output_surface_holder( | 256 scoped_ptr<ParentOutputSurface> output_surface_holder( |
259 new ParentOutputSurface(context_provider)); | 257 new ParentOutputSurface(context_provider)); |
260 output_surface_ = output_surface_holder.get(); | 258 output_surface_ = output_surface_holder.get(); |
261 layer_tree_host_->SetOutputSurface(output_surface_holder.Pass()); | 259 layer_tree_host_->SetOutputSurface(output_surface_holder.Pass()); |
262 } | 260 } |
263 | 261 |
264 void HardwareRenderer::UnusedResourcesAreAvailable() { | 262 void HardwareRenderer::UnusedResourcesAreAvailable() { |
265 cc::ReturnedResourceArray returned_resources; | 263 cc::ReturnedResourceArray returned_resources; |
266 resource_collection_->TakeUnusedResourcesForChildCompositor( | 264 resource_collection_->TakeUnusedResourcesForChildCompositor( |
267 &returned_resources); | 265 &returned_resources); |
268 shared_renderer_state_->InsertReturnedResources(returned_resources); | 266 proxy_->InsertReturnedResources(returned_resources); |
269 } | 267 } |
270 | 268 |
271 } // namespace android_webview | 269 } // namespace android_webview |
OLD | NEW |