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

Side by Side Diff: tests/PixelRefTest.cpp

Issue 108723003: Revert "Revert "PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix warnings, update SkImageRef_ashmem Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « tests/PictureTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Test.h" 1 #include "Test.h"
2 #include "TestClassDef.h" 2 #include "TestClassDef.h"
3 3
4 #include "SkPixelRef.h" 4 #include "SkPixelRef.h"
5 #include "SkMallocPixelRef.h" 5 #include "SkMallocPixelRef.h"
6 6
7 namespace { 7 namespace {
8 8
9 class TestListener : public SkPixelRef::GenIDChangeListener { 9 class TestListener : public SkPixelRef::GenIDChangeListener {
10 public: 10 public:
11 explicit TestListener(int* ptr) : fPtr(ptr) {} 11 explicit TestListener(int* ptr) : fPtr(ptr) {}
12 void onChange() SK_OVERRIDE { (*fPtr)++; } 12 void onChange() SK_OVERRIDE { (*fPtr)++; }
13 private: 13 private:
14 int* fPtr; 14 int* fPtr;
15 }; 15 };
16 16
17 } // namespace 17 } // namespace
18 18
19 DEF_TEST(PixelRef_GenIDChange, r) { 19 DEF_TEST(PixelRef_GenIDChange, r) {
20 SkMallocPixelRef pixelRef(NULL, 0, NULL); // We don't really care about the pixels here. 20 SkImageInfo info = { 10, 10, kPMColor_SkColorType, kPremul_SkAlphaType };
21
22 SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NUL L));
21 23
22 // Register a listener. 24 // Register a listener.
23 int count = 0; 25 int count = 0;
24 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); 26 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count)));
25 REPORTER_ASSERT(r, 0 == count); 27 REPORTER_ASSERT(r, 0 == count);
26 28
27 // No one has looked at our pixelRef's generation ID, so invalidating it doe sn't make sense. 29 // No one has looked at our pixelRef's generation ID, so invalidating it doe sn't make sense.
28 // (An SkPixelRef tree falls in the forest but there's nobody around to hear it. Do we care?) 30 // (An SkPixelRef tree falls in the forest but there's nobody around to hear it. Do we care?)
29 pixelRef.notifyPixelsChanged(); 31 pixelRef->notifyPixelsChanged();
30 REPORTER_ASSERT(r, 0 == count); 32 REPORTER_ASSERT(r, 0 == count);
31 33
32 // Force the generation ID to be calculated. 34 // Force the generation ID to be calculated.
33 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); 35 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
34 36
35 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi s is a no-op. 37 // Our listener was dropped in the first call to notifyPixelsChanged(). Thi s is a no-op.
36 pixelRef.notifyPixelsChanged(); 38 pixelRef->notifyPixelsChanged();
37 REPORTER_ASSERT(r, 0 == count); 39 REPORTER_ASSERT(r, 0 == count);
38 40
39 // Force the generation ID to be recalculated, then add a listener. 41 // Force the generation ID to be recalculated, then add a listener.
40 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); 42 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
41 pixelRef.addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count))); 43 pixelRef->addGenIDChangeListener(SkNEW_ARGS(TestListener, (&count)));
42 pixelRef.notifyPixelsChanged(); 44 pixelRef->notifyPixelsChanged();
43 REPORTER_ASSERT(r, 1 == count); 45 REPORTER_ASSERT(r, 1 == count);
44 46
45 // Quick check that NULL is safe. 47 // Quick check that NULL is safe.
46 REPORTER_ASSERT(r, 0 != pixelRef.getGenerationID()); 48 REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
47 pixelRef.addGenIDChangeListener(NULL); 49 pixelRef->addGenIDChangeListener(NULL);
48 pixelRef.notifyPixelsChanged(); 50 pixelRef->notifyPixelsChanged();
49 } 51 }
OLDNEW
« no previous file with comments | « tests/PictureTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698