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

Side by Side Diff: tests/ReadWriteAlphaTest.cpp

Issue 1448873002: Generate list of GPU contexts outside tests (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-01-gpu-test-context-support
Patch Set: make blurtest for all rendering contexts Created 5 years 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/ReadPixelsTest.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('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 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 && !defined(SK_BUILD_FOR_ANDROID) 11 #if SK_SUPPORT_GPU && !defined(SK_BUILD_FOR_ANDROID)
12 12
13 #include "GrContextFactory.h" 13 #include "GrContext.h"
14 #include "SkGpuDevice.h" 14 #include "SkGpuDevice.h"
15 15
16 static const int X_SIZE = 12; 16 static const int X_SIZE = 12;
17 static const int Y_SIZE = 12; 17 static const int Y_SIZE = 12;
18 18
19 DEF_GPUTEST(ReadWriteAlpha, reporter, factory) { 19 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
20 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 20 unsigned char textureData[X_SIZE][Y_SIZE];
21 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 21
22 if (!GrContextFactory::IsRenderingGLContext(glType)) { 22 memset(textureData, 0, X_SIZE * Y_SIZE);
23 continue; 23
24 GrSurfaceDesc desc;
25
26 // let Skia know we will be using this texture as a render target
27 desc.fFlags = kRenderTarget_GrSurfaceFlag;
28 // it is a single channel texture
29 desc.fConfig = kAlpha_8_GrPixelConfig;
30 desc.fWidth = X_SIZE;
31 desc.fHeight = Y_SIZE;
32
33 // We are initializing the texture with zeros here
34 GrTexture* texture = context->textureProvider()->createTexture(desc, false, textureData, 0);
35 if (!texture) {
36 return;
37 }
38
39 SkAutoTUnref<GrTexture> au(texture);
40
41 // create a distinctive texture
42 for (int y = 0; y < Y_SIZE; ++y) {
43 for (int x = 0; x < X_SIZE; ++x) {
44 textureData[x][y] = x*Y_SIZE+y;
24 } 45 }
25 GrContext* context = factory->get(glType); 46 }
26 if (nullptr == context) {
27 continue;
28 }
29 47
30 unsigned char textureData[X_SIZE][Y_SIZE]; 48 // upload the texture
49 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
50 textureData, 0);
31 51
32 memset(textureData, 0, X_SIZE * Y_SIZE); 52 unsigned char readback[X_SIZE][Y_SIZE];
33 53
34 GrSurfaceDesc desc; 54 // clear readback to something non-zero so we can detect readback failures
55 memset(readback, 0x1, X_SIZE * Y_SIZE);
35 56
36 // let Skia know we will be using this texture as a render target 57 // read the texture back
37 desc.fFlags = kRenderTarget_GrSurfaceFlag; 58 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
38 // it is a single channel texture 59 readback, 0);
39 desc.fConfig = kAlpha_8_GrPixelConfig;
40 desc.fWidth = X_SIZE;
41 desc.fHeight = Y_SIZE;
42 60
43 // We are initializing the texture with zeros here 61 // make sure the original & read back versions match
44 GrTexture* texture = context->textureProvider()->createTexture(desc, fal se, textureData, 0); 62 bool match = true;
45 if (!texture) {
46 return;
47 }
48 63
49 SkAutoTUnref<GrTexture> au(texture); 64 for (int y = 0; y < Y_SIZE; ++y) {
50 65 for (int x = 0; x < X_SIZE; ++x) {
51 // create a distinctive texture 66 if (textureData[x][y] != readback[x][y]) {
52 for (int y = 0; y < Y_SIZE; ++y) { 67 match = false;
53 for (int x = 0; x < X_SIZE; ++x) {
54 textureData[x][y] = x*Y_SIZE+y;
55 } 68 }
56 } 69 }
70 }
57 71
58 // upload the texture 72 REPORTER_ASSERT(reporter, match);
59 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
60 textureData, 0);
61 73
62 unsigned char readback[X_SIZE][Y_SIZE]; 74 // Now try writing on the single channel texture
75 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
76 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(texture->asRenderTarge t(), &props,
77 SkGpuDevice::kUninit_I nitContents));
78 SkCanvas canvas(device);
63 79
64 // clear readback to something non-zero so we can detect readback failur es 80 SkPaint paint;
65 memset(readback, 0x1, X_SIZE * Y_SIZE);
66 81
67 // read the texture back 82 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10);
68 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
69 readback, 0);
70 83
71 // make sure the original & read back versions match 84 paint.setColor(SK_ColorWHITE);
72 bool match = true;
73 85
74 for (int y = 0; y < Y_SIZE; ++y) { 86 canvas.drawRect(rect, paint);
75 for (int x = 0; x < X_SIZE; ++x) { 87
76 if (textureData[x][y] != readback[x][y]) { 88 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
77 match = false; 89 readback, 0);
78 } 90
91 match = true;
92
93 for (int y = 0; y < Y_SIZE; ++y) {
94 for (int x = 0; x < X_SIZE; ++x) {
95 if (0xFF != readback[x][y]) {
96 match = false;
79 } 97 }
80 } 98 }
99 }
81 100
82 REPORTER_ASSERT(reporter, match); 101 REPORTER_ASSERT(reporter, match);
83
84 // Now try writing on the single channel texture
85 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
86 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(texture->asRenderT arget(), &props,
87 SkGpuDevice::kUnin it_InitContents));
88 SkCanvas canvas(device);
89
90 SkPaint paint;
91
92 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10) ;
93
94 paint.setColor(SK_ColorWHITE);
95
96 canvas.drawRect(rect, paint);
97
98 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
99 readback, 0);
100
101 match = true;
102
103 for (int y = 0; y < Y_SIZE; ++y) {
104 for (int x = 0; x < X_SIZE; ++x) {
105 if (0xFF != readback[x][y]) {
106 match = false;
107 }
108 }
109 }
110
111 REPORTER_ASSERT(reporter, match);
112 }
113 } 102 }
114 103
115 #endif 104 #endif
OLDNEW
« no previous file with comments | « tests/ReadPixelsTest.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698