| Index: tests/SpecialSurfaceTest.cpp
|
| diff --git a/tests/SpecialSurfaceTest.cpp b/tests/SpecialSurfaceTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0cc10f5c342ede7ed2b54e0748790af48805e1bd
|
| --- /dev/null
|
| +++ b/tests/SpecialSurfaceTest.cpp
|
| @@ -0,0 +1,61 @@
|
| +/*
|
| +* Copyright 2016 Google Inc.
|
| +*
|
| +* Use of this source code is governed by a BSD-style license that can be
|
| +* found in the LICENSE file
|
| +*/
|
| +
|
| +#include "SkCanvas.h"
|
| +#include "SkSpecialImage.h"
|
| +#include "SkSpecialSurface.h"
|
| +#include "Test.h"
|
| +
|
| +#if SK_SUPPORT_GPU
|
| +#include "GrContext.h"
|
| +#endif
|
| +
|
| +// This needs to be a non-power-of-2 to exercise the gpu's loose fit behavior
|
| +static const int kWidthHeight = 10;
|
| +
|
| +// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot)
|
| +static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter) {
|
| +
|
| + REPORTER_ASSERT(reporter, kWidthHeight == surf->width());
|
| + REPORTER_ASSERT(reporter, kWidthHeight == surf->height());
|
| +
|
| + SkCanvas* canvas = surf->getCanvas();
|
| + SK_ALWAYSBREAK(canvas);
|
| +
|
| + canvas->clear(SK_ColorRED);
|
| +
|
| + SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot());
|
| + REPORTER_ASSERT(reporter, img);
|
| +
|
| + REPORTER_ASSERT(reporter, kWidthHeight == img->width());
|
| + REPORTER_ASSERT(reporter, kWidthHeight == img->height());
|
| +
|
| + REPORTER_ASSERT(reporter, !surf->getCanvas());
|
| +}
|
| +
|
| +DEF_TEST(SpecialSurface_Raster, reporter) {
|
| +
|
| + SkImageInfo info = SkImageInfo::MakeN32(kWidthHeight, kWidthHeight, kOpaque_SkAlphaType);
|
| + SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::New(info));
|
| +
|
| + test_surface(surf, reporter);
|
| +}
|
| +
|
| +#if SK_SUPPORT_GPU
|
| +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu, reporter, context) {
|
| + GrSurfaceDesc desc;
|
| + desc.fConfig = kSkia8888_GrPixelConfig;
|
| + desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
| + desc.fWidth = kWidthHeight;
|
| + desc.fHeight = kWidthHeight;
|
| +
|
| + SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::New(context, desc));
|
| +
|
| + test_surface(surf, reporter);
|
| +}
|
| +
|
| +#endif
|
|
|