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

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: works Created 4 years, 6 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
« no previous file with comments | « android_webview/browser/surfaces_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
8
9 #include "android_webview/browser/aw_gl_surface.h"
10 #include "android_webview/browser/aw_render_thread_context_provider.h"
11 #include "android_webview/browser/deferred_gpu_command_service.h"
12 #include "android_webview/browser/parent_output_surface.h"
13 #include "base/lazy_instance.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 base::LazyInstance<base::WeakPtr<SurfacesInstance>>::Leaky g_surfaces_instance;
32 } // namespace
33
34 // static
35 scoped_refptr<SurfacesInstance> SurfacesInstance::GetOrCreateInstance() {
boliu 2016/06/23 23:27:08 So the problem is that I want a singleton that's d
36 scoped_refptr<SurfacesInstance> instance(g_surfaces_instance.Get().get());
37 if (instance)
38 return instance;
39
40 instance = new SurfacesInstance;
41 g_surfaces_instance.Get() = instance->weak_ptr_factory_.GetWeakPtr();
42 return instance;
43 }
44
45 SurfacesInstance::SurfacesInstance()
46 : next_surface_id_namespace_(1u),
47 gl_surface_(new AwGLSurface),
48 weak_ptr_factory_(this) {
49 cc::RendererSettings settings;
50
51 // Should be kept in sync with compositor_impl_android.cc.
52 settings.allow_antialiasing = false;
53 settings.highp_threshold_min = 2048;
54
55 // Webview does not own the surface so should not clear it.
56 settings.should_clear_root_render_pass = false;
57
58 surface_manager_.reset(new cc::SurfaceManager);
59 surface_id_allocator_.reset(
60 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
61 surface_id_allocator_->RegisterSurfaceIdNamespace(surface_manager_.get());
62
63 std::unique_ptr<cc::BeginFrameSource> begin_frame_source(
64 new cc::StubBeginFrameSource);
65 std::unique_ptr<cc::TextureMailboxDeleter> texture_mailbox_deleter(
66 new cc::TextureMailboxDeleter(nullptr));
67 std::unique_ptr<ParentOutputSurface> output_surface_holder(
68 new ParentOutputSurface(AwRenderThreadContextProvider::Create(
69 gl_surface_, DeferredGpuCommandService::GetInstance())));
70 output_surface_ = output_surface_holder.get();
71 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler(
72 begin_frame_source.get(), nullptr,
73 output_surface_holder->capabilities().max_frames_pending));
74 display_.reset(new cc::Display(
75 surface_manager_.get(), nullptr /* shared_bitmap_manager */,
76 nullptr /* gpu_memory_buffer_manager */, settings,
77 surface_id_allocator_->id_namespace(), std::move(begin_frame_source),
78 std::move(output_surface_holder), std::move(scheduler),
79 std::move(texture_mailbox_deleter)));
80 display_->Initialize(this);
81
82 surface_factory_.reset(new cc::SurfaceFactory(surface_manager_.get(), this));
83 }
84
85 SurfacesInstance::~SurfacesInstance() {
86 if (!root_id_.is_null())
87 surface_factory_->Destroy(root_id_);
88 }
89
90 std::unique_ptr<cc::SurfaceIdAllocator>
91 SurfacesInstance::CreateSurfaceIdAllocator() {
92 std::unique_ptr<cc::SurfaceIdAllocator> allocator = base::WrapUnique(
93 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
94 allocator->RegisterSurfaceIdNamespace(surface_manager_.get());
95 return allocator;
96 }
97
98 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() {
99 return surface_manager_.get();
100 }
101
102 void SurfacesInstance::SetBackingFrameBufferObject(
103 int framebuffer_binding_ext) {
104 gl_surface_->SetBackingFrameBufferObject(framebuffer_binding_ext);
105 }
106
107 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport,
108 const gfx::Rect& clip,
109 const gfx::Transform& transform,
110 const gfx::Size& frame_size,
111 const cc::SurfaceId& child_id,
112 const ScopedAppGLStateRestore& gl_state) {
113 // Create a frame with a single SurfaceDrawQuad referencing the child
114 // Surface and transformed using the given transform.
115 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
116 render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(viewport), clip,
117 gfx::Transform(), false);
118
119 cc::SharedQuadState* quad_state =
120 render_pass->CreateAndAppendSharedQuadState();
121 quad_state->quad_to_target_transform = transform;
122 quad_state->quad_layer_bounds = frame_size;
123 quad_state->visible_quad_layer_rect = gfx::Rect(frame_size);
124 quad_state->opacity = 1.f;
125
126 cc::SurfaceDrawQuad* surface_quad =
127 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
128 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds),
129 gfx::Rect(quad_state->quad_layer_bounds), child_id);
130
131 std::unique_ptr<cc::DelegatedFrameData> delegated_frame(
132 new cc::DelegatedFrameData);
133 delegated_frame->render_pass_list.push_back(std::move(render_pass));
134 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
135 frame->delegated_frame_data = std::move(delegated_frame);
136
137 if (root_id_.is_null()) {
138 root_id_ = surface_id_allocator_->GenerateId();
139 surface_factory_->Create(root_id_);
140 display_->SetSurfaceId(root_id_, 1.f);
141 }
142 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame),
143 cc::SurfaceFactory::DrawCallback());
144
145 output_surface_->SetGLState(gl_state);
146 display_->Resize(viewport);
147 display_->SetExternalClip(clip);
148 display_->DrawAndSwap();
149
150 // TODO(boliu): member vars
151 std::unique_ptr<cc::CompositorFrame> empty_frame(new cc::CompositorFrame);
152 empty_frame->delegated_frame_data =
153 base::WrapUnique(new cc::DelegatedFrameData);
154 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame),
155 cc::SurfaceFactory::DrawCallback());
156 }
157
158 void SurfacesInstance::ReturnResources(
159 const cc::ReturnedResourceArray& resources) {
160 // Root surface should have no resources to return.
161 CHECK(resources.empty());
162 }
163
164 void SurfacesInstance::SetBeginFrameSource(
165 cc::BeginFrameSource* begin_frame_source) {
166 // Parent compsitor calls DrawAndSwap directly and doesn't use
167 // BeginFrameSource.
168 }
169
170 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/surfaces_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698