aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/src/gr_unittests.cpp
diff options
context:
space:
mode:
authorGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-31 21:26:24 +0000
committerGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-31 21:26:24 +0000
commitf93e717c7f7ca679a80acbfda6a34013ae1e2b8d (patch)
tree974540f0c4ebc4c9fdf547131ab9295a2e2572f3 /gpu/src/gr_unittests.cpp
parent772813afa62706bd97024430b4505afe4258687a (diff)
Refactoring the GrGpuGLShaders2 into 2 classes: GrGpuGLShaders
and GrGLProgram. The change also contains stubs and placeholders for GrEffect (work in progress), which will extend shader and rendering capabilities in Ganesh. The hash keys for the program cache table have been modified to be able to accomodate variable-length keys, which will be required for GrEffect support. Code review: http://codereview.appspot.com/4309045/ git-svn-id: http://skia.googlecode.com/svn/trunk@1031 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/gr_unittests.cpp')
-rw-r--r--gpu/src/gr_unittests.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/gpu/src/gr_unittests.cpp b/gpu/src/gr_unittests.cpp
index 16fd9dc95d..ef6b1e77dc 100644
--- a/gpu/src/gr_unittests.cpp
+++ b/gpu/src/gr_unittests.cpp
@@ -21,6 +21,7 @@
#include "GrMatrix.h"
#include "GrRedBlackTree.h"
#include "GrPath.h"
+#include "GrBinHashKey.h"
static void dump(const GrTDArray<int>& array) {
#if 0
@@ -74,9 +75,84 @@ static void test_bsearch() {
}
}
+static void test_binHashKey()
+{
+ const char* testStringA = "abcdA";
+ const char* testStringB = "abcdB";
+ enum {
+ kDataLenUsedForKey = 5
+ };
+
+ class Entry {
+ // bogus empty class
+ };
+
+ typedef GrBinHashKey<Entry, kDataLenUsedForKey> KeyType;
+
+ KeyType keyA;
+ int passCnt = 0;
+ while (keyA.doPass()) {
+ ++passCnt;
+ keyA.keyData(reinterpret_cast<const uint8_t*>(testStringA), kDataLenUsedForKey);
+ }
+ GrAssert(passCnt == 1); //We expect the static allocation to suffice
+ GrBinHashKey<Entry, kDataLenUsedForKey-1> keyBust;
+ passCnt = 0;
+ while (keyBust.doPass()) {
+ ++passCnt;
+ // Exceed static storage by 1
+ keyBust.keyData(reinterpret_cast<const uint8_t*>(testStringA), kDataLenUsedForKey);
+ }
+ GrAssert(passCnt == 2); //We expect dynamic allocation to be necessary
+ GrAssert(keyA.getHash() == keyBust.getHash());
+
+ // Test that adding keyData in chunks gives
+ // the same hash as with one chunk
+ KeyType keyA2;
+ while (keyA2.doPass()) {
+ keyA2.keyData(reinterpret_cast<const uint8_t*>(testStringA), 2);
+ keyA2.keyData(&reinterpret_cast<const uint8_t*>(testStringA)[2], kDataLenUsedForKey-2);
+ }
+ GrAssert(keyA.getHash() == keyA2.getHash());
+
+ KeyType keyB;
+ while (keyB.doPass()){
+ keyB.keyData(reinterpret_cast<const uint8_t*>(testStringB), kDataLenUsedForKey);
+ }
+ GrAssert(keyA.compare(keyB) < 0);
+ GrAssert(keyA.compare(keyA2) == 0);
+
+ //Test ownership tranfer and copying
+ keyB.copyAndTakeOwnership(keyA);
+ GrAssert(keyA.fIsValid == false);
+ GrAssert(keyB.fIsValid);
+ GrAssert(keyB.getHash() == keyA2.getHash());
+ GrAssert(keyB.compare(keyA2) == 0);
+ keyA.deepCopyFrom(keyB);
+ GrAssert(keyA.fIsValid);
+ GrAssert(keyB.fIsValid);
+ GrAssert(keyA.getHash() == keyA2.getHash());
+ GrAssert(keyA.compare(keyA2) == 0);
+
+ //Test ownership tranfer and copying with key on heap
+ GrBinHashKey<Entry, kDataLenUsedForKey-1> keyBust2;
+ keyBust2.deepCopyFrom(keyBust);
+ GrAssert(keyBust.fIsValid);
+ GrAssert(keyBust2.fIsValid);
+ GrAssert(keyBust.getHash() == keyBust2.getHash());
+ GrAssert(keyBust.compare(keyBust2) == 0);
+ GrBinHashKey<Entry, kDataLenUsedForKey-1> keyBust3;
+ keyBust3.deepCopyFrom(keyBust);
+ GrAssert(keyBust.fIsValid == false);
+ GrAssert(keyBust3.fIsValid);
+ GrAssert(keyBust3.getHash() == keyBust2.getHash());
+ GrAssert(keyBust3.compare(keyBust2) == 0);
+}
+
void gr_run_unittests() {
test_tdarray();
test_bsearch();
+ test_binHashKey();
GrMatrix::UnitTest();
GrRedBlackTree<int>::UnitTest();
GrPath::ConvexUnitTest();