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

Unified Diff: tests/WritePixelsTest.cpp

Issue 1448873002: Generate list of GPU contexts outside tests (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-01-gpu-test-context-support
Patch Set: make blurtest for all rendering contexts Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/TextBlobCacheTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/WritePixelsTest.cpp
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index c4010b711976729c74cdac27dac19ea0665b7e0f..6d672f7d16cdbcebf4ecd91b3329e93cc753e472 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -14,13 +14,11 @@
#include "sk_tool_utils.h"
#if SK_SUPPORT_GPU
-#include "GrContextFactory.h"
-#include "SkGpuDevice.h"
-#else
-class GrContext;
-class GrContextFactory;
+#include "GrContext.h"
#endif
+#include <initializer_list>
+
static const int DEV_W = 100, DEV_H = 100;
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
@@ -254,28 +252,6 @@ static bool check_write(skiatest::Reporter* reporter, SkCanvas* canvas, const Sk
return true;
}
-enum DevType {
- kRaster_DevType,
-#if SK_SUPPORT_GPU
- kGpu_BottomLeft_DevType,
- kGpu_TopLeft_DevType,
-#endif
-};
-
-struct CanvasConfig {
- DevType fDevType;
- bool fTightRowBytes;
-};
-
-static const CanvasConfig gCanvasConfigs[] = {
- {kRaster_DevType, true},
- {kRaster_DevType, false},
-#if SK_SUPPORT_GPU
- {kGpu_BottomLeft_DevType, true}, // row bytes has no meaning on gpu devices
- {kGpu_TopLeft_DevType, true}, // row bytes has no meaning on gpu devices
-#endif
-};
-
#include "SkMallocPixelRef.h"
// This is a tricky pattern, because we have to setConfig+rowBytes AND specify
@@ -295,36 +271,6 @@ static void free_pixels(void* pixels, void* ctx) {
sk_free(pixels);
}
-static SkSurface* create_surface(const CanvasConfig& c, GrContext* grCtx) {
- SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
- switch (c.fDevType) {
- case kRaster_DevType: {
- const size_t rowBytes = c.fTightRowBytes ? info.minRowBytes() : 4 * DEV_W + 100;
- const size_t size = info.getSafeSize(rowBytes);
- void* pixels = sk_malloc_throw(size);
- // if rowBytes isn't tight then set the padding to a known value
- if (!c.fTightRowBytes) {
- memset(pixels, DEV_PAD, size);
- }
- return SkSurface::NewRasterDirectReleaseProc(info, pixels, rowBytes, free_pixels, nullptr);
- }
-#if SK_SUPPORT_GPU
- case kGpu_BottomLeft_DevType:
- case kGpu_TopLeft_DevType:
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = DEV_W;
- desc.fHeight = DEV_H;
- desc.fConfig = kSkia8888_GrPixelConfig;
- desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ?
- kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
- SkAutoTUnref<GrTexture> texture(grCtx->textureProvider()->createTexture(desc, false));
- return SkSurface::NewRenderTargetDirect(texture->asRenderTarget());
-#endif
- }
- return nullptr;
-}
-
static bool setup_bitmap(SkBitmap* bm, SkColorType ct, SkAlphaType at, int w, int h, int tightRB) {
size_t rowBytes = tightRB ? 0 : 4 * w + 60;
SkImageInfo info = SkImageInfo::Make(w, h, ct, at);
@@ -346,7 +292,7 @@ static void call_writepixels(SkCanvas* canvas) {
canvas->writePixels(info, &pixel, sizeof(SkPMColor), 0, 0);
}
-static void test_surface_genid(skiatest::Reporter* reporter) {
+DEF_TEST(WritePixelsSurfaceGenID, reporter) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
uint32_t genID1 = surface->generationID();
@@ -355,11 +301,7 @@ static void test_surface_genid(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, genID1 != genID2);
}
-DEF_GPUTEST(WritePixels, reporter, factory) {
- test_surface_genid(reporter);
-
- SkCanvas canvas;
-
+static void test_write_pixels(skiatest::Reporter* reporter, SkSurface* surface) {
const SkIRect testRects[] = {
// entire thing
DEV_RECT,
@@ -407,72 +349,73 @@ DEF_GPUTEST(WritePixels, reporter, factory) {
SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
};
- for (size_t i = 0; i < SK_ARRAY_COUNT(gCanvasConfigs); ++i) {
- int glCtxTypeCnt = 1;
-#if SK_SUPPORT_GPU
- bool isGPUDevice = kGpu_TopLeft_DevType == gCanvasConfigs[i].fDevType ||
- kGpu_BottomLeft_DevType == gCanvasConfigs[i].fDevType;
- if (isGPUDevice) {
- glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
- }
-#endif
- for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
- GrContext* context = nullptr;
-#if SK_SUPPORT_GPU
- if (isGPUDevice) {
- GrContextFactory::GLContextType type =
- static_cast<GrContextFactory::GLContextType>(glCtxType);
- if (!GrContextFactory::IsRenderingGLContext(type)) {
- continue;
- }
- context = factory->get(type);
- if (nullptr == context) {
- continue;
- }
- }
-#endif
+ SkCanvas& canvas = *surface->getCanvas();
- SkAutoTUnref<SkSurface> surface(create_surface(gCanvasConfigs[i], context));
- SkCanvas& canvas = *surface->getCanvas();
-
- static const struct {
- SkColorType fColorType;
- SkAlphaType fAlphaType;
- } gSrcConfigs[] = {
- { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
- { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
- { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
- { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
- };
- for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) {
- const SkIRect& rect = testRects[r];
- for (int tightBmp = 0; tightBmp < 2; ++tightBmp) {
- for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) {
- const SkColorType ct = gSrcConfigs[c].fColorType;
- const SkAlphaType at = gSrcConfigs[c].fAlphaType;
-
- fill_canvas(&canvas);
- SkBitmap bmp;
- REPORTER_ASSERT(reporter, setup_bitmap(&bmp, ct, at, rect.width(),
- rect.height(), SkToBool(tightBmp)));
- uint32_t idBefore = surface->generationID();
-
- // sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, rect.fTop, ct, at);
- canvas.writePixels(bmp, rect.fLeft, rect.fTop);
-
- uint32_t idAfter = surface->generationID();
- REPORTER_ASSERT(reporter, check_write(reporter, &canvas, bmp,
- rect.fLeft, rect.fTop));
-
- // we should change the genID iff pixels were actually written.
- SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceSize());
- SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.fTop,
- bmp.width(), bmp.height());
- bool intersects = SkIRect::Intersects(canvasRect, writeRect) ;
- REPORTER_ASSERT(reporter, intersects == (idBefore != idAfter));
- }
- }
+ static const struct {
+ SkColorType fColorType;
+ SkAlphaType fAlphaType;
+ } gSrcConfigs[] = {
+ { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
+ { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
+ { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
+ { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
+ };
+ for (size_t r = 0; r < SK_ARRAY_COUNT(testRects); ++r) {
+ const SkIRect& rect = testRects[r];
+ for (int tightBmp = 0; tightBmp < 2; ++tightBmp) {
+ for (size_t c = 0; c < SK_ARRAY_COUNT(gSrcConfigs); ++c) {
+ const SkColorType ct = gSrcConfigs[c].fColorType;
+ const SkAlphaType at = gSrcConfigs[c].fAlphaType;
+
+ fill_canvas(&canvas);
+ SkBitmap bmp;
+ REPORTER_ASSERT(reporter, setup_bitmap(&bmp, ct, at, rect.width(),
+ rect.height(), SkToBool(tightBmp)));
+ uint32_t idBefore = surface->generationID();
+
+ // sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, rect.fTop, ct, at);
+ canvas.writePixels(bmp, rect.fLeft, rect.fTop);
+
+ uint32_t idAfter = surface->generationID();
+ REPORTER_ASSERT(reporter, check_write(reporter, &canvas, bmp,
+ rect.fLeft, rect.fTop));
+
+ // we should change the genID iff pixels were actually written.
+ SkIRect canvasRect = SkIRect::MakeSize(canvas.getDeviceSize());
+ SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.fTop,
+ bmp.width(), bmp.height());
+ bool intersects = SkIRect::Intersects(canvasRect, writeRect) ;
+ REPORTER_ASSERT(reporter, intersects == (idBefore != idAfter));
}
}
}
}
+DEF_TEST(WritePixels, reporter) {
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
+ for (auto& tightRowBytes : { true, false }) {
+ const size_t rowBytes = tightRowBytes ? info.minRowBytes() : 4 * DEV_W + 100;
+ const size_t size = info.getSafeSize(rowBytes);
+ void* pixels = sk_malloc_throw(size);
+ // if rowBytes isn't tight then set the padding to a known value
+ if (!tightRowBytes) {
+ memset(pixels, DEV_PAD, size);
+ }
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirectReleaseProc(info, pixels, rowBytes, free_pixels, nullptr));
+ test_write_pixels(reporter, surface);
+ }
+}
+#if SK_SUPPORT_GPU
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, context) {
+ for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = DEV_W;
+ desc.fHeight = DEV_H;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fOrigin = origin;
+ SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, false));
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(texture->asRenderTarget()));
+ test_write_pixels(reporter, surface);
+ }
+}
+#endif
« no previous file with comments | « tests/TextBlobCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698