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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/output/managed_memory_policy.h" | 10 #include "cc/output/managed_memory_policy.h" |
11 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
12 #include "gpu/GLES2/gl2extchromium.h" | 12 #include "gpu/GLES2/gl2extchromium.h" |
13 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
16 | 16 |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 OutputSurface::OutputSurface( | 20 OutputSurface::OutputSurface( |
21 const scoped_refptr<ContextProvider>& context_provider) | 21 const scoped_refptr<ContextProvider>& context_provider, |
| 22 const scoped_refptr<ContextProvider>& worker_context_provider, |
| 23 scoped_ptr<SoftwareOutputDevice> software_device) |
22 : client_(NULL), | 24 : client_(NULL), |
23 context_provider_(context_provider), | 25 context_provider_(context_provider), |
24 device_scale_factor_(-1), | 26 worker_context_provider_(worker_context_provider), |
25 external_stencil_test_enabled_(false), | |
26 weak_ptr_factory_(this) { | |
27 } | |
28 | |
29 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) | |
30 : client_(NULL), | |
31 software_device_(software_device.Pass()), | 27 software_device_(software_device.Pass()), |
32 device_scale_factor_(-1), | 28 device_scale_factor_(-1), |
33 external_stencil_test_enabled_(false), | 29 external_stencil_test_enabled_(false), |
34 weak_ptr_factory_(this) { | 30 weak_ptr_factory_(this) { |
35 } | 31 } |
36 | 32 |
37 OutputSurface::OutputSurface( | 33 OutputSurface::OutputSurface( |
| 34 const scoped_refptr<ContextProvider>& context_provider) |
| 35 : OutputSurface(context_provider, nullptr, nullptr) { |
| 36 } |
| 37 |
| 38 OutputSurface::OutputSurface( |
| 39 const scoped_refptr<ContextProvider>& context_provider, |
| 40 const scoped_refptr<ContextProvider>& worker_context_provider) |
| 41 : OutputSurface(context_provider, worker_context_provider, nullptr) { |
| 42 } |
| 43 |
| 44 OutputSurface::OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) |
| 45 : OutputSurface(nullptr, nullptr, software_device.Pass()) { |
| 46 } |
| 47 |
| 48 OutputSurface::OutputSurface( |
38 const scoped_refptr<ContextProvider>& context_provider, | 49 const scoped_refptr<ContextProvider>& context_provider, |
39 scoped_ptr<SoftwareOutputDevice> software_device) | 50 scoped_ptr<SoftwareOutputDevice> software_device) |
40 : client_(NULL), | 51 : OutputSurface(context_provider, nullptr, software_device.Pass()) { |
41 context_provider_(context_provider), | |
42 software_device_(software_device.Pass()), | |
43 device_scale_factor_(-1), | |
44 external_stencil_test_enabled_(false), | |
45 weak_ptr_factory_(this) { | |
46 } | 52 } |
47 | 53 |
48 void OutputSurface::CommitVSyncParameters(base::TimeTicks timebase, | 54 void OutputSurface::CommitVSyncParameters(base::TimeTicks timebase, |
49 base::TimeDelta interval) { | 55 base::TimeDelta interval) { |
50 TRACE_EVENT2("cc", | 56 TRACE_EVENT2("cc", |
51 "OutputSurface::CommitVSyncParameters", | 57 "OutputSurface::CommitVSyncParameters", |
52 "timebase", | 58 "timebase", |
53 (timebase - base::TimeTicks()).InSecondsF(), | 59 (timebase - base::TimeTicks()).InSecondsF(), |
54 "interval", | 60 "interval", |
55 interval.InSecondsF()); | 61 interval.InSecondsF()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 DCHECK(client); | 108 DCHECK(client); |
103 client_ = client; | 109 client_ = client; |
104 bool success = true; | 110 bool success = true; |
105 | 111 |
106 if (context_provider_.get()) { | 112 if (context_provider_.get()) { |
107 success = context_provider_->BindToCurrentThread(); | 113 success = context_provider_->BindToCurrentThread(); |
108 if (success) | 114 if (success) |
109 SetUpContext3d(); | 115 SetUpContext3d(); |
110 } | 116 } |
111 | 117 |
| 118 if (success && worker_context_provider_.get()) { |
| 119 success = worker_context_provider_->BindToCurrentThread(); |
| 120 if (success) { |
| 121 worker_context_provider_->SetupLock(); |
| 122 // The destructor resets the context lost callback, so base::Unretained |
| 123 // is safe, as long as the worker threads stop using the context before |
| 124 // the output surface is destroyed. |
| 125 worker_context_provider_->SetLostContextCallback(base::Bind( |
| 126 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); |
| 127 } |
| 128 } |
| 129 |
112 if (!success) | 130 if (!success) |
113 client_ = NULL; | 131 client_ = NULL; |
114 | 132 |
115 return success; | 133 return success; |
116 } | 134 } |
117 | 135 |
118 bool OutputSurface::InitializeAndSetContext3d( | 136 bool OutputSurface::InitializeAndSetContext3d( |
119 scoped_refptr<ContextProvider> context_provider) { | 137 scoped_refptr<ContextProvider> context_provider, |
| 138 scoped_refptr<ContextProvider> worker_context_provider) { |
120 DCHECK(!context_provider_.get()); | 139 DCHECK(!context_provider_.get()); |
121 DCHECK(context_provider.get()); | 140 DCHECK(context_provider.get()); |
122 DCHECK(client_); | 141 DCHECK(client_); |
123 | 142 |
124 bool success = false; | 143 bool success = context_provider->BindToCurrentThread(); |
125 if (context_provider->BindToCurrentThread()) { | 144 if (success) { |
126 context_provider_ = context_provider; | 145 context_provider_ = context_provider; |
127 SetUpContext3d(); | 146 SetUpContext3d(); |
128 client_->DeferredInitialize(); | 147 } |
129 success = true; | 148 if (success && worker_context_provider.get()) { |
| 149 success = worker_context_provider->BindToCurrentThread(); |
| 150 if (success) { |
| 151 worker_context_provider_ = worker_context_provider; |
| 152 // The destructor resets the context lost callback, so base::Unretained |
| 153 // is safe, as long as the worker threads stop using the context before |
| 154 // the output surface is destroyed. |
| 155 worker_context_provider_->SetLostContextCallback(base::Bind( |
| 156 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); |
| 157 } |
130 } | 158 } |
131 | 159 |
132 if (!success) | 160 if (!success) |
133 ResetContext3d(); | 161 ResetContext3d(); |
| 162 else |
| 163 client_->DeferredInitialize(); |
134 | 164 |
135 return success; | 165 return success; |
136 } | 166 } |
137 | 167 |
138 void OutputSurface::ReleaseGL() { | 168 void OutputSurface::ReleaseGL() { |
139 DCHECK(client_); | 169 DCHECK(client_); |
140 DCHECK(context_provider_.get()); | 170 DCHECK(context_provider_.get()); |
141 client_->ReleaseGL(); | 171 client_->ReleaseGL(); |
142 DCHECK(!context_provider_.get()); | 172 DCHECK(!context_provider_.get()); |
143 } | 173 } |
(...skipping 16 matching lines...) Expand all Loading... |
160 ResetContext3d(); | 190 ResetContext3d(); |
161 } | 191 } |
162 | 192 |
163 void OutputSurface::ResetContext3d() { | 193 void OutputSurface::ResetContext3d() { |
164 if (context_provider_.get()) { | 194 if (context_provider_.get()) { |
165 context_provider_->SetLostContextCallback( | 195 context_provider_->SetLostContextCallback( |
166 ContextProvider::LostContextCallback()); | 196 ContextProvider::LostContextCallback()); |
167 context_provider_->SetMemoryPolicyChangedCallback( | 197 context_provider_->SetMemoryPolicyChangedCallback( |
168 ContextProvider::MemoryPolicyChangedCallback()); | 198 ContextProvider::MemoryPolicyChangedCallback()); |
169 } | 199 } |
| 200 if (worker_context_provider_.get()) { |
| 201 worker_context_provider_->SetLostContextCallback( |
| 202 ContextProvider::LostContextCallback()); |
| 203 } |
170 context_provider_ = NULL; | 204 context_provider_ = NULL; |
| 205 worker_context_provider_ = NULL; |
171 } | 206 } |
172 | 207 |
173 void OutputSurface::EnsureBackbuffer() { | 208 void OutputSurface::EnsureBackbuffer() { |
174 if (software_device_) | 209 if (software_device_) |
175 software_device_->EnsureBackbuffer(); | 210 software_device_->EnsureBackbuffer(); |
176 } | 211 } |
177 | 212 |
178 void OutputSurface::DiscardBackbuffer() { | 213 void OutputSurface::DiscardBackbuffer() { |
179 if (context_provider_.get()) | 214 if (context_provider_.get()) |
180 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); | 215 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", | 257 TRACE_EVENT1("cc", "OutputSurface::SetMemoryPolicy", |
223 "bytes_limit_when_visible", policy.bytes_limit_when_visible); | 258 "bytes_limit_when_visible", policy.bytes_limit_when_visible); |
224 // Just ignore the memory manager when it says to set the limit to zero | 259 // Just ignore the memory manager when it says to set the limit to zero |
225 // bytes. This will happen when the memory manager thinks that the renderer | 260 // bytes. This will happen when the memory manager thinks that the renderer |
226 // is not visible (which the renderer knows better). | 261 // is not visible (which the renderer knows better). |
227 if (policy.bytes_limit_when_visible) | 262 if (policy.bytes_limit_when_visible) |
228 client_->SetMemoryPolicy(policy); | 263 client_->SetMemoryPolicy(policy); |
229 } | 264 } |
230 | 265 |
231 } // namespace cc | 266 } // namespace cc |
OLD | NEW |