| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 SurfacesInstance* g_surfaces_instance = nullptr; | 31 SurfacesInstance* g_surfaces_instance = nullptr; |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 scoped_refptr<SurfacesInstance> SurfacesInstance::GetOrCreateInstance() { | 35 scoped_refptr<SurfacesInstance> SurfacesInstance::GetOrCreateInstance() { |
| 36 if (g_surfaces_instance) | 36 if (g_surfaces_instance) |
| 37 return make_scoped_refptr(g_surfaces_instance); | 37 return make_scoped_refptr(g_surfaces_instance); |
| 38 return make_scoped_refptr(new SurfacesInstance); | 38 return make_scoped_refptr(new SurfacesInstance); |
| 39 } | 39 } |
| 40 | 40 |
| 41 SurfacesInstance::SurfacesInstance() : next_frame_sink_id_(1u) { | 41 SurfacesInstance::SurfacesInstance() |
| 42 : next_client_id_(1u), frame_sink_id_(AllocateFrameSinkId()) { |
| 42 cc::RendererSettings settings; | 43 cc::RendererSettings settings; |
| 43 | 44 |
| 44 // Should be kept in sync with compositor_impl_android.cc. | 45 // Should be kept in sync with compositor_impl_android.cc. |
| 45 settings.allow_antialiasing = false; | 46 settings.allow_antialiasing = false; |
| 46 settings.highp_threshold_min = 2048; | 47 settings.highp_threshold_min = 2048; |
| 47 | 48 |
| 48 // Webview does not own the surface so should not clear it. | 49 // Webview does not own the surface so should not clear it. |
| 49 settings.should_clear_root_render_pass = false; | 50 settings.should_clear_root_render_pass = false; |
| 50 | 51 |
| 51 surface_manager_.reset(new cc::SurfaceManager); | 52 surface_manager_.reset(new cc::SurfaceManager); |
| 52 surface_id_allocator_.reset(new cc::SurfaceIdAllocator( | 53 surface_id_allocator_.reset(new cc::SurfaceIdAllocator(frame_sink_id_)); |
| 53 cc::FrameSinkId(next_frame_sink_id_++, 0 /* frame_sink_id */))); | 54 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 54 surface_manager_->RegisterFrameSinkId(surface_id_allocator_->frame_sink_id()); | |
| 55 | 55 |
| 56 std::unique_ptr<cc::BeginFrameSource> begin_frame_source( | 56 std::unique_ptr<cc::BeginFrameSource> begin_frame_source( |
| 57 new cc::StubBeginFrameSource); | 57 new cc::StubBeginFrameSource); |
| 58 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter( | 58 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter( |
| 59 new cc::TextureMailboxDeleter(nullptr)); | 59 new cc::TextureMailboxDeleter(nullptr)); |
| 60 std::unique_ptr<ParentOutputSurface> output_surface_holder( | 60 std::unique_ptr<ParentOutputSurface> output_surface_holder( |
| 61 new ParentOutputSurface(AwRenderThreadContextProvider::Create( | 61 new ParentOutputSurface(AwRenderThreadContextProvider::Create( |
| 62 make_scoped_refptr(new AwGLSurface), | 62 make_scoped_refptr(new AwGLSurface), |
| 63 DeferredGpuCommandService::GetInstance()))); | 63 DeferredGpuCommandService::GetInstance()))); |
| 64 output_surface_ = output_surface_holder.get(); | 64 output_surface_ = output_surface_holder.get(); |
| 65 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 65 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 66 begin_frame_source.get(), nullptr, | 66 begin_frame_source.get(), nullptr, |
| 67 output_surface_holder->capabilities().max_frames_pending)); | 67 output_surface_holder->capabilities().max_frames_pending)); |
| 68 display_.reset(new cc::Display( | 68 display_.reset(new cc::Display( |
| 69 nullptr /* shared_bitmap_manager */, | 69 nullptr /* shared_bitmap_manager */, |
| 70 nullptr /* gpu_memory_buffer_manager */, settings, | 70 nullptr /* gpu_memory_buffer_manager */, settings, |
| 71 std::move(begin_frame_source), std::move(output_surface_holder), | 71 std::move(begin_frame_source), std::move(output_surface_holder), |
| 72 std::move(scheduler), std::move(texture_mailbox_deleter))); | 72 std::move(scheduler), std::move(texture_mailbox_deleter))); |
| 73 display_->Initialize(this, surface_manager_.get(), | 73 display_->Initialize(this, surface_manager_.get(), frame_sink_id_); |
| 74 surface_id_allocator_->frame_sink_id()); | |
| 75 display_->SetVisible(true); | 74 display_->SetVisible(true); |
| 76 | 75 |
| 77 surface_factory_.reset(new cc::SurfaceFactory(surface_manager_.get(), this)); | 76 surface_factory_.reset( |
| 77 new cc::SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)); |
| 78 | 78 |
| 79 DCHECK(!g_surfaces_instance); | 79 DCHECK(!g_surfaces_instance); |
| 80 g_surfaces_instance = this; | 80 g_surfaces_instance = this; |
| 81 | 81 |
| 82 } | 82 } |
| 83 | 83 |
| 84 SurfacesInstance::~SurfacesInstance() { | 84 SurfacesInstance::~SurfacesInstance() { |
| 85 DCHECK_EQ(g_surfaces_instance, this); | 85 DCHECK_EQ(g_surfaces_instance, this); |
| 86 g_surfaces_instance = nullptr; | 86 g_surfaces_instance = nullptr; |
| 87 | 87 |
| 88 DCHECK(child_ids_.empty()); | 88 DCHECK(child_ids_.empty()); |
| 89 if (!root_id_.is_null()) | 89 if (!root_id_.is_null()) |
| 90 surface_factory_->Destroy(root_id_); | 90 surface_factory_->Destroy(root_id_); |
| 91 | 91 |
| 92 surface_manager_->InvalidateFrameSinkId( | 92 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 93 surface_id_allocator_->frame_sink_id()); | |
| 94 } | 93 } |
| 95 | 94 |
| 96 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() { | 95 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() { |
| 97 return cc::FrameSinkId(next_frame_sink_id_++, 0 /* sink_id */); | 96 return cc::FrameSinkId(next_client_id_++, 0 /* sink_id */); |
| 98 } | 97 } |
| 99 | 98 |
| 100 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() { | 99 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() { |
| 101 return surface_manager_.get(); | 100 return surface_manager_.get(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport, | 103 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport, |
| 105 const gfx::Rect& clip, | 104 const gfx::Rect& clip, |
| 106 const gfx::Transform& transform, | 105 const gfx::Transform& transform, |
| 107 const gfx::Size& frame_size, | 106 const gfx::Size& frame_size, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 CHECK(resources.empty()); | 177 CHECK(resources.empty()); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void SurfacesInstance::SetBeginFrameSource( | 180 void SurfacesInstance::SetBeginFrameSource( |
| 182 cc::BeginFrameSource* begin_frame_source) { | 181 cc::BeginFrameSource* begin_frame_source) { |
| 183 // Parent compsitor calls DrawAndSwap directly and doesn't use | 182 // Parent compsitor calls DrawAndSwap directly and doesn't use |
| 184 // BeginFrameSource. | 183 // BeginFrameSource. |
| 185 } | 184 } |
| 186 | 185 |
| 187 } // namespace android_webview | 186 } // namespace android_webview |
| OLD | NEW |