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

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

Issue 2647583002: Switching to CompositorFrameSinkSupport in android_webview::SurfacesInstance (Closed)
Patch Set: c Created 3 years, 11 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
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
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 } 88 }
90 89
91 void SurfacesInstance::DisplayOutputSurfaceLost() { 90 void SurfacesInstance::DisplayOutputSurfaceLost() {
92 // Android WebView does not handle context loss. 91 // Android WebView does not handle context loss.
93 LOG(FATAL) << "Render thread context loss"; 92 LOG(FATAL) << "Render thread context loss";
94 } 93 }
95 94
95 void SurfacesInstance::ReclaimResources(
96 const cc::ReturnedResourceArray& resources) {
97 // Root surface should have no resources to return.
98 CHECK(resources.empty());
99 }
100
96 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() { 101 cc::FrameSinkId SurfacesInstance::AllocateFrameSinkId() {
97 return cc::FrameSinkId(next_client_id_++, 0 /* sink_id */); 102 return cc::FrameSinkId(next_client_id_++, 0 /* sink_id */);
98 } 103 }
99 104
100 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() { 105 cc::SurfaceManager* SurfacesInstance::GetSurfaceManager() {
101 return surface_manager_.get(); 106 return surface_manager_.get();
102 } 107 }
103 108
104 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport, 109 void SurfacesInstance::DrawAndSwap(const gfx::Size& viewport,
105 const gfx::Rect& clip, 110 const gfx::Rect& clip,
(...skipping 20 matching lines...) Expand all
126 131
127 cc::SurfaceDrawQuad* surface_quad = 132 cc::SurfaceDrawQuad* surface_quad =
128 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 133 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
129 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), 134 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds),
130 gfx::Rect(quad_state->quad_layer_bounds), child_id); 135 gfx::Rect(quad_state->quad_layer_bounds), child_id);
131 136
132 cc::CompositorFrame frame; 137 cc::CompositorFrame frame;
133 frame.render_pass_list.push_back(std::move(render_pass)); 138 frame.render_pass_list.push_back(std::move(render_pass));
134 frame.metadata.referenced_surfaces = child_ids_; 139 frame.metadata.referenced_surfaces = child_ids_;
135 140
136 if (!root_id_.is_valid()) { 141 if (!root_id_.is_valid())
137 root_id_ = surface_id_allocator_->GenerateId(); 142 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 143
143 display_->Resize(viewport); 144 support_->SubmitCompositorFrame(root_id_, std::move(frame));
144 display_->DrawAndSwap(); 145
146 support_->display()->Resize(viewport);
147 support_->display()->DrawAndSwap();
145 } 148 }
146 149
147 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { 150 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) {
148 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == 151 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) ==
149 child_ids_.end()); 152 child_ids_.end());
150 child_ids_.push_back(child_id); 153 child_ids_.push_back(child_id);
151 if (root_id_.is_valid()) 154 if (root_id_.is_valid())
152 SetEmptyRootFrame(); 155 SetEmptyRootFrame();
153 } 156 }
154 157
155 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { 158 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) {
156 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); 159 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id);
157 DCHECK(itr != child_ids_.end()); 160 DCHECK(itr != child_ids_.end());
158 child_ids_.erase(itr); 161 child_ids_.erase(itr);
159 if (root_id_.is_valid()) 162 if (root_id_.is_valid())
160 SetEmptyRootFrame(); 163 SetEmptyRootFrame();
161 } 164 }
162 165
163 void SurfacesInstance::SetEmptyRootFrame() { 166 void SurfacesInstance::SetEmptyRootFrame() {
164 cc::CompositorFrame empty_frame; 167 cc::CompositorFrame empty_frame;
165 empty_frame.metadata.referenced_surfaces = child_ids_; 168 empty_frame.metadata.referenced_surfaces = child_ids_;
166 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame), 169 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 } 170 }
181 171
182 } // namespace android_webview 172 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698