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" |
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/solid_color_draw_quad.h" | |
17 #include "cc/quads/surface_draw_quad.h" | 18 #include "cc/quads/surface_draw_quad.h" |
18 #include "cc/scheduler/begin_frame_source.h" | 19 #include "cc/scheduler/begin_frame_source.h" |
19 #include "cc/surfaces/compositor_frame_sink_support.h" | 20 #include "cc/surfaces/compositor_frame_sink_support.h" |
20 #include "cc/surfaces/display.h" | 21 #include "cc/surfaces/display.h" |
21 #include "cc/surfaces/display_scheduler.h" | 22 #include "cc/surfaces/display_scheduler.h" |
22 #include "cc/surfaces/local_surface_id_allocator.h" | 23 #include "cc/surfaces/local_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" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 gfx::Rect(quad_state->quad_layer_rect), child_id, | 134 gfx::Rect(quad_state->quad_layer_rect), child_id, |
134 cc::SurfaceDrawQuadType::PRIMARY, nullptr); | 135 cc::SurfaceDrawQuadType::PRIMARY, nullptr); |
135 | 136 |
136 cc::CompositorFrame frame; | 137 cc::CompositorFrame frame; |
137 // We draw synchronously, so acknowledge a manual BeginFrame. | 138 // We draw synchronously, so acknowledge a manual BeginFrame. |
138 frame.metadata.begin_frame_ack = | 139 frame.metadata.begin_frame_ack = |
139 cc::BeginFrameAck::CreateManualAckWithDamage(); | 140 cc::BeginFrameAck::CreateManualAckWithDamage(); |
140 frame.render_pass_list.push_back(std::move(render_pass)); | 141 frame.render_pass_list.push_back(std::move(render_pass)); |
141 frame.metadata.referenced_surfaces = child_ids_; | 142 frame.metadata.referenced_surfaces = child_ids_; |
142 | 143 |
143 if (!root_id_.is_valid()) { | 144 if (!root_id_.is_valid() || frame_size != surface_size_) { |
144 root_id_ = local_surface_id_allocator_->GenerateId(); | 145 root_id_ = local_surface_id_allocator_->GenerateId(); |
146 surface_size_ = frame_size; | |
145 display_->SetLocalSurfaceId(root_id_, 1.f); | 147 display_->SetLocalSurfaceId(root_id_, 1.f); |
146 } | 148 } |
147 support_->SubmitCompositorFrame(root_id_, std::move(frame)); | 149 support_->SubmitCompositorFrame(root_id_, std::move(frame)); |
148 | 150 |
149 display_->Resize(viewport); | 151 display_->Resize(viewport); |
150 display_->DrawAndSwap(); | 152 display_->DrawAndSwap(); |
151 } | 153 } |
152 | 154 |
153 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { | 155 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { |
154 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == | 156 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == |
155 child_ids_.end()); | 157 child_ids_.end()); |
156 child_ids_.push_back(child_id); | 158 child_ids_.push_back(child_id); |
157 if (root_id_.is_valid()) | 159 if (root_id_.is_valid()) |
158 SetEmptyRootFrame(); | 160 SetEmptyRootFrame(); |
159 } | 161 } |
160 | 162 |
161 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { | 163 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { |
162 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); | 164 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); |
163 DCHECK(itr != child_ids_.end()); | 165 DCHECK(itr != child_ids_.end()); |
164 child_ids_.erase(itr); | 166 child_ids_.erase(itr); |
165 if (root_id_.is_valid()) | 167 if (root_id_.is_valid()) |
166 SetEmptyRootFrame(); | 168 SetEmptyRootFrame(); |
167 } | 169 } |
168 | 170 |
169 void SurfacesInstance::SetEmptyRootFrame() { | 171 void SurfacesInstance::SetEmptyRootFrame() { |
boliu
2017/05/04 17:08:00
rename the method name and variable names please,
Saman Sami
2017/05/04 21:38:46
Done.
| |
172 if (!root_id_.is_valid()) | |
boliu
2017/05/04 17:08:00
this should be a DCHECK it looks like? every call
Saman Sami
2017/05/04 21:38:46
Done.
| |
173 return; | |
174 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | |
175 cc::SharedQuadState* quad_state = | |
176 render_pass->CreateAndAppendSharedQuadState(); | |
177 gfx::Rect rect(surface_size_); | |
178 cc::SolidColorDrawQuad* solid_quad = | |
179 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | |
180 solid_quad->SetNew(quad_state, rect, rect, SK_ColorBLACK, false); | |
170 cc::CompositorFrame empty_frame; | 181 cc::CompositorFrame empty_frame; |
182 empty_frame.render_pass_list.push_back(std::move(render_pass)); | |
171 // We draw synchronously, so acknowledge a manual BeginFrame. | 183 // We draw synchronously, so acknowledge a manual BeginFrame. |
172 empty_frame.metadata.begin_frame_ack = | 184 empty_frame.metadata.begin_frame_ack = |
173 cc::BeginFrameAck::CreateManualAckWithDamage(); | 185 cc::BeginFrameAck::CreateManualAckWithDamage(); |
174 empty_frame.metadata.referenced_surfaces = child_ids_; | 186 empty_frame.metadata.referenced_surfaces = child_ids_; |
175 support_->SubmitCompositorFrame(root_id_, std::move(empty_frame)); | 187 support_->SubmitCompositorFrame(root_id_, std::move(empty_frame)); |
176 } | 188 } |
177 | 189 |
178 void SurfacesInstance::DidReceiveCompositorFrameAck( | 190 void SurfacesInstance::DidReceiveCompositorFrameAck( |
179 const cc::ReturnedResourceArray& resources) { | 191 const cc::ReturnedResourceArray& resources) { |
180 ReclaimResources(resources); | 192 ReclaimResources(resources); |
181 } | 193 } |
182 | 194 |
183 void SurfacesInstance::OnBeginFrame(const cc::BeginFrameArgs& args) {} | 195 void SurfacesInstance::OnBeginFrame(const cc::BeginFrameArgs& args) {} |
184 | 196 |
185 void SurfacesInstance::WillDrawSurface( | 197 void SurfacesInstance::WillDrawSurface( |
186 const cc::LocalSurfaceId& local_surface_id, | 198 const cc::LocalSurfaceId& local_surface_id, |
187 const gfx::Rect& damage_rect) {} | 199 const gfx::Rect& damage_rect) {} |
188 | 200 |
189 void SurfacesInstance::ReclaimResources( | 201 void SurfacesInstance::ReclaimResources( |
190 const cc::ReturnedResourceArray& resources) { | 202 const cc::ReturnedResourceArray& resources) { |
191 // Root surface should have no resources to return. | 203 // Root surface should have no resources to return. |
192 CHECK(resources.empty()); | 204 CHECK(resources.empty()); |
193 } | 205 } |
194 | 206 |
195 } // namespace android_webview | 207 } // namespace android_webview |
OLD | NEW |