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

Side by Side Diff: tests/SpecialSurfaceTest.cpp

Issue 1896383003: Begin removing deprecated (and now, unused) ImageFilter code paths (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 4 years, 8 months 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 unified diff | Download patch
« no previous file with comments | « tests/SpecialImageTest.cpp ('k') | tests/TestingSpecialImageAccess.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "SkGr.h" 15 #include "SkGr.h"
16 #endif 16 #endif
17 17
18 class TestingSpecialSurfaceAccess { 18 class TestingSpecialSurfaceAccess {
19 public: 19 public:
20 static const SkIRect& Subset(const SkSpecialSurface* surf) { 20 static const SkIRect& Subset(const SkSpecialSurface* surf) {
21 return surf->subset(); 21 return surf->subset();
22 } 22 }
23
24 static const SkIRect& Subset(const SkSpecialImage* img) {
25 return img->subset();
26 }
27 }; 23 };
28 24
29 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise 25 // Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise
30 // the gpu's loose fit behavior 26 // the gpu's loose fit behavior
31 static const int kSmallerSize = 10; 27 static const int kSmallerSize = 10;
32 static const int kPad = 5; 28 static const int kPad = 5;
33 static const int kFullSize = kSmallerSize + 2 * kPad; 29 static const int kFullSize = kSmallerSize + 2 * kPad;
34 30
35 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho t) 31 // Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapsho t)
36 static void test_surface(const sk_sp<SkSpecialSurface>& surf, 32 static void test_surface(const sk_sp<SkSpecialSurface>& surf,
37 skiatest::Reporter* reporter, 33 skiatest::Reporter* reporter,
38 int offset) { 34 int offset) {
39 35
40 const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get()); 36 const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get());
41 REPORTER_ASSERT(reporter, offset == surfSubset.fLeft); 37 REPORTER_ASSERT(reporter, offset == surfSubset.fLeft);
42 REPORTER_ASSERT(reporter, offset == surfSubset.fTop); 38 REPORTER_ASSERT(reporter, offset == surfSubset.fTop);
43 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width()); 39 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width());
44 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height()); 40 REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height());
45 41
46 SkCanvas* canvas = surf->getCanvas(); 42 SkCanvas* canvas = surf->getCanvas();
47 SkASSERT_RELEASE(canvas); 43 SkASSERT_RELEASE(canvas);
48 44
49 canvas->clear(SK_ColorRED); 45 canvas->clear(SK_ColorRED);
50 46
51 sk_sp<SkSpecialImage> img(surf->makeImageSnapshot()); 47 sk_sp<SkSpecialImage> img(surf->makeImageSnapshot());
52 REPORTER_ASSERT(reporter, img); 48 REPORTER_ASSERT(reporter, img);
53 49
54 const SkIRect imgSubset = TestingSpecialSurfaceAccess::Subset(img.get()); 50 const SkIRect imgSubset = img->subset();
55 REPORTER_ASSERT(reporter, surfSubset == imgSubset); 51 REPORTER_ASSERT(reporter, surfSubset == imgSubset);
56 52
57 // the canvas was invalidated by the newImageSnapshot call 53 // the canvas was invalidated by the newImageSnapshot call
58 REPORTER_ASSERT(reporter, !surf->getCanvas()); 54 REPORTER_ASSERT(reporter, !surf->getCanvas());
59 } 55 }
60 56
61 DEF_TEST(SpecialSurface_Raster, reporter) { 57 DEF_TEST(SpecialSurface_Raster, reporter) {
62 58
63 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_ SkAlphaType); 59 SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_ SkAlphaType);
64 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRaster(nullptr, info)); 60 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRaster(info));
65 61
66 test_surface(surf, reporter, 0); 62 test_surface(surf, reporter, 0);
67 } 63 }
68 64
69 DEF_TEST(SpecialSurface_Raster2, reporter) { 65 DEF_TEST(SpecialSurface_Raster2, reporter) {
70 66
71 SkBitmap bm; 67 SkBitmap bm;
72 bm.allocN32Pixels(kFullSize, kFullSize, true); 68 bm.allocN32Pixels(kFullSize, kFullSize, true);
73 69
74 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS ize); 70 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS ize);
75 71
76 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromBitmap(nullptr, subse t, bm)); 72 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromBitmap(subset, bm));
77 73
78 test_surface(surf, reporter, kPad); 74 test_surface(surf, reporter, kPad);
79 75
80 // TODO: check that the clear didn't escape the active region 76 // TODO: check that the clear didn't escape the active region
81 } 77 }
82 78
83 #if SK_SUPPORT_GPU 79 #if SK_SUPPORT_GPU
84 80
85 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) { 81 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) {
86 GrSurfaceDesc desc; 82 GrSurfaceDesc desc;
87 desc.fConfig = kSkia8888_GrPixelConfig; 83 desc.fConfig = kSkia8888_GrPixelConfig;
88 desc.fFlags = kRenderTarget_GrSurfaceFlag; 84 desc.fFlags = kRenderTarget_GrSurfaceFlag;
89 desc.fWidth = kSmallerSize; 85 desc.fWidth = kSmallerSize;
90 desc.fHeight = kSmallerSize; 86 desc.fHeight = kSmallerSize;
91 87
92 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(nullptr, ctx Info.fGrContext, 88 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.fGrC ontext, desc));
93 desc));
94 89
95 test_surface(surf, reporter, 0); 90 test_surface(surf, reporter, 0);
96 } 91 }
97 92
98 // test the more flexible factory 93 // test the more flexible factory
99 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, ctxInfo) { 94 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, ctxInfo) {
100 GrSurfaceDesc desc; 95 GrSurfaceDesc desc;
101 desc.fConfig = kSkia8888_GrPixelConfig; 96 desc.fConfig = kSkia8888_GrPixelConfig;
102 desc.fFlags = kRenderTarget_GrSurfaceFlag; 97 desc.fFlags = kRenderTarget_GrSurfaceFlag;
103 desc.fWidth = kFullSize; 98 desc.fWidth = kFullSize;
104 desc.fHeight = kFullSize; 99 desc.fHeight = kFullSize;
105 100
106 SkAutoTUnref<GrTexture> temp(ctxInfo.fGrContext->textureProvider()->createAp proxTexture(desc)); 101 SkAutoTUnref<GrTexture> temp(ctxInfo.fGrContext->textureProvider()->createAp proxTexture(desc));
107 SkASSERT_RELEASE(temp); 102 SkASSERT_RELEASE(temp);
108 103
109 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS ize); 104 const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerS ize);
110 105
111 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromTexture(nullptr, subs et, temp)); 106 sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeFromTexture(subset, temp) );
112 107
113 test_surface(surf, reporter, kPad); 108 test_surface(surf, reporter, kPad);
114 109
115 // TODO: check that the clear didn't escape the active region 110 // TODO: check that the clear didn't escape the active region
116 } 111 }
117 112
118 #endif 113 #endif
OLDNEW
« no previous file with comments | « tests/SpecialImageTest.cpp ('k') | tests/TestingSpecialImageAccess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698