Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp

Issue 1408803003: Enforce queries' new availability semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLQuery.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 6
7 #include "modules/webgl/WebGLQuery.h" 7 #include "modules/webgl/WebGLQuery.h"
8 8
9 #include "modules/webgl/WebGL2RenderingContextBase.h" 9 #include "modules/webgl/WebGL2RenderingContextBase.h"
10 #include "public/platform/Platform.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 WebGLQuery* WebGLQuery::create(WebGL2RenderingContextBase* ctx) 14 WebGLQuery* WebGLQuery::create(WebGL2RenderingContextBase* ctx)
14 { 15 {
15 return new WebGLQuery(ctx); 16 return new WebGLQuery(ctx);
16 } 17 }
17 18
18 WebGLQuery::~WebGLQuery() 19 WebGLQuery::~WebGLQuery()
19 { 20 {
21 unregisterTaskObserver();
22
20 // See the comment in WebGLObject::detachAndDeleteObject(). 23 // See the comment in WebGLObject::detachAndDeleteObject().
21 detachAndDeleteObject(); 24 detachAndDeleteObject();
22 } 25 }
23 26
24 WebGLQuery::WebGLQuery(WebGL2RenderingContextBase* ctx) 27 WebGLQuery::WebGLQuery(WebGL2RenderingContextBase* ctx)
25 : WebGLSharedPlatform3DObject(ctx) 28 : WebGLSharedPlatform3DObject(ctx)
26 , m_target(0) 29 , m_target(0)
30 , m_taskObserverRegistered(false)
31 , m_canUpdateAvailability(false)
32 , m_queryResultAvailable(false)
33 , m_queryResult(0)
27 { 34 {
28 setObject(ctx->webContext()->createQueryEXT()); 35 setObject(ctx->webContext()->createQueryEXT());
29 } 36 }
30 37
31 void WebGLQuery::setTarget(GLenum target) 38 void WebGLQuery::setTarget(GLenum target)
32 { 39 {
33 ASSERT(object()); 40 ASSERT(object());
34 ASSERT(!m_target); 41 ASSERT(!m_target);
35 m_target = target; 42 m_target = target;
36 } 43 }
37 44
38 void WebGLQuery::deleteObjectImpl(WebGraphicsContext3D* context3d) 45 void WebGLQuery::deleteObjectImpl(WebGraphicsContext3D* context3d)
39 { 46 {
40 context3d->deleteQueryEXT(m_object); 47 context3d->deleteQueryEXT(m_object);
41 m_object = 0; 48 m_object = 0;
42 } 49 }
43 50
51 void WebGLQuery::resetCachedResult()
52 {
53 m_canUpdateAvailability = false;
54 m_queryResultAvailable = false;
55 m_queryResult = 0;
56 // When this is called, the implication is that we should start
57 // keeping track of whether we can update the cached availability
58 // and result.
59 registerTaskObserver();
60 }
61
62 void WebGLQuery::updateCachedResult(WebGraphicsContext3D* ctx)
63 {
64 if (m_queryResultAvailable)
65 return;
66
67 if (!m_canUpdateAvailability)
68 return;
69
70 if (!hasTarget())
71 return;
72
73 // We can only update the cached result when control returns to the browser.
74 m_canUpdateAvailability = false;
75 GLuint available = 0;
76 ctx->getQueryObjectuivEXT(object(), GL_QUERY_RESULT_AVAILABLE_EXT, &availabl e);
77 m_queryResultAvailable = !!available;
78 if (m_queryResultAvailable) {
79 GLuint result = 0;
80 ctx->getQueryObjectuivEXT(object(), GL_QUERY_RESULT_EXT, &result);
81 m_queryResult = result;
82 unregisterTaskObserver();
83 }
84 }
85
86 bool WebGLQuery::isQueryResultAvailable()
87 {
88 return m_queryResultAvailable;
89 }
90
91 GLuint WebGLQuery::getQueryResult()
92 {
93 return m_queryResult;
94 }
95
96 void WebGLQuery::registerTaskObserver()
97 {
98 if (!m_taskObserverRegistered) {
99 m_taskObserverRegistered = true;
100 Platform::current()->currentThread()->addTaskObserver(this);
101 }
102 }
103
104 void WebGLQuery::unregisterTaskObserver()
105 {
106 if (m_taskObserverRegistered) {
107 m_taskObserverRegistered = false;
108 Platform::current()->currentThread()->removeTaskObserver(this);
109 }
110 }
111
112 void WebGLQuery::didProcessTask()
113 {
114 m_canUpdateAvailability = true;
115 }
116
44 } // namespace blink 117 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLQuery.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698