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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "android_webview/browser/aw_gl_surface.h" | 9 #include "android_webview/browser/aw_gl_surface.h" |
10 #include "android_webview/browser/aw_render_thread_context_provider.h" | 10 #include "android_webview/browser/aw_render_thread_context_provider.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "ui/gfx/geometry/rect_f.h" | 31 #include "ui/gfx/geometry/rect_f.h" |
32 #include "ui/gfx/transform.h" | 32 #include "ui/gfx/transform.h" |
33 #include "ui/gl/gl_bindings.h" | 33 #include "ui/gl/gl_bindings.h" |
34 | 34 |
35 namespace android_webview { | 35 namespace android_webview { |
36 | 36 |
37 HardwareRenderer::HardwareRenderer(SharedRendererState* state) | 37 HardwareRenderer::HardwareRenderer(SharedRendererState* state) |
38 : shared_renderer_state_(state), | 38 : shared_renderer_state_(state), |
39 last_egl_context_(eglGetCurrentContext()), | 39 last_egl_context_(eglGetCurrentContext()), |
40 gl_surface_(new AwGLSurface), | 40 gl_surface_(new AwGLSurface), |
41 compositor_id_(0), // Valid compositor id starts at 1. | 41 compositor_id_(0u), // Valid compositor id starts at 1. |
42 output_surface_id_(0u), | |
42 output_surface_(NULL) { | 43 output_surface_(NULL) { |
43 DCHECK(last_egl_context_); | 44 DCHECK(last_egl_context_); |
44 | 45 |
45 cc::RendererSettings settings; | 46 cc::RendererSettings settings; |
46 | 47 |
47 // Should be kept in sync with compositor_impl_android.cc. | 48 // Should be kept in sync with compositor_impl_android.cc. |
48 settings.allow_antialiasing = false; | 49 settings.allow_antialiasing = false; |
49 settings.highp_threshold_min = 2048; | 50 settings.highp_threshold_min = 2048; |
50 | 51 |
51 // Webview does not own the surface so should not clear it. | 52 // Webview does not own the surface so should not clear it. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 99 |
99 // TODO(boliu): Handle context loss. | 100 // TODO(boliu): Handle context loss. |
100 if (last_egl_context_ != current_context) | 101 if (last_egl_context_ != current_context) |
101 DLOG(WARNING) << "EGLContextChanged"; | 102 DLOG(WARNING) << "EGLContextChanged"; |
102 | 103 |
103 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it | 104 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it |
104 // during "kModeSync" stage (which does not allow GL) might result in extra | 105 // during "kModeSync" stage (which does not allow GL) might result in extra |
105 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | 106 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
106 // unnecessary kModeProcess. | 107 // unnecessary kModeProcess. |
107 if (child_frame_.get() && child_frame_->frame.get()) { | 108 if (child_frame_.get() && child_frame_->frame.get()) { |
108 if (compositor_id_ != child_frame_->compositor_id) { | 109 if (compositor_id_ != child_frame_->compositor_id || |
110 output_surface_id_ != child_frame_->output_surface_id) { | |
109 if (!root_id_.is_null()) | 111 if (!root_id_.is_null()) |
110 surface_factory_->Destroy(root_id_); | 112 surface_factory_->Destroy(root_id_); |
111 if (!child_id_.is_null()) | 113 if (!child_id_.is_null()) |
112 surface_factory_->Destroy(child_id_); | 114 surface_factory_->Destroy(child_id_); |
113 | 115 |
114 root_id_ = cc::SurfaceId(); | 116 root_id_ = cc::SurfaceId(); |
115 child_id_ = cc::SurfaceId(); | 117 child_id_ = cc::SurfaceId(); |
116 | 118 |
117 // This will return all the resources to the previous compositor. | 119 // This will return all the resources to the previous compositor. |
118 surface_factory_.reset(); | 120 surface_factory_.reset(); |
119 compositor_id_ = child_frame_->compositor_id; | 121 compositor_id_ = child_frame_->compositor_id; |
122 output_surface_id_ = child_frame_->output_surface_id; | |
120 surface_factory_.reset( | 123 surface_factory_.reset( |
121 new cc::SurfaceFactory(surface_manager_.get(), this)); | 124 new cc::SurfaceFactory(surface_manager_.get(), this)); |
122 } | 125 } |
123 | 126 |
124 scoped_ptr<cc::CompositorFrame> child_compositor_frame = | 127 scoped_ptr<cc::CompositorFrame> child_compositor_frame = |
125 std::move(child_frame_->frame); | 128 std::move(child_frame_->frame); |
126 | 129 |
127 // On Android we put our browser layers in physical pixels and set our | 130 // On Android we put our browser layers in physical pixels and set our |
128 // browser CC device_scale_factor to 1, so suppress the transform between | 131 // browser CC device_scale_factor to 1, so suppress the transform between |
129 // DIP and pixels. | 132 // DIP and pixels. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 output_surface_ = output_surface_holder.get(); | 214 output_surface_ = output_surface_holder.get(); |
212 display_->Initialize(std::move(output_surface_holder), nullptr); | 215 display_->Initialize(std::move(output_surface_holder), nullptr); |
213 } | 216 } |
214 output_surface_->SetGLState(gl_state); | 217 output_surface_->SetGLState(gl_state); |
215 display_->SetExternalClip(clip); | 218 display_->SetExternalClip(clip); |
216 display_->DrawAndSwap(); | 219 display_->DrawAndSwap(); |
217 } | 220 } |
218 | 221 |
219 void HardwareRenderer::ReturnResources( | 222 void HardwareRenderer::ReturnResources( |
220 const cc::ReturnedResourceArray& resources) { | 223 const cc::ReturnedResourceArray& resources) { |
221 ReturnResourcesToCompositor(resources, compositor_id_); | 224 ReturnResourcesToCompositor(resources, compositor_id_, output_surface_id_); |
222 } | 225 } |
223 | 226 |
224 void HardwareRenderer::SetBeginFrameSource( | 227 void HardwareRenderer::SetBeginFrameSource( |
225 cc::SurfaceId surface_id, | 228 cc::SurfaceId surface_id, |
226 cc::BeginFrameSource* begin_frame_source) { | 229 cc::BeginFrameSource* begin_frame_source) { |
227 // TODO(tansell): Hook this up. | 230 // TODO(tansell): Hook this up. |
228 } | 231 } |
229 | 232 |
230 void HardwareRenderer::SetBackingFrameBufferObject( | 233 void HardwareRenderer::SetBackingFrameBufferObject( |
231 int framebuffer_binding_ext) { | 234 int framebuffer_binding_ext) { |
232 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); | 235 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); |
233 } | 236 } |
234 | 237 |
235 void HardwareRenderer::ReturnResourcesInChildFrame() { | 238 void HardwareRenderer::ReturnResourcesInChildFrame() { |
236 if (child_frame_.get() && child_frame_->frame.get()) { | 239 if (child_frame_.get() && child_frame_->frame.get()) { |
237 cc::ReturnedResourceArray resources_to_return; | 240 cc::ReturnedResourceArray resources_to_return; |
238 cc::TransferableResource::ReturnResources( | 241 cc::TransferableResource::ReturnResources( |
239 child_frame_->frame->delegated_frame_data->resource_list, | 242 child_frame_->frame->delegated_frame_data->resource_list, |
240 &resources_to_return); | 243 &resources_to_return); |
241 | 244 |
242 // The child frame's compositor id is not necessarily same as | 245 // The child frame's compositor id is not necessarily same as |
243 // compositor_id_. | 246 // compositor_id_. |
244 ReturnResourcesToCompositor(resources_to_return, | 247 ReturnResourcesToCompositor(resources_to_return, |
245 child_frame_->compositor_id); | 248 child_frame_->compositor_id, |
249 child_frame_->output_surface_id); | |
246 } | 250 } |
247 child_frame_.reset(); | 251 child_frame_.reset(); |
248 } | 252 } |
249 | 253 |
250 void HardwareRenderer::ReturnResourcesToCompositor( | 254 void HardwareRenderer::ReturnResourcesToCompositor( |
251 const cc::ReturnedResourceArray& resources, | 255 const cc::ReturnedResourceArray& resources, |
252 unsigned int compositor_id) { | 256 unsigned int compositor_id, |
253 shared_renderer_state_->InsertReturnedResourcesOnRT(resources, compositor_id); | 257 uint32_t output_surface_id) { |
hush (inactive)
2016/03/08 23:55:49
A bit weird that we have both unsigned int and uin
boliu
2016/03/09 00:29:58
Compositor_id doesn't leave the browser process, s
| |
258 shared_renderer_state_->InsertReturnedResourcesOnRT(resources, compositor_id, | |
259 output_surface_id); | |
254 } | 260 } |
255 | 261 |
256 } // namespace android_webview | 262 } // namespace android_webview |
OLD | NEW |