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/DeferredCanvasTest.cpp

Issue 355193006: stop calling SkCanvas::getDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: guard gpu code in no-gpu build Created 6 years, 6 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/utils/SkDeferredCanvas.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DeferredCanvasTest.cpp
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 8aaeaed5f3be9639f93da21b9965aa600bd770ab..cc8a1f2c53b4f0ce0ec81a5ff9f1bac4c7a43fb7 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -49,23 +49,6 @@ static SkPMColor read_pixel(SkSurface* surface, int x, int y) {
return pixel;
}
-static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) {
- SkBitmap store;
-
- SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
- SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
-
- canvas->clear(0x00000000);
-
- // verify that the clear() was deferred
- REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0));
-
- SkBitmap accessed = canvas->getDevice()->accessBitmap(false);
-
- // verify that clear was executed
- REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0));
-}
-
class MockSurface : public SkSurface_Base {
public:
MockSurface(int width, int height) : SkSurface_Base(width, height) {
@@ -681,13 +664,19 @@ static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter)
}
-typedef void* PixelPtr;
+typedef const void* PixelPtr;
// Returns an opaque pointer which, either points to a GrTexture or RAM pixel
// buffer. Used to test pointer equality do determine whether a surface points
// to the same pixel data storage as before.
-static PixelPtr getSurfacePixelPtr(SkSurface* surface, bool useGpu) {
- return useGpu ? surface->getCanvas()->getDevice()->accessBitmap(false).getTexture() :
- surface->getCanvas()->getDevice()->accessBitmap(false).getPixels();
+static PixelPtr get_surface_ptr(SkSurface* surface, bool useGpu) {
+#if SK_SUPPORT_GPU
+ if (useGpu) {
+ return surface->getCanvas()->internal_private_accessTopLayerRenderTarget()->asTexture();
+ } else
+#endif
+ {
+ return surface->peekPixels(NULL, NULL);
+ }
}
static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFactory* factory) {
@@ -715,7 +704,7 @@ static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac
SkImage* image1 = canvas->newImageSnapshot();
SkAutoTUnref<SkImage> aur_i1(image1);
- PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels1 = get_surface_ptr(surface, useGpu);
// The following clear would normally trigger a copy on write, but
// it won't because rendering is deferred.
canvas->clear(SK_ColorBLACK);
@@ -733,7 +722,7 @@ static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac
REPORTER_ASSERT(reporter, image1->uniqueID() != image3->uniqueID());
// Verify that backing store is now a different buffer because of copy on
// write
- PixelPtr pixels2 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels2 = get_surface_ptr(surface, useGpu);
REPORTER_ASSERT(reporter, pixels1 != pixels2);
// Verify copy-on write with a draw operation that gets deferred by
// the in order draw buffer.
@@ -742,17 +731,17 @@ static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac
SkImage* image4 = canvas->newImageSnapshot(); // implicit flush
SkAutoTUnref<SkImage> aur_i4(image4);
REPORTER_ASSERT(reporter, image4->uniqueID() != image3->uniqueID());
- PixelPtr pixels3 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels3 = get_surface_ptr(surface, useGpu);
REPORTER_ASSERT(reporter, pixels2 != pixels3);
// Verify that a direct canvas flush with a pending draw does not trigger
// a copy on write when the surface is not sharing its buffer with an
// SkImage.
canvas->clear(SK_ColorWHITE);
canvas->flush();
- PixelPtr pixels4 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels4 = get_surface_ptr(surface, useGpu);
canvas->drawPaint(paint);
canvas->flush();
- PixelPtr pixels5 = getSurfacePixelPtr(surface, useGpu);
+ PixelPtr pixels5 = get_surface_ptr(surface, useGpu);
REPORTER_ASSERT(reporter, pixels4 == pixels5);
}
@@ -782,21 +771,21 @@ static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext
SkASSERT(NULL != alternateSurface);
SkAutoTUnref<SkSurface> aur1(surface);
SkAutoTUnref<SkSurface> aur2(alternateSurface);
- PixelPtr pixels1 = getSurfacePixelPtr(surface, useGpu);
- PixelPtr pixels2 = getSurfacePixelPtr(alternateSurface, useGpu);
+ PixelPtr pixels1 = get_surface_ptr(surface, useGpu);
+ PixelPtr pixels2 = get_surface_ptr(alternateSurface, useGpu);
SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface));
SkAutoTUnref<SkImage> image1(canvas->newImageSnapshot());
canvas->setSurface(alternateSurface);
SkAutoTUnref<SkImage> image2(canvas->newImageSnapshot());
REPORTER_ASSERT(reporter, image1->uniqueID() != image2->uniqueID());
// Verify that none of the above operations triggered a surface copy on write.
- REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1);
- REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) == pixels2);
+ REPORTER_ASSERT(reporter, get_surface_ptr(surface, useGpu) == pixels1);
+ REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) == pixels2);
// Verify that a flushed draw command will trigger a copy on write on alternateSurface.
canvas->clear(SK_ColorWHITE);
canvas->flush();
- REPORTER_ASSERT(reporter, getSurfacePixelPtr(surface, useGpu) == pixels1);
- REPORTER_ASSERT(reporter, getSurfacePixelPtr(alternateSurface, useGpu) != pixels2);
+ REPORTER_ASSERT(reporter, get_surface_ptr(surface, useGpu) == pixels1);
+ REPORTER_ASSERT(reporter, get_surface_ptr(alternateSurface, useGpu) != pixels2);
}
static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) {
@@ -821,7 +810,6 @@ static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
}
DEF_TEST(DeferredCanvas_CPU, reporter) {
- TestDeferredCanvasBitmapAccess(reporter);
TestDeferredCanvasFlush(reporter);
TestDeferredCanvasSilentFlush(reporter);
TestDeferredCanvasFreshFrame(reporter);
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698