OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "ui/gfx/rect_conversions.h" | 56 #include "ui/gfx/rect_conversions.h" |
57 | 57 |
58 using gpu::gles2::GLES2Interface; | 58 using gpu::gles2::GLES2Interface; |
59 | 59 |
60 namespace cc { | 60 namespace cc { |
61 namespace { | 61 namespace { |
62 | 62 |
63 class FallbackFence : public ResourceProvider::Fence { | 63 class FallbackFence : public ResourceProvider::Fence { |
64 public: | 64 public: |
65 explicit FallbackFence(gpu::gles2::GLES2Interface* gl) | 65 explicit FallbackFence(gpu::gles2::GLES2Interface* gl) |
66 : gl_(gl), has_passed_(false) {} | 66 : gl_(gl), has_passed_(true) {} |
67 | 67 |
68 // Overridden from ResourceProvider::Fence: | 68 // Overridden from ResourceProvider::Fence: |
| 69 virtual void Set() OVERRIDE { has_passed_ = false; } |
69 virtual bool HasPassed() OVERRIDE { | 70 virtual bool HasPassed() OVERRIDE { |
70 if (!has_passed_) { | 71 if (!has_passed_) { |
71 has_passed_ = true; | 72 has_passed_ = true; |
72 Synchronize(); | 73 Synchronize(); |
73 } | 74 } |
74 return true; | 75 return true; |
75 } | 76 } |
76 | 77 |
77 private: | 78 private: |
78 virtual ~FallbackFence() {} | 79 virtual ~FallbackFence() {} |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 base::CancelableClosure finished_read_pixels_callback; | 229 base::CancelableClosure finished_read_pixels_callback; |
229 unsigned buffer; | 230 unsigned buffer; |
230 | 231 |
231 private: | 232 private: |
232 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); | 233 DISALLOW_COPY_AND_ASSIGN(PendingAsyncReadPixels); |
233 }; | 234 }; |
234 | 235 |
235 class GLRenderer::SyncQuery { | 236 class GLRenderer::SyncQuery { |
236 public: | 237 public: |
237 explicit SyncQuery(gpu::gles2::GLES2Interface* gl) | 238 explicit SyncQuery(gpu::gles2::GLES2Interface* gl) |
238 : gl_(gl), query_id_(0u), weak_ptr_factory_(this) { | 239 : gl_(gl), query_id_(0u), is_pending_(false), weak_ptr_factory_(this) { |
239 gl_->GenQueriesEXT(1, &query_id_); | 240 gl_->GenQueriesEXT(1, &query_id_); |
240 } | 241 } |
241 virtual ~SyncQuery() { gl_->DeleteQueriesEXT(1, &query_id_); } | 242 virtual ~SyncQuery() { gl_->DeleteQueriesEXT(1, &query_id_); } |
242 | 243 |
243 scoped_refptr<ResourceProvider::Fence> Begin() { | 244 scoped_refptr<ResourceProvider::Fence> Begin() { |
244 DCHECK(!weak_ptr_factory_.HasWeakPtrs() || !IsPending()); | 245 DCHECK(!IsPending()); |
245 // Invalidate weak pointer held by old fence. | 246 // Invalidate weak pointer held by old fence. |
246 weak_ptr_factory_.InvalidateWeakPtrs(); | 247 weak_ptr_factory_.InvalidateWeakPtrs(); |
247 gl_->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query_id_); | 248 // Note: In case the set of drawing commands issued before End() do not |
| 249 // depend on the query, defer BeginQueryEXT call until Set() is called and |
| 250 // query is required. |
248 return make_scoped_refptr<ResourceProvider::Fence>( | 251 return make_scoped_refptr<ResourceProvider::Fence>( |
249 new Fence(weak_ptr_factory_.GetWeakPtr())); | 252 new Fence(weak_ptr_factory_.GetWeakPtr())); |
250 } | 253 } |
251 | 254 |
252 void End() { gl_->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); } | 255 void Set() { |
| 256 if (is_pending_) |
| 257 return; |
| 258 |
| 259 // Note: BeginQueryEXT on GL_COMMANDS_COMPLETED_CHROMIUM is effectively a |
| 260 // noop relative to GL, so it doesn't matter where it happens but we still |
| 261 // make sure to issue this command when Set() is called (prior to issuing |
| 262 // any drawing commands that depend on query), in case some future extension |
| 263 // can take advantage of this. |
| 264 gl_->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query_id_); |
| 265 is_pending_ = true; |
| 266 } |
| 267 |
| 268 void End() { |
| 269 if (!is_pending_) |
| 270 return; |
| 271 |
| 272 gl_->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
| 273 } |
253 | 274 |
254 bool IsPending() { | 275 bool IsPending() { |
255 unsigned available = 1; | 276 if (!is_pending_) |
| 277 return false; |
| 278 |
| 279 unsigned result_available = 1; |
256 gl_->GetQueryObjectuivEXT( | 280 gl_->GetQueryObjectuivEXT( |
257 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 281 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &result_available); |
258 return !available; | 282 is_pending_ = !result_available; |
| 283 return is_pending_; |
259 } | 284 } |
260 | 285 |
261 void Wait() { | 286 void Wait() { |
| 287 if (!is_pending_) |
| 288 return; |
| 289 |
262 unsigned result = 0; | 290 unsigned result = 0; |
263 gl_->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result); | 291 gl_->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result); |
| 292 is_pending_ = false; |
264 } | 293 } |
265 | 294 |
266 private: | 295 private: |
267 class Fence : public ResourceProvider::Fence { | 296 class Fence : public ResourceProvider::Fence { |
268 public: | 297 public: |
269 explicit Fence(base::WeakPtr<GLRenderer::SyncQuery> query) | 298 explicit Fence(base::WeakPtr<GLRenderer::SyncQuery> query) |
270 : query_(query) {} | 299 : query_(query) {} |
271 | 300 |
272 // Overridden from ResourceProvider::Fence: | 301 // Overridden from ResourceProvider::Fence: |
| 302 virtual void Set() OVERRIDE { |
| 303 DCHECK(query_); |
| 304 query_->Set(); |
| 305 } |
273 virtual bool HasPassed() OVERRIDE { | 306 virtual bool HasPassed() OVERRIDE { |
274 return !query_ || !query_->IsPending(); | 307 return !query_ || !query_->IsPending(); |
275 } | 308 } |
276 | 309 |
277 private: | 310 private: |
278 virtual ~Fence() {} | 311 virtual ~Fence() {} |
279 | 312 |
280 base::WeakPtr<SyncQuery> query_; | 313 base::WeakPtr<SyncQuery> query_; |
281 | 314 |
282 DISALLOW_COPY_AND_ASSIGN(Fence); | 315 DISALLOW_COPY_AND_ASSIGN(Fence); |
283 }; | 316 }; |
284 | 317 |
285 gpu::gles2::GLES2Interface* gl_; | 318 gpu::gles2::GLES2Interface* gl_; |
286 unsigned query_id_; | 319 unsigned query_id_; |
| 320 bool is_pending_; |
287 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; | 321 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; |
288 | 322 |
289 DISALLOW_COPY_AND_ASSIGN(SyncQuery); | 323 DISALLOW_COPY_AND_ASSIGN(SyncQuery); |
290 }; | 324 }; |
291 | 325 |
292 scoped_ptr<GLRenderer> GLRenderer::Create( | 326 scoped_ptr<GLRenderer> GLRenderer::Create( |
293 RendererClient* client, | 327 RendererClient* client, |
294 const LayerTreeSettings* settings, | 328 const LayerTreeSettings* settings, |
295 OutputSurface* output_surface, | 329 OutputSurface* output_surface, |
296 ResourceProvider* resource_provider, | 330 ResourceProvider* resource_provider, |
(...skipping 2874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 context_support_->ScheduleOverlayPlane( | 3205 context_support_->ScheduleOverlayPlane( |
3172 overlay.plane_z_order, | 3206 overlay.plane_z_order, |
3173 overlay.transform, | 3207 overlay.transform, |
3174 pending_overlay_resources_.back()->texture_id(), | 3208 pending_overlay_resources_.back()->texture_id(), |
3175 overlay.display_rect, | 3209 overlay.display_rect, |
3176 overlay.uv_rect); | 3210 overlay.uv_rect); |
3177 } | 3211 } |
3178 } | 3212 } |
3179 | 3213 |
3180 } // namespace cc | 3214 } // namespace cc |
OLD | NEW |