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

Unified Diff: tests/ImageTest.cpp

Issue 1262923003: cache private readback for gpu-images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address items in #4 Created 5 years, 4 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 | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageTest.cpp
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index ba071bb1f75ca6f878eba49e728fcc3edcb454ea..f5e1abc0a4ad34a61eaf12e1982c4d4a75a80531 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -249,3 +249,65 @@ DEF_TEST(image_newfrombitmap, reporter) {
REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess);
}
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#if SK_SUPPORT_GPU
+
+static SkImage* make_gpu_image(GrContext* ctx, const SkImageInfo& info, SkColor color) {
+ const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted;
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, budgeted, info, 0));
+ surface->getCanvas()->drawColor(color);
+ return surface->newImageSnapshot();
+}
+
+#include "SkBitmapCache.h"
+
+/*
+ * This tests the caching (and preemptive purge) of the raster equivalent of a gpu-image.
+ * We cache it for performance when drawing into a raster surface.
+ *
+ * A cleaner test would know if each drawImage call triggered a read-back from the gpu,
+ * but we don't have that facility (at the moment) so we use a little internal knowledge
+ * of *how* the raster version is cached, and look for that.
+ */
+DEF_GPUTEST(SkImage_Gpu2Cpu, reporter, factory) {
+ GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
+ if (!ctx) {
+ REPORTER_ASSERT(reporter, false);
+ return;
+ }
+
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
+ SkAutoTUnref<SkImage> image(make_gpu_image(ctx, info, SK_ColorRED));
+ const uint32_t uniqueID = image->uniqueID();
+
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
+
+ // now we can test drawing a gpu-backed image into a cpu-backed surface
+
+ {
+ SkBitmap cachedBitmap;
+ REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap));
+ }
+
+ surface->getCanvas()->drawImage(image, 0, 0);
+ {
+ SkBitmap cachedBitmap;
+ if (SkBitmapCache::Find(uniqueID, &cachedBitmap)) {
+ REPORTER_ASSERT(reporter, cachedBitmap.getGenerationID() == uniqueID);
+ REPORTER_ASSERT(reporter, cachedBitmap.isImmutable());
+ REPORTER_ASSERT(reporter, cachedBitmap.getPixels());
+ } else {
+ // unexpected, but not really a bug, since the cache is global and this test may be
+ // run w/ other threads competing for its budget.
+ SkDebugf("SkImage_Gpu2Cpu : cachedBitmap was already purged\n");
+ }
+ }
+
+ image.reset(nullptr);
+ {
+ SkBitmap cachedBitmap;
+ REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap));
+ }
+}
+#endif
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698