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

Unified Diff: skia/ext/analysis_canvas_unittest.cc

Issue 12388095: cc: Merge GatherPixelRefs and AnalyzeInRect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compiler errors Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/analysis_canvas_unittest.cc
diff --git a/skia/ext/analysis_canvas_unittest.cc b/skia/ext/analysis_canvas_unittest.cc
index 17cfcb55c8b4558987cde3cc57323f48b00d052c..1623732b6a6fe530ad2656a62227129ee46e16ef 100644
--- a/skia/ext/analysis_canvas_unittest.cc
+++ b/skia/ext/analysis_canvas_unittest.cc
@@ -4,8 +4,8 @@
#include "base/compiler_specific.h"
#include "skia/ext/analysis_canvas.h"
-
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkShader.h"
namespace {
@@ -20,6 +20,45 @@ void transparentFill(skia::AnalysisCanvas& canvas) {
} // namespace
namespace skia {
+class TestPixelRef : public SkPixelRef {
+ public:
+ // Pure virtual implementation.
+ SkFlattenable::Factory getFactory() { return NULL; }
+ void* onLockPixels(SkColorTable**) { return NULL; }
+ void onUnlockPixels() {}
+};
+
+class TestLazyPixelRef : public LazyPixelRef {
+ public:
+ // Pure virtual implementation.
+ SkFlattenable::Factory getFactory() { return NULL; }
+ void* onLockPixels(SkColorTable**) { return NULL; }
+ void onUnlockPixels() {}
+ bool PrepareToDecode(const PrepareParams& params) { return true; }
+ void Decode() {}
+};
+
+class TestShader : public SkShader {
+ public:
+ TestShader(SkBitmap* bitmap)
+ : bitmap_(bitmap) {
+ }
+
+ SkShader::BitmapType asABitmap(SkBitmap* bitmap,
+ SkMatrix*, TileMode xy[2]) const {
+ *bitmap = *bitmap_;
+ return SkShader::kDefault_BitmapType;
+ }
+
+ // Pure virtual implementation.
+ void shadeSpan(int x, int y, SkPMColor[], int count) {}
+ SkFlattenable::Factory getFactory() { return NULL; }
+
+ private:
+
+ SkBitmap* bitmap_;
+};
+
TEST(AnalysisCanvasTest, EmptyCanvas) {
SkBitmap emptyBitmap;
emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
@@ -310,4 +349,104 @@ TEST(AnalysisCanvasTest, SaveLayerRestore) {
EXPECT_FALSE(canvas.isTransparent());
}
+TEST(AnalysisCanvasTest, LazyPixelRefs) {
+ // Set up two lazy and two non-lazy pixel refs and the corresponding bitmaps.
+ TestLazyPixelRef firstLazyPixelRef;
+ firstLazyPixelRef.setURI("lazy");
+ TestLazyPixelRef secondLazyPixelRef;
+ secondLazyPixelRef.setURI("lazy");
+
+ TestPixelRef firstNonLazyPixelRef;
+ TestPixelRef secondNonLazyPixelRef;
+ secondNonLazyPixelRef.setURI("notsolazy");
+
+ SkBitmap firstLazyBitmap;
+ firstLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ firstLazyBitmap.setPixelRef(&firstLazyPixelRef);
+ SkBitmap secondLazyBitmap;
+ secondLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ secondLazyBitmap.setPixelRef(&secondLazyPixelRef);
+
+ SkBitmap firstNonLazyBitmap;
+ firstNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ SkBitmap secondNonLazyBitmap;
+ secondNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ secondNonLazyBitmap.setPixelRef(&secondNonLazyPixelRef);
+
+ // The testcase starts here.
+ SkBitmap emptyBitmap;
+ emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ skia::AnalysisDevice device(emptyBitmap);
+ skia::AnalysisCanvas canvas(&device);
+
+ // This should be the first ref.
+ canvas.drawBitmap(firstLazyBitmap, 0, 0);
+ // The following will be ignored (non-lazy).
+ canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
+ canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
+ canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
+ canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
+ // This one will be ignored (already exists).
+ canvas.drawBitmap(firstLazyBitmap, 0, 0);
+ // This should be the second ref.
+ canvas.drawBitmap(secondLazyBitmap, 0, 0);
+
+ std::list<skia::LazyPixelRef*> pixelRefs;
+ canvas.consumeLazyPixelRefs(&pixelRefs);
+
+ // We expect to get only lazy pixel refs and only unique results.
+ EXPECT_EQ(pixelRefs.size(), 2u);
+ if (!pixelRefs.empty()) {
+ EXPECT_EQ(pixelRefs.front(),
+ static_cast<LazyPixelRef*>(&firstLazyPixelRef));
+ EXPECT_EQ(pixelRefs.back(),
+ static_cast<LazyPixelRef*>(&secondLazyPixelRef));
+ }
+}
+
+TEST(AnalysisCanvasTest, PixelRefsFromPaint) {
+ TestLazyPixelRef lazyPixelRef;
+ lazyPixelRef.setURI("lazy");
+
+ TestPixelRef nonLazyPixelRef;
+ nonLazyPixelRef.setURI("notsolazy");
+
+ SkBitmap lazyBitmap;
+ lazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ lazyBitmap.setPixelRef(&lazyPixelRef);
+
+ SkBitmap nonLazyBitmap;
+ nonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ nonLazyBitmap.setPixelRef(&nonLazyPixelRef);
+
+ TestShader lazyShader(&lazyBitmap);
+ TestShader nonLazyShader(&nonLazyBitmap);
+
+ SkPaint lazyPaint;
+ lazyPaint.setShader(&lazyShader);
+ SkPaint nonLazyPaint;
+ nonLazyPaint.setShader(&nonLazyShader);
+
+ SkBitmap emptyBitmap;
+ emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
+ skia::AnalysisDevice device(emptyBitmap);
+ skia::AnalysisCanvas canvas(&device);
+
+ canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
+ canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
+ canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
+ canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
+ canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
+ canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
+
+ std::list<skia::LazyPixelRef*> pixelRefs;
+ canvas.consumeLazyPixelRefs(&pixelRefs);
+
+ // We expect to get only lazy pixel refs and only unique results.
+ EXPECT_EQ(pixelRefs.size(), 1u);
+ if (!pixelRefs.empty()) {
+ EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&lazyPixelRef));
+ }
+}
+
} // namespace skia
« no previous file with comments | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698