OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 // This test is specific to the GPU backend. | 10 // This test is specific to the GPU backend. |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 | 12 |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "SkGpuDevice.h" | 14 #include "SkCanvas.h" |
| 15 #include "SkSurface.h" |
15 | 16 |
16 // This was made indivisible by 4 to ensure we test setting GL_PACK_ALIGNMENT pr
operly. | 17 // This was made indivisible by 4 to ensure we test setting GL_PACK_ALIGNMENT pr
operly. |
17 static const int X_SIZE = 13; | 18 static const int X_SIZE = 13; |
18 static const int Y_SIZE = 13; | 19 static const int Y_SIZE = 13; |
19 | 20 |
20 static void validate_alpha_data(skiatest::Reporter* reporter, int w, int h, cons
t uint8_t* actual, | 21 static void validate_alpha_data(skiatest::Reporter* reporter, int w, int h, cons
t uint8_t* actual, |
21 size_t actualRowBytes, const uint8_t* expected,
SkString extraMsg) { | 22 size_t actualRowBytes, const uint8_t* expected,
SkString extraMsg) { |
22 for (int y = 0; y < h; ++y) { | 23 for (int y = 0; y < h; ++y) { |
23 for (int x = 0; x < w; ++x) { | 24 for (int x = 0; x < w; ++x) { |
24 uint8_t a = actual[y * actualRowBytes + x]; | 25 uint8_t a = actual[y * actualRowBytes + x]; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 REPORTER_ASSERT_MESSAGE(reporter, result, "Initial A8 readPixels fai
led"); | 86 REPORTER_ASSERT_MESSAGE(reporter, result, "Initial A8 readPixels fai
led"); |
86 | 87 |
87 // make sure the original & read back versions match | 88 // make sure the original & read back versions match |
88 SkString msg; | 89 SkString msg; |
89 msg.printf("rt:%d, rb:%d A8", rt, SkToU32(rowBytes)); | 90 msg.printf("rt:%d, rb:%d A8", rt, SkToU32(rowBytes)); |
90 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZer
oRowBytes, | 91 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZer
oRowBytes, |
91 alphaData, msg); | 92 alphaData, msg); |
92 | 93 |
93 // Now try writing on the single channel texture (if we could create
as a RT). | 94 // Now try writing on the single channel texture (if we could create
as a RT). |
94 if (texture->asRenderTarget()) { | 95 if (texture->asRenderTarget()) { |
95 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 96 sk_sp<SkSurface> surf(SkSurface::MakeRenderTargetDirect(texture-
>asRenderTarget())); |
96 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create( | 97 SkCanvas* canvas = surf->getCanvas(); |
97 texture->asRenderTarget(), &props, SkGpuDevice::kUninit_Init
Contents)); | |
98 SkCanvas canvas(device); | |
99 | 98 |
100 SkPaint paint; | 99 SkPaint paint; |
101 | 100 |
102 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SI
ZE + 10); | 101 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SI
ZE + 10); |
103 | 102 |
104 paint.setColor(SK_ColorWHITE); | 103 paint.setColor(SK_ColorWHITE); |
105 | 104 |
106 canvas.drawRect(rect, paint); | 105 canvas->drawRect(rect, paint); |
107 | 106 |
108 memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); | 107 memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); |
109 result = texture->readPixels(0, 0, desc.fWidth, desc.fHeight, | 108 result = texture->readPixels(0, 0, desc.fWidth, desc.fHeight, |
110 desc.fConfig, readback.get(), rowBy
tes); | 109 desc.fConfig, readback.get(), rowBy
tes); |
111 REPORTER_ASSERT_MESSAGE(reporter, result, "A8 readPixels after c
lear failed"); | 110 REPORTER_ASSERT_MESSAGE(reporter, result, "A8 readPixels after c
lear failed"); |
112 | 111 |
113 match = true; | 112 match = true; |
114 for (int y = 0; y < Y_SIZE && match; ++y) { | 113 for (int y = 0; y < Y_SIZE && match; ++y) { |
115 for (int x = 0; x < X_SIZE && match; ++x) { | 114 for (int x = 0; x < X_SIZE && match; ++x) { |
116 uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x
]; | 115 uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x
]; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 SkString msg; | 182 SkString msg; |
184 msg.printf("rt:%d, rb:%d 8888", rt, SkToU32(rowBytes)); | 183 msg.printf("rt:%d, rb:%d 8888", rt, SkToU32(rowBytes)); |
185 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no
nZeroRowBytes, | 184 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no
nZeroRowBytes, |
186 alphaData, msg); | 185 alphaData, msg); |
187 } | 186 } |
188 } | 187 } |
189 } | 188 } |
190 } | 189 } |
191 | 190 |
192 #endif | 191 #endif |
OLD | NEW |