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 SetSolidColorRootFrame(); |
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 SetSolidColorRootFrame(); |
167 } | 169 } |
168 | 170 |
169 void SurfacesInstance::SetEmptyRootFrame() { | 171 void SurfacesInstance::SetSolidColorRootFrame() { |
170 cc::CompositorFrame empty_frame; | 172 DCHECK(!surface_size_.IsEmpty()); |
| 173 gfx::Rect rect(surface_size_); |
| 174 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 175 render_pass->SetNew(1, rect, rect, gfx::Transform()); |
| 176 cc::SharedQuadState* quad_state = |
| 177 render_pass->CreateAndAppendSharedQuadState(); |
| 178 quad_state->SetAll(gfx::Transform(), rect, rect, rect, false, 1.f, |
| 179 SkBlendMode::kSrcOver, 0); |
| 180 cc::SolidColorDrawQuad* solid_quad = |
| 181 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 182 solid_quad->SetNew(quad_state, rect, rect, SK_ColorBLACK, false); |
| 183 cc::CompositorFrame frame; |
| 184 frame.render_pass_list.push_back(std::move(render_pass)); |
171 // We draw synchronously, so acknowledge a manual BeginFrame. | 185 // We draw synchronously, so acknowledge a manual BeginFrame. |
172 empty_frame.metadata.begin_frame_ack = | 186 frame.metadata.begin_frame_ack = |
173 cc::BeginFrameAck::CreateManualAckWithDamage(); | 187 cc::BeginFrameAck::CreateManualAckWithDamage(); |
174 empty_frame.metadata.referenced_surfaces = child_ids_; | 188 frame.metadata.referenced_surfaces = child_ids_; |
175 support_->SubmitCompositorFrame(root_id_, std::move(empty_frame)); | 189 support_->SubmitCompositorFrame(root_id_, std::move(frame)); |
176 } | 190 } |
177 | 191 |
178 void SurfacesInstance::DidReceiveCompositorFrameAck( | 192 void SurfacesInstance::DidReceiveCompositorFrameAck( |
179 const cc::ReturnedResourceArray& resources) { | 193 const cc::ReturnedResourceArray& resources) { |
180 ReclaimResources(resources); | 194 ReclaimResources(resources); |
181 } | 195 } |
182 | 196 |
183 void SurfacesInstance::OnBeginFrame(const cc::BeginFrameArgs& args) {} | 197 void SurfacesInstance::OnBeginFrame(const cc::BeginFrameArgs& args) {} |
184 | 198 |
185 void SurfacesInstance::WillDrawSurface( | 199 void SurfacesInstance::WillDrawSurface( |
186 const cc::LocalSurfaceId& local_surface_id, | 200 const cc::LocalSurfaceId& local_surface_id, |
187 const gfx::Rect& damage_rect) {} | 201 const gfx::Rect& damage_rect) {} |
188 | 202 |
189 void SurfacesInstance::ReclaimResources( | 203 void SurfacesInstance::ReclaimResources( |
190 const cc::ReturnedResourceArray& resources) { | 204 const cc::ReturnedResourceArray& resources) { |
191 // Root surface should have no resources to return. | 205 // Root surface should have no resources to return. |
192 CHECK(resources.empty()); | 206 CHECK(resources.empty()); |
193 } | 207 } |
194 | 208 |
195 } // namespace android_webview | 209 } // namespace android_webview |
OLD | NEW |