OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file |
| 6 */ |
| 7 |
| 8 #include "SkCanvas.h" |
| 9 #include "SkSpecialImage.h" |
| 10 #include "SkSpecialSurface.h" |
| 11 #include "Test.h" |
| 12 |
| 13 #if SK_SUPPORT_GPU |
| 14 #include "GrContext.h" |
| 15 #include "SkGr.h" |
| 16 #endif |
| 17 |
| 18 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise |
| 19 // the gpu's loose fit behavior |
| 20 static const int kSmallerSize = 10; |
| 21 static const int kPad = 5; |
| 22 static const int kFullSize = kSmallerSize + 2 * kPad; |
| 23 |
| 24 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho
t) |
| 25 static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, i
nt offset) { |
| 26 |
| 27 REPORTER_ASSERT(reporter, offset == surf->activeRect().fLeft); |
| 28 REPORTER_ASSERT(reporter, offset == surf->activeRect().fTop); |
| 29 REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().width()); |
| 30 REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().height()); |
| 31 |
| 32 SkCanvas* canvas = surf->getCanvas(); |
| 33 SK_ALWAYSBREAK(canvas); |
| 34 |
| 35 canvas->clear(SK_ColorRED); |
| 36 |
| 37 SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot()); |
| 38 REPORTER_ASSERT(reporter, img); |
| 39 |
| 40 REPORTER_ASSERT(reporter, surf->activeRect() == img->activeRect()); |
| 41 |
| 42 // the canvas was invalidated by the newImageSnapshot call |
| 43 REPORTER_ASSERT(reporter, !surf->getCanvas()); |
| 44 } |
| 45 |
| 46 DEF_TEST(SpecialSurface_Raster, reporter) { |
| 47 |
| 48 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_
SkAlphaType); |
| 49 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRaster(info)); |
| 50 |
| 51 test_surface(surf, reporter, 0); |
| 52 } |
| 53 |
| 54 #if SK_SUPPORT_GPU |
| 55 |
| 56 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) { |
| 57 GrSurfaceDesc desc; |
| 58 desc.fConfig = kSkia8888_GrPixelConfig; |
| 59 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 60 desc.fWidth = kSmallerSize; |
| 61 desc.fHeight = kSmallerSize; |
| 62 |
| 63 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(context, desc))
; |
| 64 |
| 65 test_surface(surf, reporter, 0); |
| 66 } |
| 67 |
| 68 // test the more flexible factory |
| 69 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) { |
| 70 GrSurfaceDesc desc; |
| 71 desc.fConfig = kSkia8888_GrPixelConfig; |
| 72 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 73 desc.fWidth = kFullSize; |
| 74 desc.fHeight = kFullSize; |
| 75 |
| 76 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture
(desc)); |
| 77 SK_ALWAYSBREAK(temp); |
| 78 |
| 79 const SkIRect activeRect = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmal
lerSize); |
| 80 |
| 81 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(activeRect, tem
p)); |
| 82 |
| 83 test_surface(surf, reporter, kPad); |
| 84 |
| 85 // TODO: check that the clear didn't escape the active region |
| 86 } |
| 87 |
| 88 #endif |
OLD | NEW |