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