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

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

Issue 2341043002: webgl: Replace query task observer with a posted task (Closed)
Patch Set: Use CancellableTaskFactory instead Created 4 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/WebGLTimerQueryEXT.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 "modules/webgl/WebGLTimerQueryEXT.h" 5 #include "modules/webgl/WebGLTimerQueryEXT.h"
6 6
7 #include "core/dom/TaskRunnerHelper.h"
7 #include "gpu/command_buffer/client/gles2_interface.h" 8 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "modules/webgl/WebGLRenderingContextBase.h" 9 #include "modules/webgl/WebGLRenderingContextBase.h"
9 #include "public/platform/Platform.h" 10 #include "public/platform/Platform.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 WebGLTimerQueryEXT* WebGLTimerQueryEXT::create(WebGLRenderingContextBase* ctx) 14 WebGLTimerQueryEXT* WebGLTimerQueryEXT::create(WebGLRenderingContextBase* ctx)
14 { 15 {
15 return new WebGLTimerQueryEXT(ctx); 16 return new WebGLTimerQueryEXT(ctx);
16 } 17 }
17 18
18 WebGLTimerQueryEXT::~WebGLTimerQueryEXT() 19 WebGLTimerQueryEXT::~WebGLTimerQueryEXT()
19 { 20 {
20 unregisterTaskObserver();
21
22 // See the comment in WebGLObject::detachAndDeleteObject(). 21 // See the comment in WebGLObject::detachAndDeleteObject().
23 detachAndDeleteObject(); 22 detachAndDeleteObject();
24 } 23 }
25 24
26 WebGLTimerQueryEXT::WebGLTimerQueryEXT(WebGLRenderingContextBase* ctx) 25 WebGLTimerQueryEXT::WebGLTimerQueryEXT(WebGLRenderingContextBase* ctx)
27 : WebGLContextObject(ctx) 26 : WebGLContextObject(ctx)
28 , m_target(0) 27 , m_target(0)
29 , m_queryId(0) 28 , m_queryId(0)
30 , m_taskObserverRegistered(false)
31 , m_canUpdateAvailability(false) 29 , m_canUpdateAvailability(false)
32 , m_queryResultAvailable(false) 30 , m_queryResultAvailable(false)
33 , m_queryResult(0) 31 , m_queryResult(0)
32 , m_taskRunner(TaskRunnerHelper::get(TaskType::Unthrottled, &ctx->canvas()-> document())->clone())
33 , m_cancellableTaskFactory(CancellableTaskFactory::create(this, &WebGLTimerQ ueryEXT::allowAvailabilityUpdate))
34 { 34 {
35 context()->contextGL()->GenQueriesEXT(1, &m_queryId); 35 context()->contextGL()->GenQueriesEXT(1, &m_queryId);
36 } 36 }
37 37
38 void WebGLTimerQueryEXT::resetCachedResult() 38 void WebGLTimerQueryEXT::resetCachedResult()
39 { 39 {
40 m_canUpdateAvailability = false; 40 m_canUpdateAvailability = false;
41 m_queryResultAvailable = false; 41 m_queryResultAvailable = false;
42 m_queryResult = 0; 42 m_queryResult = 0;
43 // When this is called, the implication is that we should start 43 // When this is called, the implication is that we should start
44 // keeping track of whether we can update the cached availability 44 // keeping track of whether we can update the cached availability
45 // and result. 45 // and result.
46 registerTaskObserver(); 46 scheduleAllowAvailabilityUpdate();
47 } 47 }
48 48
49 void WebGLTimerQueryEXT::updateCachedResult(gpu::gles2::GLES2Interface* gl) 49 void WebGLTimerQueryEXT::updateCachedResult(gpu::gles2::GLES2Interface* gl)
50 { 50 {
51 if (m_queryResultAvailable) 51 if (m_queryResultAvailable)
52 return; 52 return;
53 53
54 if (!m_canUpdateAvailability) 54 if (!m_canUpdateAvailability)
55 return; 55 return;
56 56
57 if (!hasTarget()) 57 if (!hasTarget())
58 return; 58 return;
59 59
60 // If this is a timestamp query, set the result to 0 and make it available a s we don't support timestamps in WebGL due to very poor driver support for them 60 // If this is a timestamp query, set the result to 0 and make it available a s we don't support timestamps in WebGL due to very poor driver support for them
61 if (m_target == GL_TIMESTAMP_EXT) { 61 if (m_target == GL_TIMESTAMP_EXT) {
62 m_queryResult = 0; 62 m_queryResult = 0;
63 m_queryResultAvailable = true; 63 m_queryResultAvailable = true;
64 return; 64 return;
65 } 65 }
66 66
67 // We can only update the cached result when control returns to the browser. 67 // We can only update the cached result when control returns to the browser.
68 m_canUpdateAvailability = false; 68 m_canUpdateAvailability = false;
69 GLuint available = 0; 69 GLuint available = 0;
70 gl->GetQueryObjectuivEXT(object(), GL_QUERY_RESULT_AVAILABLE_EXT, &available ); 70 gl->GetQueryObjectuivEXT(object(), GL_QUERY_RESULT_AVAILABLE_EXT, &available );
71 m_queryResultAvailable = !!available; 71 m_queryResultAvailable = !!available;
72 if (m_queryResultAvailable) { 72 if (m_queryResultAvailable) {
73 GLuint64 result = 0; 73 GLuint64 result = 0;
74 gl->GetQueryObjectui64vEXT(object(), GL_QUERY_RESULT_EXT, &result); 74 gl->GetQueryObjectui64vEXT(object(), GL_QUERY_RESULT_EXT, &result);
75 m_queryResult = result; 75 m_queryResult = result;
76 unregisterTaskObserver(); 76 m_cancellableTaskFactory->cancel();
77 } else {
78 scheduleAllowAvailabilityUpdate();
77 } 79 }
78 } 80 }
79 81
80 bool WebGLTimerQueryEXT::isQueryResultAvailable() 82 bool WebGLTimerQueryEXT::isQueryResultAvailable()
81 { 83 {
82 return m_queryResultAvailable; 84 return m_queryResultAvailable;
83 } 85 }
84 86
85 GLuint64 WebGLTimerQueryEXT::getQueryResult() 87 GLuint64 WebGLTimerQueryEXT::getQueryResult()
86 { 88 {
87 return m_queryResult; 89 return m_queryResult;
88 } 90 }
89 91
90 void WebGLTimerQueryEXT::deleteObjectImpl(gpu::gles2::GLES2Interface* gl) 92 void WebGLTimerQueryEXT::deleteObjectImpl(gpu::gles2::GLES2Interface* gl)
91 { 93 {
92 gl->DeleteQueriesEXT(1, &m_queryId); 94 gl->DeleteQueriesEXT(1, &m_queryId);
93 m_queryId = 0; 95 m_queryId = 0;
94 } 96 }
95 97
96 void WebGLTimerQueryEXT::registerTaskObserver() 98 void WebGLTimerQueryEXT::scheduleAllowAvailabilityUpdate()
97 { 99 {
98 if (!m_taskObserverRegistered) { 100 if (!m_cancellableTaskFactory->isPending())
99 m_taskObserverRegistered = true; 101 m_taskRunner->postTask(BLINK_FROM_HERE, m_cancellableTaskFactory->cancel AndCreate());
100 Platform::current()->currentThread()->addTaskObserver(this);
101 }
102 } 102 }
103 103
104 void WebGLTimerQueryEXT::unregisterTaskObserver() 104 void WebGLTimerQueryEXT::allowAvailabilityUpdate()
105 {
106 if (m_taskObserverRegistered) {
107 m_taskObserverRegistered = false;
108 Platform::current()->currentThread()->removeTaskObserver(this);
109 }
110 }
111
112 void WebGLTimerQueryEXT::didProcessTask()
113 { 105 {
114 m_canUpdateAvailability = true; 106 m_canUpdateAvailability = true;
115 } 107 }
116 108
117 } // namespace blink 109 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLTimerQueryEXT.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698