| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 DCHECK(!g_surfaces_instance); | 78 DCHECK(!g_surfaces_instance); |
| 79 g_surfaces_instance = this; | 79 g_surfaces_instance = this; |
| 80 | 80 |
| 81 } | 81 } |
| 82 | 82 |
| 83 SurfacesInstance::~SurfacesInstance() { | 83 SurfacesInstance::~SurfacesInstance() { |
| 84 DCHECK_EQ(g_surfaces_instance, this); | 84 DCHECK_EQ(g_surfaces_instance, this); |
| 85 g_surfaces_instance = nullptr; | 85 g_surfaces_instance = nullptr; |
| 86 | 86 |
| 87 DCHECK(child_ids_.empty()); | 87 DCHECK(child_ids_.empty()); |
| 88 if (!root_id_.is_null()) | 88 if (root_id_.is_valid()) |
| 89 surface_factory_->Destroy(root_id_); | 89 surface_factory_->Destroy(root_id_); |
| 90 | 90 |
| 91 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 91 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SurfacesInstance::DisplayOutputSurfaceLost() { | 94 void SurfacesInstance::DisplayOutputSurfaceLost() { |
| 95 // Android WebView does not handle context loss. | 95 // Android WebView does not handle context loss. |
| 96 LOG(FATAL) << "Render thread context loss"; | 96 LOG(FATAL) << "Render thread context loss"; |
| 97 } | 97 } |
| 98 | 98 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 129 | 129 |
| 130 cc::SurfaceDrawQuad* surface_quad = | 130 cc::SurfaceDrawQuad* surface_quad = |
| 131 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 131 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 132 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), | 132 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds), |
| 133 gfx::Rect(quad_state->quad_layer_bounds), child_id); | 133 gfx::Rect(quad_state->quad_layer_bounds), child_id); |
| 134 | 134 |
| 135 cc::CompositorFrame frame; | 135 cc::CompositorFrame frame; |
| 136 frame.render_pass_list.push_back(std::move(render_pass)); | 136 frame.render_pass_list.push_back(std::move(render_pass)); |
| 137 frame.metadata.referenced_surfaces = child_ids_; | 137 frame.metadata.referenced_surfaces = child_ids_; |
| 138 | 138 |
| 139 if (root_id_.is_null()) { | 139 if (!root_id_.is_valid()) { |
| 140 root_id_ = surface_id_allocator_->GenerateId(); | 140 root_id_ = surface_id_allocator_->GenerateId(); |
| 141 surface_factory_->Create(root_id_); | 141 surface_factory_->Create(root_id_); |
| 142 display_->SetSurfaceId(cc::SurfaceId(frame_sink_id_, root_id_), 1.f); | 142 display_->SetSurfaceId(cc::SurfaceId(frame_sink_id_, root_id_), 1.f); |
| 143 } | 143 } |
| 144 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame), | 144 surface_factory_->SubmitCompositorFrame(root_id_, std::move(frame), |
| 145 cc::SurfaceFactory::DrawCallback()); | 145 cc::SurfaceFactory::DrawCallback()); |
| 146 | 146 |
| 147 display_->Resize(viewport); | 147 display_->Resize(viewport); |
| 148 display_->DrawAndSwap(); | 148 display_->DrawAndSwap(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { | 151 void SurfacesInstance::AddChildId(const cc::SurfaceId& child_id) { |
| 152 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == | 152 DCHECK(std::find(child_ids_.begin(), child_ids_.end(), child_id) == |
| 153 child_ids_.end()); | 153 child_ids_.end()); |
| 154 child_ids_.push_back(child_id); | 154 child_ids_.push_back(child_id); |
| 155 if (!root_id_.is_null()) | 155 if (root_id_.is_valid()) |
| 156 SetEmptyRootFrame(); | 156 SetEmptyRootFrame(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { | 159 void SurfacesInstance::RemoveChildId(const cc::SurfaceId& child_id) { |
| 160 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); | 160 auto itr = std::find(child_ids_.begin(), child_ids_.end(), child_id); |
| 161 DCHECK(itr != child_ids_.end()); | 161 DCHECK(itr != child_ids_.end()); |
| 162 child_ids_.erase(itr); | 162 child_ids_.erase(itr); |
| 163 if (!root_id_.is_null()) | 163 if (root_id_.is_valid()) |
| 164 SetEmptyRootFrame(); | 164 SetEmptyRootFrame(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void SurfacesInstance::SetEmptyRootFrame() { | 167 void SurfacesInstance::SetEmptyRootFrame() { |
| 168 cc::CompositorFrame empty_frame; | 168 cc::CompositorFrame empty_frame; |
| 169 empty_frame.metadata.referenced_surfaces = child_ids_; | 169 empty_frame.metadata.referenced_surfaces = child_ids_; |
| 170 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame), | 170 surface_factory_->SubmitCompositorFrame(root_id_, std::move(empty_frame), |
| 171 cc::SurfaceFactory::DrawCallback()); | 171 cc::SurfaceFactory::DrawCallback()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void SurfacesInstance::ReturnResources( | 174 void SurfacesInstance::ReturnResources( |
| 175 const cc::ReturnedResourceArray& resources) { | 175 const cc::ReturnedResourceArray& resources) { |
| 176 // Root surface should have no resources to return. | 176 // Root surface should have no resources to return. |
| 177 CHECK(resources.empty()); | 177 CHECK(resources.empty()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void SurfacesInstance::SetBeginFrameSource( | 180 void SurfacesInstance::SetBeginFrameSource( |
| 181 cc::BeginFrameSource* begin_frame_source) { | 181 cc::BeginFrameSource* begin_frame_source) { |
| 182 // Parent compsitor calls DrawAndSwap directly and doesn't use | 182 // Parent compsitor calls DrawAndSwap directly and doesn't use |
| 183 // BeginFrameSource. | 183 // BeginFrameSource. |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace android_webview | 186 } // namespace android_webview |
| OLD | NEW |