OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file | 5 * found in the LICENSE file |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkSpecialImage.h" | 9 #include "SkSpecialImage.h" |
10 #include "SkSpecialSurface.h" | 10 #include "SkSpecialSurface.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 }; | 27 }; |
28 | 28 |
29 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise | 29 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise |
30 // the gpu's loose fit behavior | 30 // the gpu's loose fit behavior |
31 static const int kSmallerSize = 10; | 31 static const int kSmallerSize = 10; |
32 static const int kPad = 5; | 32 static const int kPad = 5; |
33 static const int kFullSize = kSmallerSize + 2 * kPad; | 33 static const int kFullSize = kSmallerSize + 2 * kPad; |
34 | 34 |
35 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho
t) | 35 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho
t) |
36 static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, i
nt offset) { | 36 static void test_surface(const sk_sp<SkSpecialSurface>& surf, |
| 37 skiatest::Reporter* reporter, |
| 38 int offset) { |
37 | 39 |
38 const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf); | 40 const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get()); |
39 REPORTER_ASSERT(reporter, offset == surfSubset.fLeft); | 41 REPORTER_ASSERT(reporter, offset == surfSubset.fLeft); |
40 REPORTER_ASSERT(reporter, offset == surfSubset.fTop); | 42 REPORTER_ASSERT(reporter, offset == surfSubset.fTop); |
41 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width()); | 43 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width()); |
42 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height()); | 44 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height()); |
43 | 45 |
44 SkCanvas* canvas = surf->getCanvas(); | 46 SkCanvas* canvas = surf->getCanvas(); |
45 SkASSERT_RELEASE(canvas); | 47 SkASSERT_RELEASE(canvas); |
46 | 48 |
47 canvas->clear(SK_ColorRED); | 49 canvas->clear(SK_ColorRED); |
48 | 50 |
49 SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot()); | 51 sk_sp<SkSpecialImage> img(surf->makeImageSnapshot()); |
50 REPORTER_ASSERT(reporter, img); | 52 REPORTER_ASSERT(reporter, img); |
51 | 53 |
52 const SkIRect imgSubset = TestingSpecialSurfaceAccess::Subset(img); | 54 const SkIRect imgSubset = TestingSpecialSurfaceAccess::Subset(img.get()); |
53 REPORTER_ASSERT(reporter, surfSubset == imgSubset); | 55 REPORTER_ASSERT(reporter, surfSubset == imgSubset); |
54 | 56 |
55 // the canvas was invalidated by the newImageSnapshot call | 57 // the canvas was invalidated by the newImageSnapshot call |
56 REPORTER_ASSERT(reporter, !surf->getCanvas()); | 58 REPORTER_ASSERT(reporter, !surf->getCanvas()); |
57 } | 59 } |
58 | 60 |
59 DEF_TEST(SpecialSurface_Raster, reporter) { | 61 DEF_TEST(SpecialSurface_Raster, reporter) { |
60 | 62 |
61 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_
SkAlphaType); | 63 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_
SkAlphaType); |
62 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRaster(nullptr, inf
o)); | 64 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRaster(nullptr, info)); |
63 | 65 |
64 test_surface(surf, reporter, 0); | 66 test_surface(surf, reporter, 0); |
65 } | 67 } |
66 | 68 |
67 DEF_TEST(SpecialSurface_Raster2, reporter) { | 69 DEF_TEST(SpecialSurface_Raster2, reporter) { |
68 | 70 |
69 SkBitmap bm; | 71 SkBitmap bm; |
70 bm.allocN32Pixels(kFullSize, kFullSize, true); | 72 bm.allocN32Pixels(kFullSize, kFullSize, true); |
71 | 73 |
72 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS
ize); | 74 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS
ize); |
73 | 75 |
74 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewFromBitmap(nullptr,
subset, bm)); | 76 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromBitmap(nullptr, subse
t, bm)); |
75 | 77 |
76 test_surface(surf, reporter, kPad); | 78 test_surface(surf, reporter, kPad); |
77 | 79 |
78 // TODO: check that the clear didn't escape the active region | 80 // TODO: check that the clear didn't escape the active region |
79 } | 81 } |
80 | 82 |
81 #if SK_SUPPORT_GPU | 83 #if SK_SUPPORT_GPU |
82 | 84 |
83 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) { | 85 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) { |
84 GrSurfaceDesc desc; | 86 GrSurfaceDesc desc; |
85 desc.fConfig = kSkia8888_GrPixelConfig; | 87 desc.fConfig = kSkia8888_GrPixelConfig; |
86 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 88 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
87 desc.fWidth = kSmallerSize; | 89 desc.fWidth = kSmallerSize; |
88 desc.fHeight = kSmallerSize; | 90 desc.fHeight = kSmallerSize; |
89 | 91 |
90 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRenderTarget(nullpt
r, context, desc)); | 92 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(nullptr, con
text, desc)); |
91 | 93 |
92 test_surface(surf, reporter, 0); | 94 test_surface(surf, reporter, 0); |
93 } | 95 } |
94 | 96 |
95 // test the more flexible factory | 97 // test the more flexible factory |
96 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) { | 98 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) { |
97 GrSurfaceDesc desc; | 99 GrSurfaceDesc desc; |
98 desc.fConfig = kSkia8888_GrPixelConfig; | 100 desc.fConfig = kSkia8888_GrPixelConfig; |
99 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 101 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
100 desc.fWidth = kFullSize; | 102 desc.fWidth = kFullSize; |
101 desc.fHeight = kFullSize; | 103 desc.fHeight = kFullSize; |
102 | 104 |
103 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture
(desc)); | 105 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture
(desc)); |
104 SkASSERT_RELEASE(temp); | 106 SkASSERT_RELEASE(temp); |
105 | 107 |
106 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS
ize); | 108 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS
ize); |
107 | 109 |
108 SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewFromTexture(nullptr
, subset, temp)); | 110 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromTexture(nullptr, subs
et, temp)); |
109 | 111 |
110 test_surface(surf, reporter, kPad); | 112 test_surface(surf, reporter, kPad); |
111 | 113 |
112 // TODO: check that the clear didn't escape the active region | 114 // TODO: check that the clear didn't escape the active region |
113 } | 115 } |
114 | 116 |
115 #endif | 117 #endif |
OLD | NEW |