Generate list of GPU contexts outside tests
Use DEF_GPUTEST_FOR_*_CONTEXT macros to obtain the test GPU context. Makes changing the context -related classes easier, since not all tests need to be changed. BUG=skia:2992 Review URL: https://codereview.chromium.org/1448873002
This commit is contained in:
parent
362c900625
commit
1530283c48
@ -99,8 +99,7 @@ static bool compare(const SkBitmap& ref, const SkIRect& iref,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void test_blur_drawing(skiatest::Reporter* reporter) {
|
||||
|
||||
DEF_TEST(BlurDrawing, reporter) {
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorGRAY);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
@ -276,15 +275,9 @@ static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma,
|
||||
#if SK_SUPPORT_GPU
|
||||
#if 0
|
||||
// temporary disable; see below for explanation
|
||||
static bool gpu_blur_path(GrContextFactory* factory, const SkPath& path,
|
||||
static bool gpu_blur_path(GrContext* context, const SkPath& path,
|
||||
SkScalar gaussianSigma,
|
||||
int* result, int resultCount) {
|
||||
|
||||
GrContext* grContext = factory->get(GrContextFactory::kNative_GLContextType);
|
||||
if (nullptr == grContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
@ -326,8 +319,7 @@ static bool match(int* first, int* second, int count, int tol) {
|
||||
}
|
||||
|
||||
// Test out the normal blur style with a wide range of sigmas
|
||||
static void test_sigma_range(skiatest::Reporter* reporter, GrContextFactory* factory) {
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BlurSigmaRange, reporter, context) {
|
||||
static const int kSize = 100;
|
||||
|
||||
// The geometry is offset a smidge to trigger:
|
||||
@ -365,7 +357,7 @@ static void test_sigma_range(skiatest::Reporter* reporter, GrContextFactory* fac
|
||||
#if SK_SUPPORT_GPU
|
||||
#if 0
|
||||
int gpuResult[kSize];
|
||||
bool haveGPUResult = gpu_blur_path(factory, rectPath, sigma, gpuResult, kSize);
|
||||
bool haveGPUResult = gpu_blur_path(context, rectPath, sigma, gpuResult, kSize);
|
||||
// Disabling this test for now -- I don't think it's a legit comparison.
|
||||
// Will continue to investigate this.
|
||||
if (haveGPUResult) {
|
||||
@ -507,7 +499,7 @@ static void test_layerDrawLooper(skiatest::Reporter* reporter, SkMaskFilter* mf,
|
||||
test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
|
||||
}
|
||||
|
||||
static void test_asABlur(skiatest::Reporter* reporter) {
|
||||
DEF_TEST(BlurAsABlur, reporter) {
|
||||
const SkBlurStyle styles[] = {
|
||||
kNormal_SkBlurStyle, kSolid_SkBlurStyle, kOuter_SkBlurStyle, kInner_SkBlurStyle
|
||||
};
|
||||
@ -566,9 +558,3 @@ static void test_asABlur(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_GPUTEST(Blur, reporter, factory) {
|
||||
test_blur_drawing(reporter);
|
||||
test_sigma_range(reporter, factory);
|
||||
test_asABlur(reporter);
|
||||
}
|
||||
|
@ -10,13 +10,11 @@
|
||||
// This is a GR test
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrClipMaskManager.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#include "GrContext.h"
|
||||
|
||||
// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
|
||||
// to the render target
|
||||
static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) {
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) {
|
||||
static const int kXSize = 100;
|
||||
static const int kYSize = 100;
|
||||
|
||||
@ -68,18 +66,4 @@ static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) {
|
||||
REPORTER_ASSERT(reporter, isIntersectionOfRects);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GrClipBounds, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
if (!GrContextFactory::IsRenderingGLContext(glType)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(glType);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
test_clip_bounds(reporter, context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -14,19 +14,17 @@
|
||||
|
||||
#include <float.h>
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#include "GrTexture.h"
|
||||
#include "GrContextFactory.h"
|
||||
|
||||
#include "SkGpuDevice.h"
|
||||
#include "SkHalf.h"
|
||||
|
||||
static const int DEV_W = 100, DEV_H = 100;
|
||||
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
|
||||
|
||||
template <typename T>
|
||||
void runFPTest(skiatest::Reporter* reporter, GrContextFactory* factory,
|
||||
void runFPTest(skiatest::Reporter* reporter, GrContext* context,
|
||||
T min, T max, T epsilon, T maxInt, int arraySize, GrPixelConfig config) {
|
||||
SkTDArray<T> controlPixelData, readBuffer;
|
||||
controlPixelData.setCount(arraySize);
|
||||
@ -40,7 +38,6 @@ void runFPTest(skiatest::Reporter* reporter, GrContextFactory* factory,
|
||||
}
|
||||
|
||||
for (int origin = 0; origin < 2; ++origin) {
|
||||
for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++glCtxType) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = DEV_W;
|
||||
@ -48,17 +45,6 @@ void runFPTest(skiatest::Reporter* reporter, GrContextFactory* factory,
|
||||
desc.fConfig = config;
|
||||
desc.fOrigin = 0 == origin ?
|
||||
kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
|
||||
|
||||
GrContextFactory::GLContextType type =
|
||||
static_cast<GrContextFactory::GLContextType>(glCtxType);
|
||||
if (!GrContextFactory::IsRenderingGLContext(type)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(type);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->createTexture(
|
||||
desc, false, controlPixelData.begin(), 0));
|
||||
// Floating point textures are NOT supported everywhere
|
||||
@ -69,14 +55,13 @@ void runFPTest(skiatest::Reporter* reporter, GrContextFactory* factory,
|
||||
REPORTER_ASSERT(reporter,
|
||||
0 == memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4/*RGBA*/;
|
||||
static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24
|
||||
|
||||
DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
|
||||
runFPTest<float>(reporter, factory, FLT_MIN, FLT_MAX, FLT_EPSILON,
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FloatingPointTextureTest, reporter, context) {
|
||||
runFPTest<float>(reporter, context, FLT_MIN, FLT_MAX, FLT_EPSILON,
|
||||
kMaxIntegerRepresentableInSPFloatingPoint,
|
||||
FP_CONTROL_ARRAY_SIZE, kRGBA_float_GrPixelConfig);
|
||||
}
|
||||
@ -84,16 +69,16 @@ DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
|
||||
static const int HALF_ALPHA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*/;
|
||||
static const SkHalf kMaxIntegerRepresentableInHalfFloatingPoint = 0x6800; // 2 ^ 11
|
||||
|
||||
DEF_GPUTEST(HalfFloatAlphaTextureTest, reporter, factory) {
|
||||
runFPTest<SkHalf>(reporter, factory, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatAlphaTextureTest, reporter, context) {
|
||||
runFPTest<SkHalf>(reporter, context, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
|
||||
kMaxIntegerRepresentableInHalfFloatingPoint,
|
||||
HALF_ALPHA_CONTROL_ARRAY_SIZE, kAlpha_half_GrPixelConfig);
|
||||
}
|
||||
|
||||
static const int HALF_RGBA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4 /*RGBA*/;
|
||||
|
||||
DEF_GPUTEST(HalfFloatRGBATextureTest, reporter, factory) {
|
||||
runFPTest<SkHalf>(reporter, factory, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatRGBATextureTest, reporter, context) {
|
||||
runFPTest<SkHalf>(reporter, context, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
|
||||
kMaxIntegerRepresentableInHalfFloatingPoint,
|
||||
HALF_RGBA_CONTROL_ARRAY_SIZE, kRGBA_half_GrPixelConfig);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrFragmentProcessor.h"
|
||||
#include "GrInvariantOutput.h"
|
||||
#include "SkGr.h"
|
||||
@ -34,7 +33,7 @@ static GrColor filterColor(const GrColor& color, uint32_t flags) {
|
||||
return color & mask;
|
||||
}
|
||||
|
||||
static void test_getConstantColorComponents(skiatest::Reporter* reporter, GrContext* grContext) {
|
||||
DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) {
|
||||
struct GetConstantComponentTestCase {
|
||||
// "Shape drawn with"
|
||||
uint32_t inputComponents; // "rgb of", "red of", "alpha of", ...
|
||||
@ -102,7 +101,7 @@ static void test_getConstantColorComponents(skiatest::Reporter* reporter, GrCont
|
||||
const GetConstantComponentTestCase& test = filterTests[i];
|
||||
SkAutoTUnref<SkColorFilter> cf(
|
||||
SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode));
|
||||
SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(grContext));
|
||||
SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(context));
|
||||
REPORTER_ASSERT(reporter, fp);
|
||||
GrInvariantOutput inout(test.inputColor,
|
||||
static_cast<GrColorComponentFlags>(test.inputComponents),
|
||||
@ -114,17 +113,4 @@ static void test_getConstantColorComponents(skiatest::Reporter* reporter, GrCont
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GpuColorFilter, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
|
||||
GrContext* grContext = factory->get(glType);
|
||||
if (nullptr == grContext) {
|
||||
continue;
|
||||
}
|
||||
|
||||
test_getConstantColorComponents(reporter, grContext);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,7 +10,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrPath.h"
|
||||
#include "GrStrokeInfo.h"
|
||||
#include "SkBitmap.h"
|
||||
@ -24,6 +23,8 @@
|
||||
#include "SkSurface.h"
|
||||
#include "Test.h"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) {
|
||||
// Filling an empty path should not crash.
|
||||
SkPaint paint;
|
||||
@ -76,43 +77,22 @@ static void test_drawSameRectOvals(skiatest::Reporter*, SkCanvas* canvas) {
|
||||
fill_and_stroke(canvas, oval1, oval2, dashEffect);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GpuDrawPath, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
|
||||
GrContext* grContext = factory->get(glType);
|
||||
if (nullptr == grContext) {
|
||||
continue;
|
||||
}
|
||||
static const int sampleCounts[] = { 0, 4, 16 };
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(sampleCounts); ++i) {
|
||||
DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuDrawPath, reporter, context) {
|
||||
for (auto& test_func : { &test_drawPathEmpty, &test_drawSameRectOvals }) {
|
||||
for (auto& sampleCount : {0, 4, 16}) {
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255);
|
||||
|
||||
SkAutoTUnref<SkSurface> surface(
|
||||
SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, info,
|
||||
sampleCounts[i], nullptr));
|
||||
SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info,
|
||||
sampleCount, nullptr));
|
||||
if (!surface) {
|
||||
continue;
|
||||
}
|
||||
test_drawPathEmpty(reporter, surface->getCanvas());
|
||||
test_func(reporter, surface->getCanvas());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GpuDrawPathSameRectOvals, reporter, factory) {
|
||||
GrContext* grContext = factory->get(GrContextFactory::kNVPR_GLContextType);
|
||||
if (!grContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkSurface> surface(
|
||||
SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted,
|
||||
SkImageInfo::MakeN32Premul(255, 255), 4));
|
||||
test_drawSameRectOvals(reporter, surface->getCanvas());
|
||||
}
|
||||
|
||||
DEF_TEST(GrPathKeys, reporter) {
|
||||
DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) {
|
||||
// Keys should not ignore conic weights.
|
||||
SkPath path1, path2;
|
||||
path1.setIsVolatile(true);
|
||||
|
@ -8,7 +8,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrLayerCache.h"
|
||||
#include "GrResourceCache.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
@ -108,7 +107,7 @@ static void lock_layer(skiatest::Reporter* reporter,
|
||||
// In particular it checks its interaction with the resource cache (w.r.t.
|
||||
// locking & unlocking textures).
|
||||
// TODO: need to add checks on VRAM usage!
|
||||
DEF_GPUTEST(GpuLayerCache, reporter, factory) {
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) {
|
||||
// Add one more layer than can fit in the atlas
|
||||
static const int kInitialNumLayers = TestingAccess::NumPlots() + 1;
|
||||
|
||||
@ -116,19 +115,6 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) {
|
||||
GrResourceCache::Stats stats;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
|
||||
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
|
||||
|
||||
if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GrContext* context = factory->get(glCtxType);
|
||||
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SkAutoTUnref<const SkPicture> picture;
|
||||
|
||||
{
|
||||
@ -378,7 +364,6 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) {
|
||||
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
||||
REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,28 +11,14 @@
|
||||
|
||||
#include "GrCaps.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrGpu.h"
|
||||
|
||||
static void test_print(skiatest::Reporter*, const GrCaps* caps) {
|
||||
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrDrawTargetPrint, reporter, context) {
|
||||
// This used to assert.
|
||||
SkString result = caps->dump();
|
||||
SkString result = context->caps()->dump();
|
||||
SkASSERT(!result.isEmpty());
|
||||
SkString shaderResult = caps->shaderCaps()->dump();
|
||||
SkString shaderResult = context->caps()->shaderCaps()->dump();
|
||||
SkASSERT(!shaderResult.isEmpty());
|
||||
}
|
||||
|
||||
DEF_GPUTEST(GrDrawTarget, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
|
||||
GrContext* grContext = factory->get(glType);
|
||||
if (nullptr == grContext) {
|
||||
continue;
|
||||
}
|
||||
|
||||
test_print(reporter, grContext->caps());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -27,16 +27,9 @@ static void test_color_opaque_with_coverage(skiatest::Reporter* reporter, const
|
||||
static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
|
||||
static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
|
||||
static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps);
|
||||
static void test_no_dual_source_blending(skiatest::Reporter* reporter);
|
||||
|
||||
DEF_GPUTEST(GrPorterDuff, reporter, factory) {
|
||||
GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
|
||||
if (!ctx) {
|
||||
SkFAIL("Failed to create null context.");
|
||||
return;
|
||||
}
|
||||
|
||||
const GrCaps& caps = *ctx->getGpu()->caps();
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(GrPorterDuff, reporter, context) {
|
||||
const GrCaps& caps = *context->getGpu()->caps();
|
||||
if (!caps.shaderCaps()->dualSourceBlendingSupport()) {
|
||||
SkFAIL("Null context does not support dual source blending.");
|
||||
return;
|
||||
@ -48,7 +41,6 @@ DEF_GPUTEST(GrPorterDuff, reporter, factory) {
|
||||
test_color_opaque_no_coverage(reporter, caps);
|
||||
test_lcd_coverage(reporter, caps);
|
||||
test_lcd_coverage_fallback_case(reporter, caps);
|
||||
test_no_dual_source_blending(reporter);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1154,12 +1146,11 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const
|
||||
TEST_ASSERT(blendInfo.fWriteColor);
|
||||
}
|
||||
|
||||
static void test_no_dual_source_blending(skiatest::Reporter* reporter) {
|
||||
DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
|
||||
GrContextOptions opts;
|
||||
opts.fSuppressDualSourceBlending = true;
|
||||
GrContextFactory factory(opts);
|
||||
factory.get(GrContextFactory::kNull_GLContextType);
|
||||
GrContext* ctx = factory.get(GrContextFactory::kNull_GLContextType);
|
||||
GrContextFactory mockFactory(opts);
|
||||
GrContext* ctx = mockFactory.get(GrContextFactory::kNull_GLContextType);
|
||||
if (!ctx) {
|
||||
SkFAIL("Failed to create null context without ARB_blend_func_extended.");
|
||||
return;
|
||||
@ -1172,7 +1163,8 @@ static void test_no_dual_source_blending(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
GrBackendObject backendTex =
|
||||
ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig);
|
||||
ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100,
|
||||
kRGBA_8888_GrPixelConfig);
|
||||
GrBackendTextureDesc fakeDesc;
|
||||
fakeDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
||||
fakeDesc.fWidth = fakeDesc.fHeight = 100;
|
||||
|
@ -10,7 +10,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrGpu.h"
|
||||
#include "GrRenderTarget.h"
|
||||
#include "GrTexture.h"
|
||||
@ -19,9 +18,7 @@
|
||||
|
||||
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
|
||||
// and render targets to GrSurface all work as expected.
|
||||
DEF_GPUTEST(GrSurface, reporter, factory) {
|
||||
GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
|
||||
if (context) {
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(GrSurface, reporter, context) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
@ -70,7 +67,6 @@ DEF_GPUTEST(GrSurface, reporter, factory) {
|
||||
texRT2->unref();
|
||||
tex1->unref();
|
||||
context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,7 +10,6 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrTexture.h"
|
||||
#include "GrTexturePriv.h"
|
||||
#include "SkCanvas.h"
|
||||
@ -20,9 +19,7 @@
|
||||
|
||||
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
|
||||
// and render targets to GrSurface all work as expected.
|
||||
DEF_GPUTEST(GrTextureMipMapInvalidationTest, reporter, factory) {
|
||||
GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
|
||||
if (context) {
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
@ -60,7 +57,6 @@ DEF_GPUTEST(GrTextureMipMapInvalidationTest, reporter, factory) {
|
||||
surface->unref();
|
||||
texRT1->unref();
|
||||
texRT2->unref();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#endif
|
||||
|
||||
@ -1261,11 +1261,7 @@ DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
|
||||
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
|
||||
if (nullptr == context) {
|
||||
return;
|
||||
}
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) {
|
||||
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
|
||||
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
|
||||
@ -1279,11 +1275,7 @@ DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
|
||||
test_crop_rects(&proxy, reporter);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) {
|
||||
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
|
||||
if (nullptr == context) {
|
||||
return;
|
||||
}
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(HugeBlurImageFilter_Gpu, reporter, context) {
|
||||
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
|
||||
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
|
||||
@ -1297,11 +1289,7 @@ DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) {
|
||||
test_huge_blur(&canvas, reporter);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
|
||||
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
|
||||
if (nullptr == context) {
|
||||
return;
|
||||
}
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, context) {
|
||||
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
|
||||
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
|
||||
@ -1315,11 +1303,7 @@ DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
|
||||
test_xfermode_cropped_input(&canvas, reporter);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) {
|
||||
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
|
||||
if (nullptr == context) {
|
||||
return;
|
||||
}
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) {
|
||||
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
|
||||
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#endif
|
||||
#include "SkImage.h"
|
||||
#include "SkSurface.h"
|
||||
@ -65,23 +65,10 @@ DEF_TEST(ImageIsOpaqueTest, reporter) {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
DEF_GPUTEST(ImageIsOpaqueTest_GPU, reporter, factory) {
|
||||
for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
|
||||
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
|
||||
|
||||
if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GrContext* context = factory->get(glCtxType);
|
||||
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, context) {
|
||||
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
|
||||
SkAutoTUnref<SkSurface> surfaceTransparent(
|
||||
SkSurface::NewRenderTarget(context,SkSurface::kNo_Budgeted, infoTransparent));
|
||||
SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, infoTransparent));
|
||||
check_isopaque(reporter, surfaceTransparent, false);
|
||||
|
||||
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
|
||||
@ -89,7 +76,6 @@ DEF_GPUTEST(ImageIsOpaqueTest_GPU, reporter, factory) {
|
||||
SkSurface::NewRenderTarget(context,SkSurface::kNo_Budgeted, infoOpaque));
|
||||
|
||||
check_isopaque(reporter, surfaceOpaque, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -5,17 +5,17 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkTypes.h"
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#endif
|
||||
#include "SkCanvas.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkShader.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
#include "SkTypes.h"
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#endif
|
||||
|
||||
void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) {
|
||||
SkAutoLockPixels lockBm1(bm1);
|
||||
SkAutoLockPixels lockBm2(bm2);
|
||||
@ -143,20 +143,7 @@ void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) {
|
||||
runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) {
|
||||
for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
|
||||
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
|
||||
|
||||
if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GrContext* context = factory->get(glCtxType);
|
||||
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageNewShader_GPU, reporter, context) {
|
||||
// GPU -> GPU
|
||||
gpuToGpu(reporter, context);
|
||||
|
||||
@ -165,7 +152,6 @@ DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) {
|
||||
|
||||
// RASTER -> GPU
|
||||
rasterToGpu(reporter, context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -31,10 +31,6 @@
|
||||
#include "SkStream.h"
|
||||
#include "sk_tool_utils.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "SkSurface.h"
|
||||
#include "GrContextFactory.h"
|
||||
#endif
|
||||
#include "Test.h"
|
||||
|
||||
#include "SkLumaColorFilter.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "sk_tool_utils.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#endif
|
||||
|
||||
@ -63,41 +63,8 @@ static void fillCanvas(SkCanvas* canvas, SkColorType colorType, PackUnpremulProc
|
||||
canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) {
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
|
||||
|
||||
for (int dtype = 0; dtype < 2; ++dtype) {
|
||||
|
||||
int glCtxTypeCnt = 1;
|
||||
#if SK_SUPPORT_GPU
|
||||
if (0 != dtype) {
|
||||
glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
|
||||
}
|
||||
#endif
|
||||
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
|
||||
SkAutoTUnref<SkBaseDevice> device;
|
||||
if (0 == dtype) {
|
||||
device.reset(SkBitmapDevice::Create(info, props));
|
||||
} else {
|
||||
#if SK_SUPPORT_GPU
|
||||
GrContextFactory::GLContextType type =
|
||||
static_cast<GrContextFactory::GLContextType>(glCtxType);
|
||||
if (!GrContextFactory::IsRenderingGLContext(type)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* ctx = factory->get(type);
|
||||
if (nullptr == ctx) {
|
||||
continue;
|
||||
}
|
||||
device.reset(SkGpuDevice::Create(ctx, SkSurface::kNo_Budgeted, info, 0, &props,
|
||||
SkGpuDevice::kUninit_InitContents));
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
}
|
||||
static void test_premul_alpha_roundtrip(skiatest::Reporter* reporter, SkBaseDevice* device) {
|
||||
SkCanvas canvas(device);
|
||||
|
||||
for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremul); ++upmaIdx) {
|
||||
fillCanvas(&canvas, gUnpremul[upmaIdx].fColorType, gUnpremul[upmaIdx].fPackProc);
|
||||
|
||||
@ -129,6 +96,22 @@ DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEF_TEST(PremulAlphaRoundTrip, reporter) {
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
|
||||
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
|
||||
test_premul_alpha_roundtrip(reporter, device);
|
||||
}
|
||||
#if SK_SUPPORT_GPU
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PremulAlphaRoundTrip_Gpu, reporter, context) {
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
|
||||
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
SkAutoTUnref<SkBaseDevice> device(
|
||||
SkGpuDevice::Create(context, SkSurface::kNo_Budgeted, info, 0, &props,
|
||||
SkGpuDevice::kUninit_InitContents));
|
||||
test_premul_alpha_roundtrip(reporter, device);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -13,11 +13,12 @@
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "SkGpuDevice.h"
|
||||
#include "GrContext.h"
|
||||
#include "SkGr.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,
|
||||
@ -257,8 +258,16 @@ static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init,
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST(ReadPixels, reporter, factory) {
|
||||
const SkIRect testRects[] = {
|
||||
static const struct {
|
||||
SkColorType fColorType;
|
||||
SkAlphaType fAlphaType;
|
||||
} gReadPixelsConfigs[] = {
|
||||
{ kRGBA_8888_SkColorType, kPremul_SkAlphaType },
|
||||
{ kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
|
||||
{ kBGRA_8888_SkColorType, kPremul_SkAlphaType },
|
||||
{ kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
|
||||
};
|
||||
const SkIRect gReadPixelsTestRects[] = {
|
||||
// entire thing
|
||||
DEV_RECT,
|
||||
// larger on all sides
|
||||
@ -303,75 +312,18 @@ DEF_GPUTEST(ReadPixels, reporter, factory) {
|
||||
SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
|
||||
// overlapping top right and bottom right corners
|
||||
SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
|
||||
};
|
||||
};
|
||||
|
||||
for (int dtype = 0; dtype < 3; ++dtype) {
|
||||
int glCtxTypeCnt = 1;
|
||||
#if SK_SUPPORT_GPU
|
||||
// On the GPU we will also try reading back from a non-renderable texture.
|
||||
SkAutoTUnref<GrTexture> texture;
|
||||
|
||||
if (0 != dtype) {
|
||||
glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
|
||||
}
|
||||
#endif
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
|
||||
for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
|
||||
SkAutoTUnref<SkSurface> surface;
|
||||
if (0 == dtype) {
|
||||
surface.reset(SkSurface::NewRaster(info));
|
||||
} else {
|
||||
#if SK_SUPPORT_GPU
|
||||
GrContextFactory::GLContextType type =
|
||||
static_cast<GrContextFactory::GLContextType>(glCtxType);
|
||||
if (!GrContextFactory::IsRenderingGLContext(type)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(type);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = DEV_W;
|
||||
desc.fHeight = DEV_H;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
|
||||
SkAutoTUnref<GrTexture> surfaceTexture(
|
||||
context->textureProvider()->createTexture(desc, false));
|
||||
surface.reset(SkSurface::NewRenderTargetDirect(surfaceTexture->asRenderTarget()));
|
||||
desc.fFlags = kNone_GrSurfaceFlags;
|
||||
|
||||
texture.reset(context->textureProvider()->createTexture(desc, false));
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
}
|
||||
SkCanvas& canvas = *surface->getCanvas();
|
||||
fill_src_canvas(&canvas);
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
if (texture) {
|
||||
fill_src_texture(texture);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const struct {
|
||||
SkColorType fColorType;
|
||||
SkAlphaType fAlphaType;
|
||||
} gReadConfigs[] = {
|
||||
{ kRGBA_8888_SkColorType, kPremul_SkAlphaType },
|
||||
{ kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
|
||||
{ kBGRA_8888_SkColorType, kPremul_SkAlphaType },
|
||||
{ kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
|
||||
};
|
||||
for (size_t rect = 0; rect < SK_ARRAY_COUNT(testRects); ++rect) {
|
||||
const SkIRect& srcRect = testRects[rect];
|
||||
static void test_readpixels(skiatest::Reporter* reporter, SkSurface* surface) {
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
fill_src_canvas(canvas);
|
||||
for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
|
||||
const SkIRect& srcRect = gReadPixelsTestRects[rect];
|
||||
for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bmi = nextBMI(bmi)) {
|
||||
for (size_t c = 0; c < SK_ARRAY_COUNT(gReadConfigs); ++c) {
|
||||
for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) {
|
||||
SkBitmap bmp;
|
||||
init_bitmap(&bmp, srcRect, bmi,
|
||||
gReadConfigs[c].fColorType, gReadConfigs[c].fAlphaType);
|
||||
gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs[c].fAlphaType);
|
||||
|
||||
// if the bitmap has pixels allocated before the readPixels,
|
||||
// note that and fill them with pattern
|
||||
@ -380,7 +332,7 @@ DEF_GPUTEST(ReadPixels, reporter, factory) {
|
||||
fill_dst_bmp_with_init_data(&bmp);
|
||||
}
|
||||
uint32_t idBefore = surface->generationID();
|
||||
bool success = canvas.readPixels(&bmp, srcRect.fLeft, srcRect.fTop);
|
||||
bool success = canvas->readPixels(&bmp, srcRect.fLeft, srcRect.fTop);
|
||||
uint32_t idAfter = surface->generationID();
|
||||
|
||||
// we expect to succeed when the read isn't fully clipped
|
||||
@ -399,32 +351,11 @@ DEF_GPUTEST(ReadPixels, reporter, factory) {
|
||||
// failed then our bitmap should still not have pixels
|
||||
REPORTER_ASSERT(reporter, bmp.isNull());
|
||||
}
|
||||
#if SK_SUPPORT_GPU
|
||||
// Try doing the read directly from a non-renderable texture
|
||||
if (texture && startsWithPixels) {
|
||||
fill_dst_bmp_with_init_data(&bmp);
|
||||
GrPixelConfig dstConfig =
|
||||
SkImageInfo2GrPixelConfig(gReadConfigs[c].fColorType,
|
||||
gReadConfigs[c].fAlphaType,
|
||||
kLinear_SkColorProfileType);
|
||||
uint32_t flags = 0;
|
||||
if (gReadConfigs[c].fAlphaType == kUnpremul_SkAlphaType) {
|
||||
flags = GrContext::kUnpremul_PixelOpsFlag;
|
||||
}
|
||||
bmp.lockPixels();
|
||||
success = texture->readPixels(srcRect.fLeft, srcRect.fTop, bmp.width(),
|
||||
bmp.height(), dstConfig, bmp.getPixels(),
|
||||
bmp.rowBytes(), flags);
|
||||
bmp.unlockPixels();
|
||||
check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop,
|
||||
success, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// check the old webkit version of readPixels that clips the
|
||||
// bitmap size
|
||||
SkBitmap wkbmp;
|
||||
bool success = canvas.readPixels(srcRect, &wkbmp);
|
||||
bool success = canvas->readPixels(srcRect, &wkbmp);
|
||||
SkIRect clippedRect = DEV_RECT;
|
||||
if (clippedRect.intersect(srcRect)) {
|
||||
REPORTER_ASSERT(reporter, success);
|
||||
@ -437,10 +368,83 @@ DEF_GPUTEST(ReadPixels, reporter, factory) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DEF_TEST(ReadPixels, reporter) {
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
|
||||
test_readpixels(reporter, surface);
|
||||
}
|
||||
#if SK_SUPPORT_GPU
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) {
|
||||
for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = DEV_W;
|
||||
desc.fHeight = DEV_H;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fOrigin = origin;
|
||||
SkAutoTUnref<GrTexture> surfaceTexture(
|
||||
context->textureProvider()->createTexture(desc, false));
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(surfaceTexture->asRenderTarget()));
|
||||
desc.fFlags = kNone_GrSurfaceFlags;
|
||||
test_readpixels(reporter, surface);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* texture) {
|
||||
fill_src_texture(texture);
|
||||
for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
|
||||
const SkIRect& srcRect = gReadPixelsTestRects[rect];
|
||||
for (BitmapInit bmi = kFirstBitmapInit; bmi < kBitmapInitCnt; bmi = nextBMI(bmi)) {
|
||||
for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) {
|
||||
SkBitmap bmp;
|
||||
init_bitmap(&bmp, srcRect, bmi,
|
||||
gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs[c].fAlphaType);
|
||||
|
||||
// if the bitmap has pixels allocated before the readPixels,
|
||||
// note that and fill them with pattern
|
||||
bool startsWithPixels = !bmp.isNull();
|
||||
// Try doing the read directly from a non-renderable texture
|
||||
if (startsWithPixels) {
|
||||
fill_dst_bmp_with_init_data(&bmp);
|
||||
GrPixelConfig dstConfig =
|
||||
SkImageInfo2GrPixelConfig(gReadPixelsConfigs[c].fColorType,
|
||||
gReadPixelsConfigs[c].fAlphaType,
|
||||
kLinear_SkColorProfileType);
|
||||
uint32_t flags = 0;
|
||||
if (gReadPixelsConfigs[c].fAlphaType == kUnpremul_SkAlphaType) {
|
||||
flags = GrContext::kUnpremul_PixelOpsFlag;
|
||||
}
|
||||
bmp.lockPixels();
|
||||
bool success = texture->readPixels(srcRect.fLeft, srcRect.fTop, bmp.width(),
|
||||
bmp.height(), dstConfig, bmp.getPixels(),
|
||||
bmp.rowBytes(), flags);
|
||||
bmp.unlockPixels();
|
||||
check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop,
|
||||
success, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, context) {
|
||||
// On the GPU we will also try reading back from a non-renderable texture.
|
||||
for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
|
||||
SkAutoTUnref<GrTexture> texture;
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = DEV_W;
|
||||
desc.fHeight = DEV_H;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fOrigin = origin;
|
||||
desc.fFlags = kNone_GrSurfaceFlags;
|
||||
texture.reset(context->textureProvider()->createTexture(desc, false));
|
||||
test_readpixels_texture(reporter, texture);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/////////////////////
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
@ -560,13 +564,7 @@ static void dump_to_file(const char name[], SkData* data) {
|
||||
*
|
||||
* https://bug.skia.org/4351
|
||||
*/
|
||||
DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) {
|
||||
GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
|
||||
if (!ctx) {
|
||||
REPORTER_ASSERT(reporter, false);
|
||||
return;
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(ReadPixels_Subset_Gpu, reporter, context) {
|
||||
SkBitmap bitmap;
|
||||
make_ringed_bitmap(&bitmap, 6, 6);
|
||||
const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4);
|
||||
@ -575,7 +573,7 @@ DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) {
|
||||
SkBitmap bm_subset, tx_subset;
|
||||
|
||||
// ... one from a texture-subset
|
||||
SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(ctx, bitmap,
|
||||
SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(context, bitmap,
|
||||
GrTextureParams::ClampNoFilter()));
|
||||
SkBitmap tx_full;
|
||||
GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_full);
|
||||
@ -584,7 +582,7 @@ DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) {
|
||||
// ... one from a bitmap-subset
|
||||
SkBitmap tmp_subset;
|
||||
bitmap.extractSubset(&tmp_subset, subset);
|
||||
SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(ctx, tmp_subset,
|
||||
SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(context, tmp_subset,
|
||||
GrTextureParams::ClampNoFilter()));
|
||||
GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), true, &bm_subset);
|
||||
|
||||
@ -593,8 +591,8 @@ DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) {
|
||||
|
||||
// do they draw the same?
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
|
||||
SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0));
|
||||
SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0));
|
||||
SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
|
||||
SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
|
||||
|
||||
if (false) {
|
||||
//
|
||||
|
@ -10,23 +10,13 @@
|
||||
// This test is specific to the GPU backend.
|
||||
#if SK_SUPPORT_GPU && !defined(SK_BUILD_FOR_ANDROID)
|
||||
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "SkGpuDevice.h"
|
||||
|
||||
static const int X_SIZE = 12;
|
||||
static const int Y_SIZE = 12;
|
||||
|
||||
DEF_GPUTEST(ReadWriteAlpha, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
if (!GrContextFactory::IsRenderingGLContext(glType)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(glType);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
|
||||
unsigned char textureData[X_SIZE][Y_SIZE];
|
||||
|
||||
memset(textureData, 0, X_SIZE * Y_SIZE);
|
||||
@ -109,7 +99,6 @@ DEF_GPUTEST(ReadWriteAlpha, reporter, factory) {
|
||||
}
|
||||
|
||||
REPORTER_ASSERT(reporter, match);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrLayerCache.h"
|
||||
#include "GrRecordReplaceDraw.h"
|
||||
#include "RecordTestUtils.h"
|
||||
@ -140,20 +140,9 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace
|
||||
}
|
||||
}
|
||||
|
||||
DEF_GPUTEST(RecordReplaceDraw, r, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
if (!GrContextFactory::IsRenderingGLContext(glType)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(glType);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RecordReplaceDraw, r, context) {
|
||||
test_replacements(r, context, false);
|
||||
test_replacements(r, context, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -30,7 +30,17 @@ static const int gWidth = 640;
|
||||
static const int gHeight = 480;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanvas* canvas) {
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = gWidth;
|
||||
desc.fHeight = gHeight;
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
|
||||
SkSurface::kNo_Budgeted, info));
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
|
||||
const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
|
||||
|
||||
SkBitmap src;
|
||||
@ -70,7 +80,7 @@ static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva
|
||||
context->setResourceCacheLimits(oldMaxNum, oldMaxBytes);
|
||||
}
|
||||
|
||||
static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* context) {
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, context) {
|
||||
GrSurfaceDesc smallDesc;
|
||||
smallDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
smallDesc.fConfig = kSkia8888_GrPixelConfig;
|
||||
@ -176,7 +186,7 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
|
||||
}
|
||||
}
|
||||
|
||||
static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* context) {
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, context) {
|
||||
const GrGpu* gpu = context->getGpu();
|
||||
// this test is only valid for GL
|
||||
if (!gpu || !gpu->glContextForTesting()) {
|
||||
@ -1284,30 +1294,7 @@ static void test_abandoned(skiatest::Reporter* reporter) {
|
||||
resource->resourcePriv().removeUniqueKey();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
DEF_GPUTEST(ResourceCache, reporter, factory) {
|
||||
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
|
||||
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
|
||||
if (!GrContextFactory::IsRenderingGLContext(glType)) {
|
||||
continue;
|
||||
}
|
||||
GrContext* context = factory->get(glType);
|
||||
if (nullptr == context) {
|
||||
continue;
|
||||
}
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = gWidth;
|
||||
desc.fHeight = gHeight;
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
|
||||
SkSurface::kNo_Budgeted, info));
|
||||
test_cache(reporter, context, surface->getCanvas());
|
||||
test_stencil_buffers(reporter, context);
|
||||
test_wrapped_resources(reporter, context);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(ResourceCacheMisc, reporter, factory) {
|
||||
// The below tests create their own mock contexts.
|
||||
test_no_key(reporter);
|
||||
test_budgeting(reporter);
|
||||
|
@ -7,11 +7,10 @@
|
||||
|
||||
#include "Test.h"
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "SkCanvas.h"
|
||||
|
||||
#include "SkSurface.h"
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrCaps.h"
|
||||
#include "GrContext.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
// using anonymous namespace because these functions are used as template params.
|
||||
namespace {
|
||||
@ -139,7 +138,7 @@ void read_and_check_pixels(skiatest::Reporter* reporter, GrTexture* texture, uin
|
||||
|
||||
// TODO: Add tests for copySurface between srgb/linear textures. Add tests for unpremul/premul
|
||||
// conversion during read/write along with srgb/linear conversions.
|
||||
DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
|
||||
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, context) {
|
||||
#if defined(GOOGLE3)
|
||||
// Stack frame size is limited in GOOGLE3.
|
||||
static const int kW = 63;
|
||||
@ -155,14 +154,6 @@ DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = 0; t < GrContextFactory::kGLContextTypeCnt; ++t) {
|
||||
GrContextFactory::GLContextType glType = (GrContextFactory::GLContextType) t;
|
||||
GrContext* context;
|
||||
// We allow more error on GPUs with lower precision shader variables.
|
||||
if (!GrContextFactory::IsRenderingGLContext(glType) || !(context = factory->get(glType))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = kW;
|
||||
@ -173,7 +164,7 @@ DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
|
||||
SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(desc, false));
|
||||
if (!tex) {
|
||||
ERRORF(reporter, "Could not create SRGBA texture.");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
float error = context->caps()->shaderCaps()->floatPrecisionVaries() ? 1.2f : 0.5f;
|
||||
@ -212,7 +203,7 @@ DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
|
||||
tex.reset(context->textureProvider()->createTexture(desc, false));
|
||||
if (!tex) {
|
||||
ERRORF(reporter, "Could not create RGBA texture.");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// Write srgba data to a rgba texture and read back as srgba and rgba
|
||||
@ -235,7 +226,6 @@ DEF_GPUTEST(SRGBReadWritePixels, reporter, factory) {
|
||||
} else {
|
||||
ERRORF(reporter, "Could not write rgba data to rgba texture.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "SkPath.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrTest.h"
|
||||
#include "Test.h"
|
||||
#include "batches/GrTessellatingPathRenderer.h"
|
||||
@ -252,11 +252,7 @@ static void test_path(GrDrawTarget* dt, GrRenderTarget* rt, GrResourceProvider*
|
||||
tess.drawPath(args);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TessellatingPathRendererTests, reporter, factory) {
|
||||
GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
|
||||
if (nullptr == context) {
|
||||
return;
|
||||
}
|
||||
DEF_GPUTEST_FOR_NATIVE_CONTEXT(TessellatingPathRendererTests, reporter, context) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = 800;
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "Test.h"
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContextFactory.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrTest.h"
|
||||
|
||||
struct TextBlobWrapper {
|
||||
@ -52,24 +52,21 @@ static const int kWidth = 1024;
|
||||
static const int kHeight = 768;
|
||||
|
||||
// This test hammers the GPU textblobcache and font atlas
|
||||
static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory* factory,
|
||||
static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* context,
|
||||
int maxTotalText, int maxGlyphID, int maxFamilies, bool normal,
|
||||
bool stressTest) {
|
||||
// setup surface
|
||||
uint32_t flags = 0;
|
||||
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
|
||||
|
||||
// We don't typically actually draw with this unittest
|
||||
GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
|
||||
|
||||
// configure our context for maximum stressing of cache and atlas
|
||||
if (stressTest) {
|
||||
GrTest::SetupAlwaysEvictAtlas(ctx);
|
||||
ctx->setTextBlobCacheLimit_ForTesting(0);
|
||||
GrTest::SetupAlwaysEvictAtlas(context);
|
||||
context->setTextBlobCacheLimit_ForTesting(0);
|
||||
}
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType);
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info,
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info,
|
||||
0, &props));
|
||||
REPORTER_ASSERT(reporter, surface);
|
||||
if (!surface) {
|
||||
@ -149,30 +146,30 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory
|
||||
draw(canvasNoLCD, 2, blobs);
|
||||
|
||||
// test draw after free
|
||||
ctx->freeGpuResources();
|
||||
context->freeGpuResources();
|
||||
draw(canvas, 1, blobs);
|
||||
|
||||
ctx->freeGpuResources();
|
||||
context->freeGpuResources();
|
||||
draw(canvasNoLCD, 1, blobs);
|
||||
|
||||
// test draw after abandon
|
||||
ctx->abandonContext();
|
||||
context->abandonContext();
|
||||
draw(canvas, 1, blobs);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TextBlobCache, reporter, factory) {
|
||||
text_blob_cache_inner(reporter, factory, 1024, 256, 30, true, false);
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobCache, reporter, context) {
|
||||
text_blob_cache_inner(reporter, context, 1024, 256, 30, true, false);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TextBlobStressCache, reporter, factory) {
|
||||
text_blob_cache_inner(reporter, factory, 256, 256, 10, true, true);
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressCache, reporter, context) {
|
||||
text_blob_cache_inner(reporter, context, 256, 256, 10, true, true);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TextBlobAbnormal, reporter, factory) {
|
||||
text_blob_cache_inner(reporter, factory, 256, 256, 10, false, false);
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobAbnormal, reporter, context) {
|
||||
text_blob_cache_inner(reporter, context, 256, 256, 10, false, false);
|
||||
}
|
||||
|
||||
DEF_GPUTEST(TextBlobStressAbnormal, reporter, factory) {
|
||||
text_blob_cache_inner(reporter, factory, 256, 256, 10, false, true);
|
||||
DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressAbnormal, reporter, context) {
|
||||
text_blob_cache_inner(reporter, context, 256, 256, 10, false, true);
|
||||
}
|
||||
#endif
|
||||
|
@ -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,32 +349,6 @@ 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
|
||||
|
||||
SkAutoTUnref<SkSurface> surface(create_surface(gCanvasConfigs[i], context));
|
||||
SkCanvas& canvas = *surface->getCanvas();
|
||||
|
||||
static const struct {
|
||||
@ -473,6 +389,33 @@ DEF_GPUTEST(WritePixels, reporter, factory) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user