| 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 12 matching lines...) Expand all Loading... |
| 23 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
| 24 | 24 |
| 25 namespace android_webview { | 25 namespace android_webview { |
| 26 | 26 |
| 27 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) | 27 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) |
| 28 : render_thread_manager_(state), | 28 : render_thread_manager_(state), |
| 29 last_egl_context_(eglGetCurrentContext()), | 29 last_egl_context_(eglGetCurrentContext()), |
| 30 surfaces_(SurfacesInstance::GetOrCreateInstance()), | 30 surfaces_(SurfacesInstance::GetOrCreateInstance()), |
| 31 frame_sink_id_(surfaces_->AllocateFrameSinkId()), | 31 frame_sink_id_(surfaces_->AllocateFrameSinkId()), |
| 32 surface_id_allocator_(base::MakeUnique<cc::SurfaceIdAllocator>()), | 32 surface_id_allocator_(base::MakeUnique<cc::SurfaceIdAllocator>()), |
| 33 surface_factory_(new cc::SurfaceFactory(frame_sink_id_, |
| 34 surfaces_->GetSurfaceManager(), |
| 35 this)), |
| 33 last_committed_compositor_frame_sink_id_(0u), | 36 last_committed_compositor_frame_sink_id_(0u), |
| 34 last_submitted_compositor_frame_sink_id_(0u) { | 37 last_submitted_compositor_frame_sink_id_(0u) { |
| 35 DCHECK(last_egl_context_); | 38 DCHECK(last_egl_context_); |
| 36 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); | 39 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |
| 37 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, | 40 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, |
| 38 this); | 41 this); |
| 39 } | 42 } |
| 40 | 43 |
| 41 HardwareRenderer::~HardwareRenderer() { | 44 HardwareRenderer::~HardwareRenderer() { |
| 42 // Must reset everything before |surface_factory_| to ensure all | 45 // Must reset everything before |surface_factory_| to ensure all |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | 91 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
| 89 // unnecessary kModeProcess. | 92 // unnecessary kModeProcess. |
| 90 if (child_frame_.get() && child_frame_->frame.get()) { | 93 if (child_frame_.get() && child_frame_->frame.get()) { |
| 91 if (!compositor_id_.Equals(child_frame_->compositor_id) || | 94 if (!compositor_id_.Equals(child_frame_->compositor_id) || |
| 92 last_submitted_compositor_frame_sink_id_ != | 95 last_submitted_compositor_frame_sink_id_ != |
| 93 child_frame_->compositor_frame_sink_id) { | 96 child_frame_->compositor_frame_sink_id) { |
| 94 if (!child_id_.is_null()) | 97 if (!child_id_.is_null()) |
| 95 DestroySurface(); | 98 DestroySurface(); |
| 96 | 99 |
| 97 // This will return all the resources to the previous compositor. | 100 // This will return all the resources to the previous compositor. |
| 98 surface_factory_.reset(); | 101 surface_factory_->Reset(); |
| 99 compositor_id_ = child_frame_->compositor_id; | 102 compositor_id_ = child_frame_->compositor_id; |
| 100 last_submitted_compositor_frame_sink_id_ = | 103 last_submitted_compositor_frame_sink_id_ = |
| 101 child_frame_->compositor_frame_sink_id; | 104 child_frame_->compositor_frame_sink_id; |
| 102 surface_factory_.reset(new cc::SurfaceFactory( | |
| 103 frame_sink_id_, surfaces_->GetSurfaceManager(), this)); | |
| 104 } | 105 } |
| 105 | 106 |
| 106 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = | 107 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = |
| 107 std::move(child_frame_->frame); | 108 std::move(child_frame_->frame); |
| 108 | 109 |
| 109 gfx::Size frame_size = | 110 gfx::Size frame_size = |
| 110 child_compositor_frame->render_pass_list.back()->output_rect.size(); | 111 child_compositor_frame->render_pass_list.back()->output_rect.size(); |
| 111 bool size_changed = frame_size != frame_size_; | 112 bool size_changed = frame_size != frame_size_; |
| 112 frame_size_ = frame_size; | 113 frame_size_ = frame_size; |
| 113 if (child_id_.is_null() || size_changed) { | 114 if (child_id_.is_null() || size_changed) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 141 | 142 |
| 142 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, | 143 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, |
| 143 draw_info->clip_right - draw_info->clip_left, | 144 draw_info->clip_right - draw_info->clip_left, |
| 144 draw_info->clip_bottom - draw_info->clip_top); | 145 draw_info->clip_bottom - draw_info->clip_top); |
| 145 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, | 146 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, |
| 146 cc::SurfaceId(frame_sink_id_, child_id_)); | 147 cc::SurfaceId(frame_sink_id_, child_id_)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void HardwareRenderer::AllocateSurface() { | 150 void HardwareRenderer::AllocateSurface() { |
| 150 DCHECK(child_id_.is_null()); | 151 DCHECK(child_id_.is_null()); |
| 151 DCHECK(surface_factory_); | |
| 152 child_id_ = surface_id_allocator_->GenerateId(); | 152 child_id_ = surface_id_allocator_->GenerateId(); |
| 153 surface_factory_->Create(child_id_); | 153 surface_factory_->Create(child_id_); |
| 154 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 154 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void HardwareRenderer::DestroySurface() { | 157 void HardwareRenderer::DestroySurface() { |
| 158 DCHECK(!child_id_.is_null()); | 158 DCHECK(!child_id_.is_null()); |
| 159 DCHECK(surface_factory_); | |
| 160 | 159 |
| 161 // Submit an empty frame to force any existing resources to be returned. | 160 // Submit an empty frame to force any existing resources to be returned. |
| 162 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), | 161 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), |
| 163 cc::SurfaceFactory::DrawCallback()); | 162 cc::SurfaceFactory::DrawCallback()); |
| 164 | 163 |
| 165 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 164 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 166 surface_factory_->Destroy(child_id_); | 165 surface_factory_->Destroy(child_id_); |
| 167 child_id_ = cc::LocalFrameId(); | 166 child_id_ = cc::LocalFrameId(); |
| 168 } | 167 } |
| 169 | 168 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 197 const cc::ReturnedResourceArray& resources, | 196 const cc::ReturnedResourceArray& resources, |
| 198 const CompositorID& compositor_id, | 197 const CompositorID& compositor_id, |
| 199 uint32_t compositor_frame_sink_id) { | 198 uint32_t compositor_frame_sink_id) { |
| 200 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) | 199 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) |
| 201 return; | 200 return; |
| 202 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, | 201 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, |
| 203 compositor_frame_sink_id); | 202 compositor_frame_sink_id); |
| 204 } | 203 } |
| 205 | 204 |
| 206 } // namespace android_webview | 205 } // namespace android_webview |
| OLD | NEW |