diff options
Diffstat (limited to 'libs/hwui')
| -rw-r--r-- | libs/hwui/Caches.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/Dither.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/Extensions.h | 4 | ||||
| -rw-r--r-- | libs/hwui/GradientCache.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/Query.h | 152 |
5 files changed, 159 insertions, 3 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 74aeddb..31b0f6a 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -145,7 +145,7 @@ void Caches::initStaticProperties() { gpuPixelBuffersEnabled = false; // OpenGL ES 3.0+ specific features - if (mExtensions.getMajorGlVersion() >= 3) { + if (mExtensions.hasPixelBufferObjects()) { char property[PROPERTY_VALUE_MAX]; if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) { gpuPixelBuffersEnabled = !strcmp(property, "true"); diff --git a/libs/hwui/Dither.cpp b/libs/hwui/Dither.cpp index 649a7bc..77006a4 100644 --- a/libs/hwui/Dither.cpp +++ b/libs/hwui/Dither.cpp @@ -29,7 +29,7 @@ Dither::Dither(): mCaches(NULL), mInitialized(false), mDitherTexture(0) { void Dither::bindDitherTexture() { if (!mInitialized) { - bool useFloatTexture = Extensions::getInstance().getMajorGlVersion() >= 3; + bool useFloatTexture = Extensions::getInstance().hasFloatTextures(); glGenTextures(1, &mDitherTexture); mCaches->bindTexture(mDitherTexture); diff --git a/libs/hwui/Extensions.h b/libs/hwui/Extensions.h index 3112244..5e574a6 100644 --- a/libs/hwui/Extensions.h +++ b/libs/hwui/Extensions.h @@ -42,6 +42,10 @@ public: inline bool has4BitStencil() const { return mHas4BitStencil; } inline bool hasNvSystemTime() const { return mHasNvSystemTime; } + inline bool hasPixelBufferObjects() const { return mVersionMajor >= 3; } + inline bool hasOcclusionQueries() const { return mVersionMajor >= 3; } + inline bool hasFloatTextures() const { return mVersionMajor >= 3; } + inline int getMajorGlVersion() const { return mVersionMajor; } inline int getMinorGlVersion() const { return mVersionMinor; } diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp index 1815bff..0916942 100644 --- a/libs/hwui/GradientCache.cpp +++ b/libs/hwui/GradientCache.cpp @@ -78,7 +78,7 @@ GradientCache::GradientCache(): mCache.setOnEntryRemovedListener(this); const Extensions& extensions = Extensions::getInstance(); - mUseFloatTexture = extensions.getMajorGlVersion() >= 3; + mUseFloatTexture = extensions.hasFloatTextures(); mHasNpot = extensions.hasNPot(); } diff --git a/libs/hwui/Query.h b/libs/hwui/Query.h new file mode 100644 index 0000000..e25b16b --- /dev/null +++ b/libs/hwui/Query.h @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HWUI_QUERY_H +#define ANDROID_HWUI_QUERY_H + +#include <GLES3/gl3.h> + +#include "Extensions.h" + +namespace android { +namespace uirenderer { + +/** + * A Query instance can be used to perform occlusion queries. If the device + * does not support occlusion queries, the result of a query will always be + * 0 and the result will always be marked available. + * + * To run an occlusion query successfully, you must start end end the query: + * + * Query query; + * query.begin(); + * // execute OpenGL calls + * query.end(); + * GLuint result = query.getResult(); + */ +class Query { +public: + /** + * Possible query targets. + */ + enum Target { + /** + * Indicates if any sample passed the depth & stencil tests. + */ + kTargetSamples = GL_ANY_SAMPLES_PASSED, + /** + * Indicates if any sample passed the depth & stencil tests. + * The implementation may choose to use a less precise version + * of the test, potentially resulting in false positives. + */ + kTargetConservativeSamples = GL_ANY_SAMPLES_PASSED_CONSERVATIVE, + }; + + /** + * Creates a new query with the specified target. The default + * target is kTargetSamples (of GL_ANY_SAMPLES_PASSED in OpenGL.) + */ + Query(Target target = kTargetSamples): mActive(false), mTarget(target), + mCanQuery(Extensions::getInstance().hasOcclusionQueries()), + mQuery(0) { + } + + ~Query() { + if (mQuery) { + glDeleteQueries(1, &mQuery); + } + } + + /** + * Begins the query. If the query has already begun or if the device + * does not support occlusion queries, calling this method as no effect. + * After calling this method successfully, the query is marked active. + */ + void begin() { + if (!mActive && mCanQuery) { + if (!mQuery) { + glGenQueries(1, &mQuery); + } + + glBeginQuery(mTarget, mQuery); + mActive = true; + } + } + + /** + * Ends the query. If the query has already begun or if the device + * does not support occlusion queries, calling this method as no effect. + * After calling this method successfully, the query is marked inactive. + */ + void end() { + if (mQuery && mActive) { + glEndQuery(mTarget); + mActive = false; + } + } + + /** + * Returns true if the query is active, false otherwise. + */ + bool isActive() { + return mActive; + } + + /** + * Returns true if the result of the query is available, + * false otherwise. Calling getResult() before the result + * is available may result in the calling thread being blocked. + * If the device does not support queries, this method always + * returns true. + */ + bool isResultAvailable() { + if (!mQuery) return true; + + GLuint result; + glGetQueryObjectuiv(mQuery, GL_QUERY_RESULT_AVAILABLE, &result); + return result == GL_TRUE; + } + + /** + * Returns the result of the query. If the device does not + * support queries this method will return 0. + * + * Calling this method implicitely calls end() if the query + * is currently active. + */ + GLuint getResult() { + if (!mQuery) return 0; + + end(); + + GLuint result; + glGetQueryObjectuiv(mQuery, GL_QUERY_RESULT, &result); + return result; + } + + +private: + bool mActive; + GLenum mTarget; + bool mCanQuery; + GLuint mQuery; + +}; // class Query + +}; // namespace uirenderer +}; // namespace android + +#endif // ANDROID_HWUI_QUERY_H |
