Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/surfaces_instance.h" | 5 #include "android_webview/browser/surfaces_instance.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "android_webview/browser/aw_gl_surface.h" | 10 #include "android_webview/browser/aw_gl_surface.h" |
| 11 #include "android_webview/browser/aw_render_thread_context_provider.h" | 11 #include "android_webview/browser/aw_render_thread_context_provider.h" |
| 12 #include "android_webview/browser/deferred_gpu_command_service.h" | 12 #include "android_webview/browser/deferred_gpu_command_service.h" |
| 13 #include "android_webview/browser/parent_output_surface.h" | 13 #include "android_webview/browser/parent_output_surface.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "cc/output/renderer_settings.h" | 15 #include "cc/output/renderer_settings.h" |
| 16 #include "cc/output/texture_mailbox_deleter.h" | 16 #include "cc/output/texture_mailbox_deleter.h" |
| 17 #include "cc/quads/surface_draw_quad.h" | 17 #include "cc/quads/surface_draw_quad.h" |
| 18 #include "cc/scheduler/begin_frame_source.h" | 18 #include "cc/scheduler/begin_frame_source.h" |
| 19 #include "cc/surfaces/compositor_frame_sink_support.h" | |
| 19 #include "cc/surfaces/display.h" | 20 #include "cc/surfaces/display.h" |
| 20 #include "cc/surfaces/display_scheduler.h" | 21 #include "cc/surfaces/display_scheduler.h" |
| 21 #include "cc/surfaces/surface_factory.h" | 22 #include "cc/surfaces/surface_factory.h" |
| 22 #include "cc/surfaces/surface_id_allocator.h" | 23 #include "cc/surfaces/surface_id_allocator.h" |
| 23 #include "cc/surfaces/surface_manager.h" | 24 #include "cc/surfaces/surface_manager.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
| 27 | 28 |
| 28 namespace android_webview { | 29 namespace android_webview { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 44 | 45 |
| 45 // Should be kept in sync with compositor_impl_android.cc. | 46 // Should be kept in sync with compositor_impl_android.cc. |
| 46 settings.allow_antialiasing = false; | 47 settings.allow_antialiasing = false; |
| 47 settings.highp_threshold_min = 2048; | 48 settings.highp_threshold_min = 2048; |
| 48 | 49 |
| 49 // Webview does not own the surface so should not clear it. | 50 // Webview does not own the surface so should not clear it. |
| 50 settings.should_clear_root_render_pass = false; | 51 settings.should_clear_root_render_pass = false; |
| 51 | 52 |
| 52 surface_manager_.reset(new cc::SurfaceManager); | 53 surface_manager_.reset(new cc::SurfaceManager); |
| 53 surface_id_allocator_.reset(new cc::SurfaceIdAllocator()); | 54 surface_id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 54 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | |
| 55 surface_factory_.reset( | |
| 56 new cc::SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)); | |
| 57 | 55 |
| 58 begin_frame_source_.reset(new cc::StubBeginFrameSource); | 56 auto begin_frame_source = base::MakeUnique<cc::StubBeginFrameSource>(); |
| 59 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter( | 57 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter( |
| 60 new cc::TextureMailboxDeleter(nullptr)); | 58 new cc::TextureMailboxDeleter(nullptr)); |
| 61 std::unique_ptr<ParentOutputSurface> output_surface_holder( | 59 std::unique_ptr<ParentOutputSurface> output_surface_holder( |
| 62 new ParentOutputSurface(AwRenderThreadContextProvider::Create( | 60 new ParentOutputSurface(AwRenderThreadContextProvider::Create( |
| 63 make_scoped_refptr(new AwGLSurface), | 61 make_scoped_refptr(new AwGLSurface), |
| 64 DeferredGpuCommandService::GetInstance()))); | 62 DeferredGpuCommandService::GetInstance()))); |
| 65 output_surface_ = output_surface_holder.get(); | 63 output_surface_ = output_surface_holder.get(); |
| 66 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 64 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 67 nullptr, output_surface_holder->capabilities().max_frames_pending)); | 65 nullptr, output_surface_holder->capabilities().max_frames_pending)); |
| 68 display_.reset(new cc::Display( | 66 |
| 67 auto display = base::MakeUnique<cc::Display>( | |
| 69 nullptr /* shared_bitmap_manager */, | 68 nullptr /* shared_bitmap_manager */, |
| 70 nullptr /* gpu_memory_buffer_manager */, settings, frame_sink_id_, | 69 nullptr /* gpu_memory_buffer_manager */, settings, frame_sink_id_, |
| 71 begin_frame_source_.get(), std::move(output_surface_holder), | 70 begin_frame_source.get(), std::move(output_surface_holder), |
| 72 std::move(scheduler), std::move(texture_mailbox_deleter))); | 71 std::move(scheduler), std::move(texture_mailbox_deleter)); |
| 73 display_->Initialize(this, surface_manager_.get()); | 72 |
| 74 display_->SetVisible(true); | 73 support_.reset(new cc::CompositorFrameSinkSupport( |
| 74 nullptr, surface_manager_.get(), frame_sink_id_, std::move(display), | |
| 75 std::move(begin_frame_source))); | |
| 75 | 76 |
| 76 DCHECK(!g_surfaces_instance); | 77 DCHECK(!g_surfaces_instance); |
| 77 g_surfaces_instance = this; | 78 g_surfaces_instance = this; |
| 78 | 79 |
| 79 } | 80 } |
| 80 | 81 |
| 81 SurfacesInstance::~SurfacesInstance() { | 82 SurfacesInstance::~SurfacesInstance() { |
| 82 DCHECK_EQ(g_surfaces_instance, this); | 83 DCHECK_EQ(g_surfaces_instance, this); |
| 83 g_surfaces_instance = nullptr; | 84 g_surfaces_instance = nullptr; |
| 84 | 85 |
| 85 DCHECK(child_ids_.empty()); | 86 DCHECK(child_ids_.empty()); |
| 86 surface_factory_->EvictSurface(); | 87 support_->EvictFrame(); |
| 87 | |
| 88 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | |
| 89 } | |
| 90 | |
| 91 void SurfacesInstance::DisplayOutputSurfaceLost() { | |
| 92 // Android WebView does not handle context loss. | |
| 93 LOG(FATAL) << "Render thread context loss"; | |
|
boliu
2017/01/19 22:44:38
need to keep this behavior, so now this needs to b
Saman Sami
2017/01/24 16:04:03
Yes. We can do that.
| |
| 94 } | 88 } |
| 95 | 89 |
| 96 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() { | 90 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() { |
| 97 return cc::FrameSinkId(next_client_id_++, 0 /* sink_id */); | 91 return cc::FrameSinkId(next_client_id_++, 0 /* sink_id */); |
| 98 } | 92 } |
| 99 | 93 |
| 100 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() { | 94 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() { |
| 101 return surface_manager_.get(); | 95 return surface_manager_.get(); |
| 102 } | 96 } |
| 103 | 97 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 126 | 120 |
| 127 cc::SurfaceDrawQuad* surface_quad = | 121 cc::SurfaceDrawQuad* surface_quad = |
| 128 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 122 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 129 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), | 123 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), |
| 130 gfx::Rect(quad_state->quad_layer_bounds), child_id); | 124 gfx::Rect(quad_state->quad_layer_bounds), child_id); |
| 131 | 125 |
| 132 cc::CompositorFrame frame; | 126 cc::CompositorFrame frame; |
| 133 frame.render_pass_list.push_back(std::move(render_pass)); | 127 frame.render_pass_list.push_back(std::move(render_pass)); |
| 134 frame.metadata.referenced_surfaces = child_ids_; | 128 frame.metadata.referenced_surfaces = child_ids_; |
| 135 | 129 |
| 136 if (!root_id_.is_valid()) { | 130 if (!root_id_.is_valid()) |
| 137 root_id_ = surface_id_allocator_->GenerateId(); | 131 root_id_ = surface_id_allocator_->GenerateId(); |
| 138 display_->SetLocalFrameId(root_id_, 1.f); | |
| 139 } | |
| 140 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame), | |
| 141 cc::SurfaceFactory::DrawCallback()); | |
| 142 | 132 |
| 143 display_->Resize(viewport); | 133 support_->SubmitCompositorFrame(root_id_, std::move(frame)); |
| 144 display_->DrawAndSwap(); | 134 |
| 135 support_->display()->Resize(viewport); | |
| 136 support_->display()->DrawAndSwap(); | |
| 145 } | 137 } |
| 146 | 138 |
| 147 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { | 139 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { |
| 148 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == | 140 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == |
| 149 child_ids_.end()); | 141 child_ids_.end()); |
| 150 child_ids_.push_back(child_id); | 142 child_ids_.push_back(child_id); |
| 151 if (root_id_.is_valid()) | 143 if (root_id_.is_valid()) |
| 152 SetEmptyRootFrame(); | 144 SetEmptyRootFrame(); |
| 153 } | 145 } |
| 154 | 146 |
| 155 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { | 147 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { |
| 156 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); | 148 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); |
| 157 DCHECK(itr != child_ids_.end()); | 149 DCHECK(itr != child_ids_.end()); |
| 158 child_ids_.erase(itr); | 150 child_ids_.erase(itr); |
| 159 if (root_id_.is_valid()) | 151 if (root_id_.is_valid()) |
| 160 SetEmptyRootFrame(); | 152 SetEmptyRootFrame(); |
| 161 } | 153 } |
| 162 | 154 |
| 163 void SurfacesInstance::SetEmptyRootFrame() { | 155 void SurfacesInstance::SetEmptyRootFrame() { |
| 164 cc::CompositorFrame empty_frame; | 156 cc::CompositorFrame empty_frame; |
| 165 empty_frame.metadata.referenced_surfaces = child_ids_; | 157 empty_frame.metadata.referenced_surfaces = child_ids_; |
| 166 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame), | 158 support_->SubmitCompositorFrame(root_id_, std::move(empty_frame)); |
| 167 cc::SurfaceFactory::DrawCallback()); | |
| 168 } | |
| 169 | |
| 170 void SurfacesInstance::ReturnResources( | |
| 171 const cc::ReturnedResourceArray& resources) { | |
| 172 // Root surface should have no resources to return. | |
| 173 CHECK(resources.empty()); | |
| 174 } | |
| 175 | |
| 176 void SurfacesInstance::SetBeginFrameSource( | |
| 177 cc::BeginFrameSource* begin_frame_source) { | |
| 178 // Parent compsitor calls DrawAndSwap directly and doesn't use | |
| 179 // BeginFrameSource. | |
| 180 } | 159 } |
| 181 | 160 |
| 182 } // namespace android_webview | 161 } // namespace android_webview |
| OLD | NEW |