Index: src/gpu/gl/GrGLCaps.h |
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h |
index ccf04fd7ba5a3d668ef5d2671d0defc5af6ea6b6..00f735b152b0a1087c8907ce13c76cd7d8cfbe59 100644 |
--- a/src/gpu/gl/GrGLCaps.h |
+++ b/src/gpu/gl/GrGLCaps.h |
@@ -13,6 +13,7 @@ |
#include "GrGLStencilBuffer.h" |
#include "SkTArray.h" |
#include "SkTDArray.h" |
+#include "SkTDynamicHash.h" |
class GrGLContextInfo; |
@@ -253,7 +254,8 @@ public: |
/// Does ReadPixels support the provided format/type combo? |
bool readPixelsSupported(const GrGLInterface* intf, |
GrGLenum format, |
- GrGLenum type) const; |
+ GrGLenum type, |
+ GrGLenum currFboFormat) const; |
bool isCoreProfile() const { return fIsCoreProfile; } |
@@ -324,6 +326,10 @@ private: |
void initConfigRenderableTable(const GrGLContextInfo&); |
void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*); |
+ bool doReadPixelsSupported(const GrGLInterface* intf, |
+ GrGLenum format, |
+ GrGLenum type) const; |
+ |
// tracks configs that have been verified to pass the FBO completeness when |
// used as a color attachment |
VerifiedColorConfigs fVerifiedColorConfigs; |
@@ -364,6 +370,85 @@ private: |
bool fFullClearIsFree : 1; |
bool fDropsTileOnZeroDivide : 1; |
+ struct ReadPixelsSupportedFormatsKey { |
+ GrGLenum fFormat; |
+ GrGLenum fType; |
+ GrGLenum fFboFormat; |
+ |
+ bool operator==(const ReadPixelsSupportedFormatsKey& rhs) const { |
+ return fFormat == rhs.fFormat |
+ && fType == rhs.fType |
+ && fFboFormat == rhs.fFboFormat; |
+ } |
+ }; |
+ |
+ class ReadPixelsSupportedFormats { |
+ public: |
+ ReadPixelsSupportedFormats(ReadPixelsSupportedFormatsKey key, |
+ bool value) |
+ :fKey(key), fValue(value) { |
+ } |
+ |
+ static const ReadPixelsSupportedFormatsKey& GetKey(const ReadPixelsSupportedFormats& element) { |
+ return element.fKey; |
+ } |
+ static uint32_t Hash(const ReadPixelsSupportedFormatsKey&); |
+ |
+ bool value() const { return fValue; } |
+ private: |
+ ReadPixelsSupportedFormatsKey fKey; |
+ bool fValue; |
+ }; |
+ |
+ template <typename T, |
+ typename Key, |
+ typename Traits = T, |
+ int kGrowPercent = 75> |
+ class DynamicHashCache { |
+ public: |
+ DynamicHashCache(): fDict(), fValues() { } |
Justin Novosad
2014/07/03 18:57:44
No need to explicitly call default constructors
Rémi Piotaix
2014/07/03 20:38:27
Done.
|
+ |
+ bool has(Key& key) const { |
+ return NULL != find(key); |
+ } |
+ |
+ T* find(Key& key) const { |
+ return fDict.find(key); |
+ } |
+ |
+ // if element already in cache, return immediately the cached value |
+ T& put(T& element) { |
+ Key key = Traits::GetKey(element); |
+ if(has(key)) |
+ return *find(key); |
+ |
+ T& e = fValues.push_back(element); |
+ |
+ fDict.add(&e); |
+ |
+ return e; |
+ } |
+ |
+ int size() { |
+ return fValues.count(); |
+ } |
+ |
+ void clear() { |
+ while(fValues.count()) { |
Justin Novosad
2014/07/03 18:57:44
Looping should not be necessary here. SkTDynamicHa
Rémi Piotaix
2014/07/03 20:38:27
Done.
|
+ T& element = fValues.back(); |
+ |
+ fDict.remove(Traits::GetKey(element)); |
+ |
+ fValues.pop_back(); |
+ } |
+ } |
+ private: |
+ SkTDynamicHash<T, Key, Traits, kGrowPercent> fDict; |
+ SkTArray<T, true> fValues; |
+ }; |
+ |
+ mutable DynamicHashCache<ReadPixelsSupportedFormats, ReadPixelsSupportedFormatsKey> fReadPixelsSupportedCache; |
Justin Novosad
2014/07/03 18:57:44
Why doe this need to be mutable?
Rémi Piotaix
2014/07/03 20:38:27
Because readPixelsSupported() is const and Dynamic
Justin Novosad
2014/07/04 14:42:27
Ok. I guess cached results are usually an acceptab
|
+ |
typedef GrDrawTargetCaps INHERITED; |
}; |