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

Side by Side Diff: tests/ImageNewShaderTest.cpp

Issue 1352293002: Revert[2] of add ImageShader, sharing code with its Bitmap cousin (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: undo change to test, check in Image_Gpu for nopt support Created 5 years, 3 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 | « src/image/SkImage_Raster.cpp ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkTypes.h" 8 #include "SkTypes.h"
9 #if SK_SUPPORT_GPU 9 #if SK_SUPPORT_GPU
10 #include "GrContextFactory.h" 10 #include "GrContextFactory.h"
11 #endif 11 #endif
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 16
17 #include "Test.h" 17 #include "Test.h"
18 18
19 void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& b m2) { 19 void testBitmapEquality(skiatest::Reporter* reporter, const SkBitmap& src, const SkBitmap& dst,
20 SkAutoLockPixels lockBm1(bm1); 20 const char label[]) {
21 SkAutoLockPixels lockBm2(bm2); 21 SkAutoLockPixels lockBm1(src);
22 SkAutoLockPixels lockBm2(dst);
22 23
23 REPORTER_ASSERT(reporter, bm1.getSize() == bm2.getSize()); 24 REPORTER_ASSERT(reporter, src.getSize() == dst.getSize());
24 REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1. getSize())); 25 if (memcmp(src.getPixels(), dst.getPixels(), dst.getSize())) {
26 SkDebugf("testBitmapEquality %s\n", label);
27 for (int y = 0; y < src.height(); ++y) {
28 for (int x = 0; x < src.width(); ++x) {
29 SkDebugf("(%d %d) src=%08X dst=%08X\n", x, y, src.getColor(x, y) , dst.getColor(x, y));
30 }
31 }
32 REPORTER_ASSERT(reporter, false);
33 }
25 } 34 }
26 35
27 void paintSource(SkSurface* sourceSurface) { 36 void paintSource(SkSurface* sourceSurface) {
28 SkCanvas* sourceCanvas = sourceSurface->getCanvas(); 37 SkCanvas* sourceCanvas = sourceSurface->getCanvas();
29 sourceCanvas->clear(0xFFDEDEDE); 38 sourceCanvas->clear(0xFFDEDEDE);
30 39
31 SkPaint paintColor; 40 SkPaint paintColor;
32 paintColor.setColor(0xFFFF0000); 41 paintColor.setColor(0xFFFF0000);
33 paintColor.setStyle(SkPaint::kFill_Style); 42 paintColor.setStyle(SkPaint::kFill_Style);
34 43
35 SkRect rect = SkRect::MakeXYWH( 44 SkRect rect = SkRect::MakeXYWH(
36 SkIntToScalar(1), 45 SkIntToScalar(1),
37 SkIntToScalar(0), 46 SkIntToScalar(0),
38 SkIntToScalar(1), 47 SkIntToScalar(1),
39 SkIntToScalar(sourceSurface->height())); 48 SkIntToScalar(sourceSurface->height()));
40 49
41 sourceCanvas->drawRect(rect, paintColor); 50 sourceCanvas->drawRect(rect, paintColor);
42 } 51 }
43 52
44 void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface, SkSur face* destinationSurface, SkImageInfo& info) { 53 void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface,
54 SkSurface* destinationSurface, SkImageInfo& info, const char label[]) {
45 paintSource(sourceSurface); 55 paintSource(sourceSurface);
46 56
47 SkAutoTUnref<SkImage> sourceImage(sourceSurface->newImageSnapshot()); 57 SkAutoTUnref<SkImage> sourceImage(sourceSurface->newImageSnapshot());
48 SkAutoTUnref<SkShader> sourceShader(sourceImage->newShader( 58 SkAutoTUnref<SkShader> sourceShader(sourceImage->newShader(
49 SkShader::kRepeat_TileMode, 59 SkShader::kRepeat_TileMode,
50 SkShader::kRepeat_TileMode)); 60 SkShader::kRepeat_TileMode));
51 61
52 SkPaint paint; 62 SkPaint paint;
53 paint.setShader(sourceShader); 63 paint.setShader(sourceShader);
54 64
55 SkCanvas* destinationCanvas = destinationSurface->getCanvas(); 65 SkCanvas* destinationCanvas = destinationSurface->getCanvas();
56 destinationCanvas->clear(SK_ColorTRANSPARENT); 66 destinationCanvas->clear(SK_ColorTRANSPARENT);
57 destinationCanvas->drawPaint(paint); 67 destinationCanvas->drawPaint(paint);
58 68
59 SkIRect rect = info.bounds(); 69 SkIRect rect = info.bounds();
60 70
61 SkBitmap bmOrig; 71 SkBitmap srcBM;
62 sourceSurface->getCanvas()->readPixels(rect, &bmOrig); 72 sourceSurface->getCanvas()->readPixels(rect, &srcBM);
63 73
64 74
65 SkBitmap bm; 75 SkBitmap dstBM;
66 destinationCanvas->readPixels(rect, &bm); 76 destinationCanvas->readPixels(rect, &dstBM);
67 77
68 testBitmapEquality(reporter, bmOrig, bm); 78 testBitmapEquality(reporter, srcBM, dstBM, label);
69 79
70 80
71 81
72 // Test with a translated shader 82 // Test with a translated shader
73 SkMatrix matrix; 83 SkMatrix matrix;
74 matrix.setTranslate(SkIntToScalar(-1), SkIntToScalar(0)); 84 matrix.setTranslate(SkIntToScalar(-1), SkIntToScalar(0));
75 85
76 SkAutoTUnref<SkShader> sourceShaderTranslated(sourceImage->newShader( 86 SkAutoTUnref<SkShader> sourceShaderTranslated(sourceImage->newShader(
77 SkShader::kRepeat_TileMode, 87 SkShader::kRepeat_TileMode,
78 SkShader::kRepeat_TileMode, 88 SkShader::kRepeat_TileMode,
79 &matrix)); 89 &matrix));
80 90
81 destinationCanvas->clear(SK_ColorTRANSPARENT); 91 destinationCanvas->clear(SK_ColorTRANSPARENT);
82 92
83 SkPaint paintTranslated; 93 SkPaint paintTranslated;
84 paintTranslated.setShader(sourceShaderTranslated); 94 paintTranslated.setShader(sourceShaderTranslated);
85 95
86 destinationCanvas->drawPaint(paintTranslated); 96 destinationCanvas->drawPaint(paintTranslated);
87 97
88 SkBitmap bmt; 98 SkBitmap bmt;
89 destinationCanvas->readPixels(rect, &bmt); 99 destinationCanvas->readPixels(rect, &bmt);
90 100
91 // Test correctness 101 // Test correctness
92 { 102 {
93 SkAutoLockPixels lockBm(bmt); 103 SkAutoLockPixels lockBm(bmt);
94 for (int y = 0; y < info.height(); y++) { 104 for (int y = 0; y < info.height(); y++) {
95 REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y)); 105 if (0xFFFF0000 != bmt.getColor(0, y)) {
106 SkDebugf("y = %d for %s\n", y, label);
107 REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y));
108 }
96 109
97 for (int x = 1; x < info.width(); x++) { 110 for (int x = 1; x < info.width(); x++) {
111 if (0xFFDEDEDE != bmt.getColor(x, y)) {
112 SkDebugf("(%d %d) color = %x for %s\n", x, y, bmt.getColor(x , y), label);
113 }
98 REPORTER_ASSERT(reporter, 0xFFDEDEDE == bmt.getColor(x, y)); 114 REPORTER_ASSERT(reporter, 0xFFDEDEDE == bmt.getColor(x, y));
99 } 115 }
100 } 116 }
101 } 117 }
102 } 118 }
103 119
104 DEF_TEST(ImageNewShader, reporter) { 120 DEF_TEST(ImageNewShader, reporter) {
105 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); 121 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
106 122
107 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info)); 123 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info));
108 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info)); 124 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info));
109 125
110 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info) ; 126 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info, "raster");
111 } 127 }
112 128
113 #if SK_SUPPORT_GPU 129 #if SK_SUPPORT_GPU
114 130
115 void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { 131 void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) {
132 // if we change these to 5,5, this fails on Nexus 7 w/ Tegra 3. See skbug.co m/4365
reed1 2015/09/21 21:02:06 Will remove this comment.
116 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); 133 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
117 134
118 SkAutoTUnref<SkSurface> sourceSurface( 135 SkAutoTUnref<SkSurface> sourceSurface(
119 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info)); 136 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info));
120 SkAutoTUnref<SkSurface> destinationSurface( 137 SkAutoTUnref<SkSurface> destinationSurface(
121 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info)); 138 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info));
122 139
123 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info) ; 140 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info, "gpu");
124 } 141 }
125 142
126 void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { 143 void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) {
127 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); 144 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
128 145
129 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRenderTarget(context, 146 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRenderTarget(context,
130 SkSurface::kNo_Budgeted, info)); 147 SkSurface::kNo_Budgeted, info));
131 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info)); 148 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info));
132 149
133 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info) ; 150 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info, "gpu-raster");
134 } 151 }
135 152
136 void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { 153 void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) {
137 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); 154 SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
138 155
139 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info)); 156 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info));
140 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRenderTarget(contex t, 157 SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRenderTarget(contex t,
141 SkSurface::kNo_Budgeted, info)); 158 SkSurface::kNo_Budgeted, info));
142 159
143 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info) ; 160 runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info, "raster-gpu");
144 } 161 }
145 162
146 DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) { 163 DEF_GPUTEST(ImageNewShader_GPU, reporter, factory) {
147 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 164 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
148 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 165 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
149 166
150 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 167 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
151 continue; 168 continue;
152 } 169 }
153 170
154 GrContext* context = factory->get(glCtxType); 171 GrContext* context = factory->get(glCtxType);
155 172
156 if (nullptr == context) { 173 if (nullptr == context) {
157 continue; 174 continue;
158 } 175 }
159 176
160 // GPU -> GPU 177 // GPU -> GPU
161 gpuToGpu(reporter, context); 178 gpuToGpu(reporter, context);
162 179
163 // GPU -> RASTER 180 // GPU -> RASTER
164 gpuToRaster(reporter, context); 181 gpuToRaster(reporter, context);
165 182
166 // RASTER -> GPU 183 // RASTER -> GPU
167 rasterToGpu(reporter, context); 184 rasterToGpu(reporter, context);
168 } 185 }
169 } 186 }
170 187
171 #endif 188 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698