[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 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 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
[email protected] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 8 | #include "base/debug/trace_event.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 9 | #include "cc/base/thread.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 10 | #include "cc/output/context_provider.h" |
| 11 | #include "cc/output/output_surface.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 12 | #include "cc/quads/draw_quad.h" |
[email protected] | e12dd0e | 2013-03-18 08:24:40 | [diff] [blame] | 13 | #include "cc/resources/prioritized_resource_manager.h" |
| 14 | #include "cc/resources/resource_update_controller.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 15 | #include "cc/trees/layer_tree_host.h" |
| 16 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 18 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 19 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 20 | scoped_ptr<Proxy> SingleThreadProxy::Create(LayerTreeHost* layer_tree_host) { |
| 21 | return make_scoped_ptr( |
| 22 | new SingleThreadProxy(layer_tree_host)).PassAs<Proxy>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 23 | } |
| 24 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 25 | SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host) |
| 26 | : Proxy(scoped_ptr<Thread>(NULL)), |
| 27 | layer_tree_host_(layer_tree_host), |
| 28 | output_surface_lost_(false), |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 29 | created_offscreen_context_provider_(false), |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 30 | renderer_initialized_(false), |
| 31 | next_frame_is_newly_committed_frame_(false), |
| 32 | inside_draw_(false), |
| 33 | total_commit_count_(0) { |
| 34 | TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 35 | DCHECK(Proxy::IsMainThread()); |
| 36 | DCHECK(layer_tree_host); |
[email protected] | 1e4c352b | 2013-01-10 02:05:23 | [diff] [blame] | 37 | |
[email protected] | 089102b | 2013-03-14 03:54:56 | [diff] [blame] | 38 | // Impl-side painting not supported without threaded compositing. |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 39 | CHECK(!layer_tree_host->settings().impl_side_painting); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 40 | } |
| 41 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 42 | void SingleThreadProxy::Start() { |
| 43 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 44 | layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | SingleThreadProxy::~SingleThreadProxy() { |
| 48 | TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); |
| 49 | DCHECK(Proxy::IsMainThread()); |
| 50 | DCHECK(!layer_tree_host_impl_.get() && |
| 51 | !layer_tree_host_); // make sure Stop() got called. |
| 52 | } |
| 53 | |
| 54 | bool SingleThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 55 | TRACE_EVENT0("cc", "SingleThreadProxy::CompositeAndReadback"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 56 | DCHECK(Proxy::IsMainThread()); |
| 57 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 58 | if (!CommitAndComposite(base::TimeTicks::Now())) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 59 | return false; |
| 60 | |
| 61 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 62 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 63 | layer_tree_host_impl_->Readback(pixels, rect); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 64 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 65 | if (layer_tree_host_impl_->IsContextLost()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 66 | return false; |
| 67 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 68 | layer_tree_host_impl_->SwapBuffers(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 69 | } |
| 70 | DidSwapFrame(); |
| 71 | |
| 72 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 75 | void SingleThreadProxy::StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 76 | bool use_anchor, |
| 77 | float scale, |
| 78 | base::TimeDelta duration) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 79 | layer_tree_host_impl_->StartPageScaleAnimation( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 80 | target_offset, use_anchor, scale, base::TimeTicks::Now(), duration); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 83 | void SingleThreadProxy::FinishAllRendering() { |
| 84 | DCHECK(Proxy::IsMainThread()); |
| 85 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 86 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 87 | layer_tree_host_impl_->FinishAllRendering(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 88 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 91 | bool SingleThreadProxy::IsStarted() const { |
| 92 | DCHECK(Proxy::IsMainThread()); |
| 93 | return layer_tree_host_impl_.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 96 | bool SingleThreadProxy::InitializeOutputSurface() { |
| 97 | DCHECK(Proxy::IsMainThread()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 98 | scoped_ptr<OutputSurface> output_surface = |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 99 | layer_tree_host_->CreateOutputSurface(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 100 | if (!output_surface.get()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 101 | return false; |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 102 | output_surface_before_initialization_ = output_surface.Pass(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 103 | return true; |
| 104 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 105 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 106 | void SingleThreadProxy::SetSurfaceReady() { |
| 107 | // Scheduling is controlled by the embedder in the single thread case, so |
| 108 | // nothing to do. |
| 109 | } |
| 110 | |
| 111 | void SingleThreadProxy::SetVisible(bool visible) { |
| 112 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 113 | layer_tree_host_impl_->SetVisible(visible); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool SingleThreadProxy::InitializeRenderer() { |
| 117 | DCHECK(Proxy::IsMainThread()); |
| 118 | DCHECK(output_surface_before_initialization_.get()); |
| 119 | { |
| 120 | DebugScopedSetImplThread impl(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 121 | bool ok = layer_tree_host_impl_->InitializeRenderer( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 122 | output_surface_before_initialization_.Pass()); |
| 123 | if (ok) { |
| 124 | renderer_initialized_ = true; |
| 125 | renderer_capabilities_for_main_thread_ = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 126 | layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | 0a45172 | 2013-02-22 20:32:05 | [diff] [blame] | 127 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 128 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 129 | return ok; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | bool SingleThreadProxy::RecreateOutputSurface() { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 134 | TRACE_EVENT0("cc", "SingleThreadProxy::RecreateContext"); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 135 | DCHECK(Proxy::IsMainThread()); |
| 136 | DCHECK(output_surface_lost_); |
| 137 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 138 | scoped_ptr<OutputSurface> output_surface = |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 139 | layer_tree_host_->CreateOutputSurface(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 140 | if (!output_surface.get()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 141 | return false; |
| 142 | scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 143 | if (created_offscreen_context_provider_) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 144 | offscreen_context_provider = |
| 145 | layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 146 | if (!offscreen_context_provider) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 147 | return false; |
| 148 | } |
| 149 | |
| 150 | bool initialized; |
| 151 | { |
| 152 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 153 | DebugScopedSetImplThread impl(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 154 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 155 | layer_tree_host_impl_->resource_provider()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 156 | initialized = |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 157 | layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 158 | if (initialized) { |
| 159 | renderer_capabilities_for_main_thread_ = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 160 | layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 161 | layer_tree_host_impl_->resource_provider()-> |
| 162 | set_offscreen_context_provider(offscreen_context_provider); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 163 | } else if (offscreen_context_provider) { |
| 164 | offscreen_context_provider->VerifyContexts(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 165 | } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 166 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 167 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 168 | if (initialized) |
| 169 | output_surface_lost_ = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 170 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 171 | return initialized; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 172 | } |
| 173 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 174 | const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
| 175 | DCHECK(renderer_initialized_); |
| 176 | // Note: this gets called during the commit by the "impl" thread. |
| 177 | return renderer_capabilities_for_main_thread_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 180 | void SingleThreadProxy::SetNeedsAnimate() { |
| 181 | // Thread-only feature. |
| 182 | NOTREACHED(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 185 | void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
| 186 | DCHECK(Proxy::IsMainThread()); |
| 187 | // Commit immediately. |
| 188 | { |
| 189 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 190 | DebugScopedSetImplThread impl(this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 192 | RenderingStatsInstrumentation* stats_instrumentation = |
| 193 | layer_tree_host_->rendering_stats_instrumentation(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 194 | base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 195 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 196 | layer_tree_host_impl_->BeginCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 197 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 198 | layer_tree_host_->contents_texture_manager()-> |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 199 | PushTexturePrioritiesToBackings(); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 200 | layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 201 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 202 | scoped_ptr<ResourceUpdateController> update_controller = |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 203 | ResourceUpdateController::Create( |
| 204 | NULL, |
| 205 | Proxy::MainThread(), |
| 206 | queue.Pass(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 207 | layer_tree_host_impl_->resource_provider()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 208 | update_controller->Finalize(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 209 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 210 | layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 211 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 212 | layer_tree_host_impl_->CommitComplete(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 213 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 214 | #ifndef NDEBUG |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 215 | // In the single-threaded case, the scroll deltas should never be |
| 216 | // touched on the impl layer tree. |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 217 | scoped_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 218 | layer_tree_host_impl_->ProcessScrollDeltas(); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 219 | DCHECK(!scroll_info->scrolls.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 220 | #endif |
[email protected] | 8b9af6b | 2012-09-27 00:36:36 | [diff] [blame] | 221 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 222 | base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 223 | stats_instrumentation->AddCommit(duration); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 224 | } |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 225 | layer_tree_host_->CommitComplete(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 226 | next_frame_is_newly_committed_frame_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 229 | void SingleThreadProxy::SetNeedsCommit() { |
| 230 | DCHECK(Proxy::IsMainThread()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 231 | layer_tree_host_->ScheduleComposite(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 234 | void SingleThreadProxy::SetNeedsRedraw() { |
| 235 | // FIXME: Once we move render_widget scheduling into this class, we can |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame^] | 236 | // treat redraw requests more efficiently than CommitAndRedraw requests. |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 237 | layer_tree_host_impl_->SetFullRootLayerDamage(); |
| 238 | SetNeedsCommit(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 241 | void SingleThreadProxy::OnHasPendingTreeStateChanged(bool have_pending_tree) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 242 | // Thread-only feature. |
| 243 | NOTREACHED(); |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 246 | void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
| 247 | // Thread-only feature. |
| 248 | NOTREACHED(); |
[email protected] | 6b16679e | 2012-10-27 00:44:28 | [diff] [blame] | 249 | } |
| 250 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 251 | bool SingleThreadProxy::CommitRequested() const { return false; } |
| 252 | |
| 253 | size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
| 254 | return std::numeric_limits<size_t>::max(); |
| 255 | } |
| 256 | |
| 257 | void SingleThreadProxy::Stop() { |
| 258 | TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
| 259 | DCHECK(Proxy::IsMainThread()); |
| 260 | { |
| 261 | DebugScopedSetMainThreadBlocked mainThreadBlocked(this); |
| 262 | DebugScopedSetImplThread impl(this); |
| 263 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 264 | layer_tree_host_->DeleteContentsTexturesOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 265 | layer_tree_host_impl_->resource_provider()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 266 | layer_tree_host_impl_.reset(); |
| 267 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 268 | layer_tree_host_ = NULL; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 271 | void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 272 | layer_tree_host_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 273 | } |
| 274 | |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 275 | void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 276 | // Impl-side painting only. |
| 277 | NOTREACHED(); |
| 278 | } |
| 279 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 280 | void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 281 | layer_tree_host_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 284 | void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 285 | layer_tree_host_->ScheduleComposite(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 288 | void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 289 | scoped_ptr<AnimationEventsVector> events, |
| 290 | base::Time wall_clock_time) { |
| 291 | DCHECK(Proxy::IsImplThread()); |
| 292 | DebugScopedSetMainThread main(this); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 293 | layer_tree_host_->SetAnimationEvents(events.Pass(), wall_clock_time); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 296 | bool SingleThreadProxy::ReduceContentsTextureMemoryOnImplThread( |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 297 | size_t limit_bytes, |
| 298 | int priority_cutoff) { |
| 299 | DCHECK(IsImplThread()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 300 | if (!layer_tree_host_->contents_texture_manager()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 301 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 302 | |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 303 | return layer_tree_host_->contents_texture_manager()->ReduceMemoryOnImplThread( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 304 | limit_bytes, priority_cutoff, layer_tree_host_impl_->resource_provider()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 307 | void SingleThreadProxy::ReduceWastedContentsTextureMemoryOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 308 | // Impl-side painting only. |
| 309 | NOTREACHED(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 310 | } |
| 311 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 312 | void SingleThreadProxy::SendManagedMemoryStats() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 313 | DCHECK(Proxy::IsImplThread()); |
| 314 | if (!layer_tree_host_impl_.get()) |
| 315 | return; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 316 | if (!layer_tree_host_->contents_texture_manager()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 317 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 318 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 319 | PrioritizedResourceManager* contents_texture_manager = |
| 320 | layer_tree_host_->contents_texture_manager(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 321 | layer_tree_host_impl_->SendManagedMemoryStats( |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 322 | contents_texture_manager->MemoryVisibleBytes(), |
| 323 | contents_texture_manager->MemoryVisibleAndNearbyBytes(), |
| 324 | contents_texture_manager->MemoryUseBytes()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 327 | bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 328 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 329 | void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 330 | // Cause a commit so we can notice the lost context. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 331 | SetNeedsCommitOnImplThread(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 334 | // Called by the legacy scheduling path (e.g. where render_widget does the |
| 335 | // scheduling) |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 336 | void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 337 | if (CommitAndComposite(frame_begin_time)) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 338 | layer_tree_host_impl_->SwapBuffers(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 339 | DidSwapFrame(); |
| 340 | } |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 343 | scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
| 344 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 345 | { |
| 346 | // The following line casts away const modifiers because it is just |
| 347 | // setting debug state. We still want the AsValue() function and its |
| 348 | // call chain to be const throughout. |
| 349 | DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
| 350 | |
| 351 | state->Set("layer_tree_host_impl", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 352 | layer_tree_host_impl_->AsValue().release()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 353 | } |
| 354 | return state.PassAs<base::Value>(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 357 | void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
| 358 | { |
| 359 | DebugScopedSetImplThread impl(this); |
| 360 | if (renderer_initialized_) |
| 361 | layer_tree_host_impl_->renderer()->DoNoOp(); |
| 362 | } |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 365 | void SingleThreadProxy::OnSwapBuffersCompleteOnImplThread() { NOTREACHED(); } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 366 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 367 | bool SingleThreadProxy::CommitAndComposite(base::TimeTicks frame_begin_time) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 368 | DCHECK(Proxy::IsMainThread()); |
[email protected] | b1969fa | 2012-10-17 20:16:29 | [diff] [blame] | 369 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 370 | if (!layer_tree_host_->InitializeRendererIfNeeded()) |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 371 | return false; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 372 | |
| 373 | scoped_refptr<cc::ContextProvider> offscreen_context_provider; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 374 | if (renderer_capabilities_for_main_thread_.using_offscreen_context3d && |
| 375 | layer_tree_host_->needs_offscreen_context()) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 376 | offscreen_context_provider = |
| 377 | layer_tree_host_->client()->OffscreenContextProviderForMainThread(); |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 378 | if (offscreen_context_provider) |
| 379 | created_offscreen_context_provider_ = true; |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 380 | } |
| 381 | |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 382 | layer_tree_host_->contents_texture_manager()->UnlinkAndClearEvictedBackings(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 383 | |
| 384 | scoped_ptr<ResourceUpdateQueue> queue = |
| 385 | make_scoped_ptr(new ResourceUpdateQueue); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 386 | layer_tree_host_->UpdateLayers( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 387 | queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 388 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 389 | layer_tree_host_->WillCommit(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 390 | DoCommit(queue.Pass()); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 391 | bool result = DoComposite(offscreen_context_provider, frame_begin_time); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 392 | layer_tree_host_->DidBeginFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 393 | return result; |
[email protected] | 16288a4 | 2012-12-17 23:31:05 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 396 | bool SingleThreadProxy::DoComposite( |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 397 | scoped_refptr<cc::ContextProvider> offscreen_context_provider, |
| 398 | base::TimeTicks frame_begin_time) { |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 399 | DCHECK(!output_surface_lost_); |
| 400 | { |
| 401 | DebugScopedSetImplThread impl(this); |
| 402 | base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 403 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 404 | layer_tree_host_impl_->resource_provider()-> |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 405 | set_offscreen_context_provider(offscreen_context_provider); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 406 | |
| 407 | if (!layer_tree_host_impl_->visible()) |
| 408 | return false; |
| 409 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 410 | layer_tree_host_impl_->Animate(base::TimeTicks::Now(), base::Time::Now()); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 411 | |
| 412 | // We guard prepareToDraw() with canDraw() because it always returns a valid |
| 413 | // frame, so can only be used when such a frame is possible. Since |
| 414 | // drawLayers() depends on the result of prepareToDraw(), it is guarded on |
| 415 | // canDraw() as well. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 416 | if (!layer_tree_host_impl_->CanDraw()) |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 417 | return false; |
| 418 | |
| 419 | LayerTreeHostImpl::FrameData frame; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 420 | layer_tree_host_impl_->PrepareToDraw(&frame); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 421 | layer_tree_host_impl_->DrawLayers(&frame, frame_begin_time); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 422 | layer_tree_host_impl_->DidDrawAllLayers(frame); |
| 423 | output_surface_lost_ = layer_tree_host_impl_->IsContextLost(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 424 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 425 | layer_tree_host_impl_->BeginNextFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | if (output_surface_lost_) { |
| 429 | cc::ContextProvider* offscreen_contexts = layer_tree_host_impl_-> |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 430 | resource_provider()->offscreen_context_provider(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 431 | if (offscreen_contexts) |
| 432 | offscreen_contexts->VerifyContexts(); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 433 | layer_tree_host_->DidLoseOutputSurface(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | |
| 437 | return true; |
| 438 | } |
| 439 | |
| 440 | void SingleThreadProxy::DidSwapFrame() { |
| 441 | if (next_frame_is_newly_committed_frame_) { |
| 442 | next_frame_is_newly_committed_frame_ = false; |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 443 | layer_tree_host_->DidCommitAndDrawFrame(); |
[email protected] | a8a049c | 2013-03-11 23:27:06 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
| 448 | |
| 449 | skia::RefPtr<SkPicture> SingleThreadProxy::CapturePicture() { |
| 450 | // Impl-side painting only. |
| 451 | NOTREACHED(); |
| 452 | return skia::RefPtr<SkPicture>(); |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 453 | } |
| 454 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 455 | } // namespace cc |