Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: android_webview/browser/surfaces_instance.cc

Issue 2090903002: aw: Share cc::Display instance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: raw pointers Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "android_webview/browser/surfaces_instance.h"
6
7 #include <algorithm>
8 #include <utility>
9
10 #include "android_webview/browser/aw_gl_surface.h"
11 #include "android_webview/browser/aw_render_thread_context_provider.h"
12 #include "android_webview/browser/deferred_gpu_command_service.h"
13 #include "android_webview/browser/parent_output_surface.h"
14 #include "base/memory/ptr_util.h"
15 #include "cc/output/renderer_settings.h"
16 #include "cc/output/texture_mailbox_deleter.h"
17 #include "cc/quads/surface_draw_quad.h"
18 #include "cc/scheduler/begin_frame_source.h"
19 #include "cc/surfaces/display.h"
20 #include "cc/surfaces/display_scheduler.h"
21 #include "cc/surfaces/surface_factory.h"
22 #include "cc/surfaces/surface_id_allocator.h"
23 #include "cc/surfaces/surface_manager.h"
24 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/geometry/size.h"
26 #include "ui/gfx/transform.h"
27
28 namespace android_webview {
29
30 namespace {
31 SurfacesInstance* g_surfaces_instance = nullptr;
32 } // namespace
33
34 // static
35 scoped_refptr<SurfacesInstance> SurfacesInstance::GetOrCreateInstance() {
36 if (g_surfaces_instance)
37 return make_scoped_refptr(g_surfaces_instance);
38 return make_scoped_refptr(new SurfacesInstance);
39 }
40
41 SurfacesInstance::SurfacesInstance()
42 : next_surface_id_namespace_(1u),
43 gl_surface_(new AwGLSurface) {
44 DCHECK(!g_surfaces_instance);
45 g_surfaces_instance = this;
hush (inactive) 2016/06/29 00:03:12 shouldn't this line be at the last line of constru
boliu 2016/06/29 01:01:03 Done fwiw this is all single threaded, so not rea
Torne 2016/07/08 11:12:06 It's not sufficient to just put this as the last l
46
47 cc::RendererSettings settings;
48
49 // Should be kept in sync with compositor_impl_android.cc.
50 settings.allow_antialiasing = false;
51 settings.highp_threshold_min = 2048;
52
53 // Webview does not own the surface so should not clear it.
54 settings.should_clear_root_render_pass = false;
55
56 surface_manager_.reset(new cc::SurfaceManager);
57 surface_id_allocator_.reset(
58 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
59 surface_id_allocator_->RegisterSurfaceIdNamespace(surface_manager_.get());
60
61 std::unique_ptr<cc::BeginFrameSource> begin_frame_source(
62 new cc::StubBeginFrameSource);
63 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter(
64 new cc::TextureMailboxDeleter(nullptr));
65 std::unique_ptr<ParentOutputSurface> output_surface_holder(
66 new ParentOutputSurface(AwRenderThreadContextProvider::Create(
67 gl_surface_, DeferredGpuCommandService::GetInstance())));
68 output_surface_ = output_surface_holder.get();
69 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler(
70 begin_frame_source.get(), nullptr,
71 output_surface_holder->capabilities().max_frames_pending));
72 display_.reset(new cc::Display(
73 surface_manager_.get(), nullptr /* shared_bitmap_manager */,
74 nullptr /* gpu_memory_buffer_manager */, settings,
75 surface_id_allocator_->id_namespace(), std::move(begin_frame_source),
76 std::move(output_surface_holder), std::move(scheduler),
77 std::move(texture_mailbox_deleter)));
78 display_->Initialize(this);
79
80 surface_factory_.reset(new cc::SurfaceFactory(surface_manager_.get(), this));
81 }
82
83 SurfacesInstance::~SurfacesInstance() {
84 DCHECK_EQ(g_surfaces_instance, this);
85 g_surfaces_instance = nullptr;
86
87 DCHECK(child_ids_.empty());
88 if (!root_id_.is_null())
89 surface_factory_->Destroy(root_id_);
90 }
91
92 std::unique_ptr<cc::SurfaceIdAllocator>
93 SurfacesInstance::CreateSurfaceIdAllocator() {
94 std::unique_ptr<cc::SurfaceIdAllocator> allocator = base::WrapUnique(
95 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
96 allocator->RegisterSurfaceIdNamespace(surface_manager_.get());
97 return allocator;
98 }
99
100 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() {
101 return surface_manager_.get();
102 }
103
104 void SurfacesInstance::SetBackingFrameBufferObject(
105 int framebuffer_binding_ext) {
106 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext);
107 }
108
109 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport,
110 const gfx::Rect& clip,
111 const gfx::Transform& transform,
112 const gfx::Size& frame_size,
113 const cc::SurfaceId& child_id,
114 const ScopedAppGLStateRestore& gl_state) {
115 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) !=
116 child_ids_.end());
117
118 // Create a frame with a single SurfaceDrawQuad referencing the child
119 // Surface and transformed using the given transform.
120 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
121 render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(viewport), clip,
122 gfx::Transform(), false);
123
124 cc::SharedQuadState* quad_state =
125 render_pass->CreateAndAppendSharedQuadState();
126 quad_state->quad_to_target_transform = transform;
127 quad_state->quad_layer_bounds = frame_size;
128 quad_state->visible_quad_layer_rect = gfx::Rect(frame_size);
129 quad_state->opacity = 1.f;
130
131 cc::SurfaceDrawQuad* surface_quad =
132 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
133 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds),
134 gfx::Rect(quad_state->quad_layer_bounds), child_id);
135
136 std::unique_ptr<cc::DelegatedFrameData> delegated_frame(
137 new cc::DelegatedFrameData);
138 delegated_frame->render_pass_list.push_back(std::move(render_pass));
139 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
140 frame->delegated_frame_data = std::move(delegated_frame);
141 frame->metadata.referenced_surfaces = child_ids_;
142
143 if (root_id_.is_null()) {
144 root_id_ = surface_id_allocator_->GenerateId();
145 surface_factory_->Create(root_id_);
146 display_->SetSurfaceId(root_id_, 1.f);
147 }
148 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame),
149 cc::SurfaceFactory::DrawCallback());
150
151 output_surface_->SetGLState(gl_state);
152 display_->Resize(viewport);
153 display_->SetExternalClip(clip);
154 display_->DrawAndSwap();
155
156 // Reset the root surface frame so child surface lifetime remains independent.
hush (inactive) 2016/06/29 00:03:11 what does this mean? I don't see this thing in the
boliu 2016/06/29 01:01:03 Removed. It's "nice property" that root doesn't r
157 SetEmptyRootFrame();
158 }
159
160 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) {
161 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) ==
hush (inactive) 2016/06/29 00:03:12 i'm just curious how this is different from child_
boliu 2016/06/29 01:01:03 vector doesn't have a find method :p
162 child_ids_.end());
163 child_ids_.push_back(child_id);
164 if (!root_id_.is_null())
165 SetEmptyRootFrame();
166 }
167
168 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) {
169 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id);
170 DCHECK(itr != child_ids_.end());
171 child_ids_.erase(itr);
172 if (!root_id_.is_null())
173 SetEmptyRootFrame();
174 }
175
176 void SurfacesInstance::SetEmptyRootFrame() {
177 std::unique_ptr<cc::CompositorFrame> empty_frame(new cc::CompositorFrame);
178 empty_frame->delegated_frame_data =
179 base::WrapUnique(new cc::DelegatedFrameData);
180 empty_frame->metadata.referenced_surfaces = child_ids_;
181 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame),
182 cc::SurfaceFactory::DrawCallback());
183 }
184
185 void SurfacesInstance::ReturnResources(
186 const cc::ReturnedResourceArray& resources) {
187 // Root surface should have no resources to return.
188 CHECK(resources.empty());
189 }
190
191 void SurfacesInstance::SetBeginFrameSource(
192 cc::BeginFrameSource* begin_frame_source) {
193 // Parent compsitor calls DrawAndSwap directly and doesn't use
194 // BeginFrameSource.
195 }
196
197 } // namespace android_webview
OLDNEW
« android_webview/browser/surfaces_instance.h ('K') | « android_webview/browser/surfaces_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698