| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "cc/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const scoped_refptr<ContextProvider>& context_provider, | 25 const scoped_refptr<ContextProvider>& context_provider, |
| 26 const scoped_refptr<ContextProvider>& worker_context_provider, | 26 const scoped_refptr<ContextProvider>& worker_context_provider, |
| 27 scoped_ptr<SoftwareOutputDevice> software_device) | 27 scoped_ptr<SoftwareOutputDevice> software_device) |
| 28 : client_(NULL), | 28 : client_(NULL), |
| 29 context_provider_(context_provider), | 29 context_provider_(context_provider), |
| 30 worker_context_provider_(worker_context_provider), | 30 worker_context_provider_(worker_context_provider), |
| 31 software_device_(software_device.Pass()), | 31 software_device_(software_device.Pass()), |
| 32 device_scale_factor_(-1), | 32 device_scale_factor_(-1), |
| 33 external_stencil_test_enabled_(false), | 33 external_stencil_test_enabled_(false), |
| 34 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 35 client_thread_checker_.DetachFromThread(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 OutputSurface::OutputSurface( | 38 OutputSurface::OutputSurface( |
| 38 const scoped_refptr<ContextProvider>& context_provider) | 39 const scoped_refptr<ContextProvider>& context_provider) |
| 39 : OutputSurface(context_provider, nullptr, nullptr) { | 40 : OutputSurface(context_provider, nullptr, nullptr) { |
| 40 } | 41 } |
| 41 | 42 |
| 42 OutputSurface::OutputSurface( | 43 OutputSurface::OutputSurface( |
| 43 const scoped_refptr<ContextProvider>& context_provider, | 44 const scoped_refptr<ContextProvider>& context_provider, |
| 44 const scoped_refptr<ContextProvider>& worker_context_provider) | 45 const scoped_refptr<ContextProvider>& worker_context_provider) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 bool resourceless_software_draw) { | 95 bool resourceless_software_draw) { |
| 95 client_->SetExternalDrawConstraints(transform, | 96 client_->SetExternalDrawConstraints(transform, |
| 96 viewport, | 97 viewport, |
| 97 clip, | 98 clip, |
| 98 viewport_rect_for_tile_priority, | 99 viewport_rect_for_tile_priority, |
| 99 transform_for_tile_priority, | 100 transform_for_tile_priority, |
| 100 resourceless_software_draw); | 101 resourceless_software_draw); |
| 101 } | 102 } |
| 102 | 103 |
| 103 OutputSurface::~OutputSurface() { | 104 OutputSurface::~OutputSurface() { |
| 104 if (context_provider_.get()) { | 105 if (client_) |
| 105 context_provider_->SetLostContextCallback( | 106 DetachFromClient(); |
| 106 ContextProvider::LostContextCallback()); | |
| 107 context_provider_->SetMemoryPolicyChangedCallback( | |
| 108 ContextProvider::MemoryPolicyChangedCallback()); | |
| 109 } | |
| 110 } | 107 } |
| 111 | 108 |
| 112 bool OutputSurface::HasExternalStencilTest() const { | 109 bool OutputSurface::HasExternalStencilTest() const { |
| 113 return external_stencil_test_enabled_; | 110 return external_stencil_test_enabled_; |
| 114 } | 111 } |
| 115 | 112 |
| 116 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { | 113 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 117 DCHECK(client); | 114 DCHECK(client); |
| 115 DCHECK(!client_); |
| 116 DCHECK(CalledOnValidClientThread()); |
| 118 client_ = client; | 117 client_ = client; |
| 119 bool success = true; | 118 bool success = true; |
| 120 | 119 |
| 121 if (context_provider_.get()) { | 120 if (context_provider_.get()) { |
| 122 success = context_provider_->BindToCurrentThread(); | 121 success = context_provider_->BindToCurrentThread(); |
| 123 if (success) { | 122 if (success) { |
| 124 context_provider_->SetLostContextCallback(base::Bind( | 123 context_provider_->SetLostContextCallback(base::Bind( |
| 125 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); | 124 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); |
| 126 context_provider_->SetMemoryPolicyChangedCallback( | 125 context_provider_->SetMemoryPolicyChangedCallback( |
| 127 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); | 126 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); |
| 128 } | 127 } |
| 129 } | 128 } |
| 130 | 129 |
| 131 if (success && worker_context_provider_.get()) { | |
| 132 success = worker_context_provider_->BindToCurrentThread(); | |
| 133 if (success) | |
| 134 worker_context_provider_->SetupLock(); | |
| 135 } | |
| 136 | |
| 137 if (!success) | 130 if (!success) |
| 138 client_ = NULL; | 131 client_ = NULL; |
| 139 | 132 |
| 140 return success; | 133 return success; |
| 141 } | 134 } |
| 142 | 135 |
| 136 void OutputSurface::DetachFromClient() { |
| 137 DCHECK(CalledOnValidClientThread()); |
| 138 DCHECK(client_); |
| 139 if (context_provider_.get()) { |
| 140 context_provider_->SetLostContextCallback( |
| 141 ContextProvider::LostContextCallback()); |
| 142 context_provider_->SetMemoryPolicyChangedCallback( |
| 143 ContextProvider::MemoryPolicyChangedCallback()); |
| 144 } |
| 145 context_provider_ = nullptr; |
| 146 client_ = nullptr; |
| 147 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 148 } |
| 149 |
| 150 bool OutputSurface::CalledOnValidClientThread() { |
| 151 return client_thread_checker_.CalledOnValidThread(); |
| 152 } |
| 153 |
| 143 void OutputSurface::EnsureBackbuffer() { | 154 void OutputSurface::EnsureBackbuffer() { |
| 144 if (software_device_) | 155 if (software_device_) |
| 145 software_device_->EnsureBackbuffer(); | 156 software_device_->EnsureBackbuffer(); |
| 146 } | 157 } |
| 147 | 158 |
| 148 void OutputSurface::DiscardBackbuffer() { | 159 void OutputSurface::DiscardBackbuffer() { |
| 149 if (context_provider_.get()) | 160 if (context_provider_.get()) |
| 150 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); | 161 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); |
| 151 if (software_device_) | 162 if (software_device_) |
| 152 software_device_->DiscardBackbuffer(); | 163 software_device_->DiscardBackbuffer(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 aggressively_free_resources); | 229 aggressively_free_resources); |
| 219 } | 230 } |
| 220 } | 231 } |
| 221 } | 232 } |
| 222 | 233 |
| 223 bool OutputSurface::SurfaceIsSuspendForRecycle() const { | 234 bool OutputSurface::SurfaceIsSuspendForRecycle() const { |
| 224 return false; | 235 return false; |
| 225 } | 236 } |
| 226 | 237 |
| 227 } // namespace cc | 238 } // namespace cc |
| OLD | NEW |