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(!weak_ptr_factory_.HasWeakPtrs() || !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 is_pending_ = false; |
248 return make_scoped_refptr<ResourceProvider::Fence>( | 249 return make_scoped_refptr<ResourceProvider::Fence>( |
249 new Fence(weak_ptr_factory_.GetWeakPtr())); | 250 new Fence(weak_ptr_factory_.GetWeakPtr())); |
250 } | 251 } |
251 | 252 |
252 void End() { gl_->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); } | 253 void Set() { is_pending_ = true; } |
254 | |
255 void End() { | |
256 if (!is_pending_) | |
257 return; | |
258 | |
259 gl_->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query_id_); | |
piman
2014/07/18 22:19:42
nit: it's a bit of an abuse. Maybe add a comment s
reveman
2014/07/18 23:51:06
Good point. I've updated the patch so we're still
| |
260 gl_->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | |
261 } | |
253 | 262 |
254 bool IsPending() { | 263 bool IsPending() { |
255 unsigned available = 1; | 264 if (!is_pending_) |
265 return false; | |
266 | |
267 unsigned result_available = 1; | |
256 gl_->GetQueryObjectuivEXT( | 268 gl_->GetQueryObjectuivEXT( |
257 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 269 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &result_available); |
258 return !available; | 270 is_pending_ = !result_available; |
271 return is_pending_; | |
259 } | 272 } |
260 | 273 |
261 void Wait() { | 274 void Wait() { |
275 if (!is_pending_) | |
276 return; | |
277 | |
262 unsigned result = 0; | 278 unsigned result = 0; |
263 gl_->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result); | 279 gl_->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result); |
264 } | 280 } |
265 | 281 |
266 private: | 282 private: |
267 class Fence : public ResourceProvider::Fence { | 283 class Fence : public ResourceProvider::Fence { |
268 public: | 284 public: |
269 explicit Fence(base::WeakPtr<GLRenderer::SyncQuery> query) | 285 explicit Fence(base::WeakPtr<GLRenderer::SyncQuery> query) |
270 : query_(query) {} | 286 : query_(query) {} |
271 | 287 |
272 // Overridden from ResourceProvider::Fence: | 288 // Overridden from ResourceProvider::Fence: |
289 virtual void Set() OVERRIDE { | |
290 DCHECK(query_); | |
291 query_->Set(); | |
292 } | |
273 virtual bool HasPassed() OVERRIDE { | 293 virtual bool HasPassed() OVERRIDE { |
274 return !query_ || !query_->IsPending(); | 294 return !query_ || !query_->IsPending(); |
275 } | 295 } |
276 | 296 |
277 private: | 297 private: |
278 virtual ~Fence() {} | 298 virtual ~Fence() {} |
279 | 299 |
280 base::WeakPtr<SyncQuery> query_; | 300 base::WeakPtr<SyncQuery> query_; |
281 | 301 |
282 DISALLOW_COPY_AND_ASSIGN(Fence); | 302 DISALLOW_COPY_AND_ASSIGN(Fence); |
283 }; | 303 }; |
284 | 304 |
285 gpu::gles2::GLES2Interface* gl_; | 305 gpu::gles2::GLES2Interface* gl_; |
286 unsigned query_id_; | 306 unsigned query_id_; |
307 bool is_pending_; | |
287 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; | 308 base::WeakPtrFactory<SyncQuery> weak_ptr_factory_; |
288 | 309 |
289 DISALLOW_COPY_AND_ASSIGN(SyncQuery); | 310 DISALLOW_COPY_AND_ASSIGN(SyncQuery); |
290 }; | 311 }; |
291 | 312 |
292 scoped_ptr<GLRenderer> GLRenderer::Create( | 313 scoped_ptr<GLRenderer> GLRenderer::Create( |
293 RendererClient* client, | 314 RendererClient* client, |
294 const LayerTreeSettings* settings, | 315 const LayerTreeSettings* settings, |
295 OutputSurface* output_surface, | 316 OutputSurface* output_surface, |
296 ResourceProvider* resource_provider, | 317 ResourceProvider* resource_provider, |
(...skipping 2874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3171 context_support_->ScheduleOverlayPlane( | 3192 context_support_->ScheduleOverlayPlane( |
3172 overlay.plane_z_order, | 3193 overlay.plane_z_order, |
3173 overlay.transform, | 3194 overlay.transform, |
3174 pending_overlay_resources_.back()->texture_id(), | 3195 pending_overlay_resources_.back()->texture_id(), |
3175 overlay.display_rect, | 3196 overlay.display_rect, |
3176 overlay.uv_rect); | 3197 overlay.uv_rect); |
3177 } | 3198 } |
3178 } | 3199 } |
3179 | 3200 |
3180 } // namespace cc | 3201 } // namespace cc |
OLD | NEW |