Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/WebGLTimerQueryEXT.h" | 7 #include "modules/webgl/WebGLTimerQueryEXT.h" |
| 8 | 8 |
| 9 #include "modules/webgl/WebGLRenderingContextBase.h" | 9 #include "modules/webgl/WebGLRenderingContextBase.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 { |
| 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 WebGLTimerQueryEXT::WebGLTimerQueryEXT(WebGLRenderingContextBase* ctx) | 27 WebGLTimerQueryEXT::WebGLTimerQueryEXT(WebGLRenderingContextBase* ctx) |
| 25 : WebGLContextObject(ctx) | 28 : WebGLContextObject(ctx) |
| 26 , m_target(0) | 29 , m_target(0) |
| 27 , m_queryId(0) | 30 , m_queryId(0) |
| 31 , m_taskObserverRegistered(false) | |
| 32 , m_canUpdateAvailability(false) | |
| 33 , m_queryResultAvailable(false) | |
| 34 , m_queryResult(0) | |
| 28 { | 35 { |
| 29 m_queryId = context()->webContext()->createQueryEXT(); | 36 m_queryId = context()->webContext()->createQueryEXT(); |
| 30 } | 37 } |
| 31 | 38 |
| 39 void WebGLTimerQueryEXT::resetCachedResult() | |
|
David Yen
2015/10/05 17:23:16
We also need to reset the cache results when begin
| |
| 40 { | |
| 41 m_canUpdateAvailability = false; | |
| 42 m_queryResultAvailable = false; | |
| 43 m_queryResult = 0; | |
| 44 // When this is called, the implication is that we should start | |
| 45 // keeping track of whether we can update the cached availability | |
| 46 // and result. | |
| 47 registerTaskObserver(); | |
| 48 } | |
| 49 | |
| 50 void WebGLTimerQueryEXT::updateCachedResult(WebGraphicsContext3D* ctx) | |
| 51 { | |
| 52 if (m_queryResultAvailable) | |
| 53 return; | |
| 54 | |
| 55 if (!m_canUpdateAvailability) | |
| 56 return; | |
| 57 | |
| 58 if (!hasTarget()) | |
| 59 return; | |
| 60 | |
| 61 // We can only update the cached result when control returns to the browser. | |
| 62 m_canUpdateAvailability = false; | |
| 63 GLuint available = 0; | |
| 64 ctx->getQueryObjectuivEXT(object(), GL_QUERY_RESULT_AVAILABLE_EXT, &availabl e); | |
| 65 m_queryResultAvailable = !!available; | |
| 66 if (m_queryResultAvailable) { | |
| 67 GLuint64 result = 0; | |
| 68 ctx->getQueryObjectui64vEXT(object(), GL_QUERY_RESULT_EXT, &result); | |
| 69 m_queryResult = result; | |
| 70 unregisterTaskObserver(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 bool WebGLTimerQueryEXT::isQueryResultAvailable() | |
| 75 { | |
| 76 return m_queryResultAvailable; | |
| 77 } | |
| 78 | |
| 79 GLuint64 WebGLTimerQueryEXT::getQueryResult() | |
| 80 { | |
| 81 return m_queryResult; | |
| 82 } | |
| 83 | |
| 32 void WebGLTimerQueryEXT::deleteObjectImpl(WebGraphicsContext3D* context3d) | 84 void WebGLTimerQueryEXT::deleteObjectImpl(WebGraphicsContext3D* context3d) |
| 33 { | 85 { |
| 34 context3d->deleteQueryEXT(m_queryId); | 86 context3d->deleteQueryEXT(m_queryId); |
| 35 m_queryId = 0; | 87 m_queryId = 0; |
| 36 } | 88 } |
| 37 | 89 |
| 90 void WebGLTimerQueryEXT::registerTaskObserver() | |
| 91 { | |
| 92 if (!m_taskObserverRegistered) { | |
| 93 m_taskObserverRegistered = true; | |
| 94 Platform::current()->currentThread()->addTaskObserver(this); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void WebGLTimerQueryEXT::unregisterTaskObserver() | |
| 99 { | |
| 100 if (m_taskObserverRegistered) { | |
| 101 m_taskObserverRegistered = false; | |
| 102 Platform::current()->currentThread()->removeTaskObserver(this); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 void WebGLTimerQueryEXT::didProcessTask() | |
| 107 { | |
| 108 m_canUpdateAvailability = true; | |
| 109 } | |
| 110 | |
| 38 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |