| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 104 |
| 104 // TODO(boliu): Handle context loss. | 105 // TODO(boliu): Handle context loss. |
| 105 if (last_egl_context_ != current_context) | 106 if (last_egl_context_ != current_context) |
| 106 DLOG(WARNING) << "EGLContextChanged"; | 107 DLOG(WARNING) << "EGLContextChanged"; |
| 107 | 108 |
| 108 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it | 109 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it |
| 109 // during "kModeSync" stage (which does not allow GL) might result in extra | 110 // during "kModeSync" stage (which does not allow GL) might result in extra |
| 110 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | 111 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
| 111 // unnecessary kModeProcess. | 112 // unnecessary kModeProcess. |
| 112 if (child_frame_.get() && child_frame_->frame.get()) { | 113 if (child_frame_.get() && child_frame_->frame.get()) { |
| 113 if (compositor_id_ != child_frame_->compositor_id) { | 114 if (compositor_id_ != child_frame_->compositor_id || |
| 115 output_surface_id_ != child_frame_->output_surface_id) { |
| 114 if (!root_id_.is_null()) | 116 if (!root_id_.is_null()) |
| 115 surface_factory_->Destroy(root_id_); | 117 surface_factory_->Destroy(root_id_); |
| 116 if (!child_id_.is_null()) | 118 if (!child_id_.is_null()) |
| 117 surface_factory_->Destroy(child_id_); | 119 surface_factory_->Destroy(child_id_); |
| 118 | 120 |
| 119 root_id_ = cc::SurfaceId(); | 121 root_id_ = cc::SurfaceId(); |
| 120 child_id_ = cc::SurfaceId(); | 122 child_id_ = cc::SurfaceId(); |
| 121 | 123 |
| 122 // This will return all the resources to the previous compositor. | 124 // This will return all the resources to the previous compositor. |
| 123 surface_factory_.reset(); | 125 surface_factory_.reset(); |
| 124 compositor_id_ = child_frame_->compositor_id; | 126 compositor_id_ = child_frame_->compositor_id; |
| 127 output_surface_id_ = child_frame_->output_surface_id; |
| 125 surface_factory_.reset( | 128 surface_factory_.reset( |
| 126 new cc::SurfaceFactory(surface_manager_.get(), this)); | 129 new cc::SurfaceFactory(surface_manager_.get(), this)); |
| 127 } | 130 } |
| 128 | 131 |
| 129 scoped_ptr<cc::CompositorFrame> child_compositor_frame = | 132 scoped_ptr<cc::CompositorFrame> child_compositor_frame = |
| 130 std::move(child_frame_->frame); | 133 std::move(child_frame_->frame); |
| 131 | 134 |
| 132 // On Android we put our browser layers in physical pixels and set our | 135 // On Android we put our browser layers in physical pixels and set our |
| 133 // browser CC device_scale_factor to 1, so suppress the transform between | 136 // browser CC device_scale_factor to 1, so suppress the transform between |
| 134 // DIP and pixels. | 137 // DIP and pixels. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 output_surface_ = output_surface_holder.get(); | 219 output_surface_ = output_surface_holder.get(); |
| 217 display_->Initialize(std::move(output_surface_holder), nullptr); | 220 display_->Initialize(std::move(output_surface_holder), nullptr); |
| 218 } | 221 } |
| 219 output_surface_->SetGLState(gl_state); | 222 output_surface_->SetGLState(gl_state); |
| 220 display_->SetExternalClip(clip); | 223 display_->SetExternalClip(clip); |
| 221 display_->DrawAndSwap(); | 224 display_->DrawAndSwap(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 void HardwareRenderer::ReturnResources( | 227 void HardwareRenderer::ReturnResources( |
| 225 const cc::ReturnedResourceArray& resources) { | 228 const cc::ReturnedResourceArray& resources) { |
| 226 ReturnResourcesToCompositor(resources, compositor_id_); | 229 ReturnResourcesToCompositor(resources, compositor_id_, output_surface_id_); |
| 227 } | 230 } |
| 228 | 231 |
| 229 void HardwareRenderer::SetBeginFrameSource( | 232 void HardwareRenderer::SetBeginFrameSource( |
| 230 cc::BeginFrameSource* begin_frame_source) { | 233 cc::BeginFrameSource* begin_frame_source) { |
| 231 // TODO(tansell): Hook this up. | 234 // TODO(tansell): Hook this up. |
| 232 } | 235 } |
| 233 | 236 |
| 234 void HardwareRenderer::SetBackingFrameBufferObject( | 237 void HardwareRenderer::SetBackingFrameBufferObject( |
| 235 int framebuffer_binding_ext) { | 238 int framebuffer_binding_ext) { |
| 236 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); | 239 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext); |
| 237 } | 240 } |
| 238 | 241 |
| 239 void HardwareRenderer::ReturnResourcesInChildFrame() { | 242 void HardwareRenderer::ReturnResourcesInChildFrame() { |
| 240 if (child_frame_.get() && child_frame_->frame.get()) { | 243 if (child_frame_.get() && child_frame_->frame.get()) { |
| 241 cc::ReturnedResourceArray resources_to_return; | 244 cc::ReturnedResourceArray resources_to_return; |
| 242 cc::TransferableResource::ReturnResources( | 245 cc::TransferableResource::ReturnResources( |
| 243 child_frame_->frame->delegated_frame_data->resource_list, | 246 child_frame_->frame->delegated_frame_data->resource_list, |
| 244 &resources_to_return); | 247 &resources_to_return); |
| 245 | 248 |
| 246 // The child frame's compositor id is not necessarily same as | 249 // The child frame's compositor id is not necessarily same as |
| 247 // compositor_id_. | 250 // compositor_id_. |
| 248 ReturnResourcesToCompositor(resources_to_return, | 251 ReturnResourcesToCompositor(resources_to_return, |
| 249 child_frame_->compositor_id); | 252 child_frame_->compositor_id, |
| 253 child_frame_->output_surface_id); |
| 250 } | 254 } |
| 251 child_frame_.reset(); | 255 child_frame_.reset(); |
| 252 } | 256 } |
| 253 | 257 |
| 254 void HardwareRenderer::ReturnResourcesToCompositor( | 258 void HardwareRenderer::ReturnResourcesToCompositor( |
| 255 const cc::ReturnedResourceArray& resources, | 259 const cc::ReturnedResourceArray& resources, |
| 256 uint32_t compositor_id) { | 260 uint32_t compositor_id, |
| 257 shared_renderer_state_->InsertReturnedResourcesOnRT(resources, compositor_id); | 261 uint32_t output_surface_id) { |
| 262 shared_renderer_state_->InsertReturnedResourcesOnRT(resources, compositor_id, |
| 263 output_surface_id); |
| 258 } | 264 } |
| 259 | 265 |
| 260 } // namespace android_webview | 266 } // namespace android_webview |
| OLD | NEW |