OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Test.h" | |
9 | |
10 #if SK_SUPPORT_GPU | |
11 #include "GrContext.h" | |
12 #include "GrTexture.h" | |
13 #include "GrTextureProvider.h" | |
14 | |
15 #include "SkUtils.h" | |
16 | |
17 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, context) { | |
18 static const int kW = 10; | |
19 static const int kH = 10; | |
20 static const size_t kRowBytes = sizeof(uint32_t) * kW; | |
21 | |
22 GrSurfaceDesc baseDesc; | |
23 baseDesc.fConfig = kRGBA_8888_GrPixelConfig; | |
24 baseDesc.fWidth = kW; | |
25 baseDesc.fHeight = kH; | |
26 | |
27 SkAutoTMalloc<uint32_t> srcPixels(kW * kH); | |
28 for (int i = 0; i < kW * kH; ++i) { | |
29 srcPixels.get()[i] = i; | |
30 } | |
31 | |
32 SkAutoTMalloc<uint32_t> dstPixels(kW * kH); | |
robertphillips
2016/02/11 18:31:29
Is this memset useful ?
bsalomon
2016/02/11 18:49:11
Nope, leftover from earlier iteration of this test
| |
33 sk_memset32(dstPixels.get(), 0, kW * kH); | |
34 for (int i = 0; i < kW * kH; ++i) { | |
35 dstPixels.get()[i] = ~i; | |
36 } | |
37 | |
38 static const SkIRect kSrcRects[] { | |
39 { 0, 0, kW , kH }, | |
40 {-1, -1, kW+1, kH+1}, | |
41 { 1, 1, kW-1, kH-1}, | |
42 { 5, 5, 6 , 6 }, | |
43 }; | |
44 | |
45 static const SkIPoint kDstPoints[] { | |
46 { 0 , 0 }, | |
47 { 1 , 1 }, | |
48 { kW/2, kH/4}, | |
49 { kW-1, kH-1}, | |
50 { kW , kH }, | |
51 { kW+1, kH+2}, | |
52 {-1 , -1 }, | |
53 }; | |
54 | |
55 SkAutoTMalloc<uint32_t> read(kW * kH); | |
56 | |
57 for (auto sOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { | |
58 for (auto dOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrig in}) { | |
59 for (auto sFlags: {kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { | |
60 for (auto dFlags: {kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceF lags}) { | |
61 for (auto srcRect : kSrcRects) { | |
62 for (auto dstPoint : kDstPoints) { | |
63 GrSurfaceDesc srcDesc = baseDesc; | |
64 srcDesc.fOrigin = sOrigin; | |
65 srcDesc.fFlags = sFlags; | |
66 GrSurfaceDesc dstDesc = baseDesc; | |
67 dstDesc.fOrigin = dOrigin; | |
68 dstDesc.fFlags = dFlags; | |
69 | |
70 SkAutoTUnref<GrTexture> src( | |
71 context->textureProvider()->createTexture(srcDes c, false, | |
72 srcPix els.get(), | |
73 kRowBy tes)); | |
74 SkAutoTUnref<GrTexture> dst( | |
75 context->textureProvider()->createTexture(dstDes c, false, | |
76 dstPix els.get(), | |
77 kRowBy tes)); | |
78 if (!src || !dst) { | |
79 ERRORF(reporter, | |
80 "Could not create surfaces for copy surfa ce test."); | |
81 continue; | |
82 } | |
83 | |
84 bool result = context->copySurface(dst, src, srcRect , dstPoint); | |
85 | |
86 bool expectedResult = true; | |
87 SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft, | |
88 dstPoint.fY - srcRect.fTop }; | |
89 | |
90 SkIRect copiedSrcRect; | |
91 if (!copiedSrcRect.intersect(srcRect, SkIRect::MakeW H(kW, kH))) { | |
92 expectedResult = false; | |
93 } | |
94 SkIRect copiedDstRect = SkIRect::MakeXYWH(dstPoint.f X, | |
95 dstPoint.f Y, | |
96 srcRect.wi dth(), | |
97 srcRect.he ight()); | |
98 // If the src rect was clipped, apply same clipping to each side of | |
99 // copied dst rect. | |
100 copiedDstRect.fLeft += copiedSrcRect.fLeft - srcRect .fLeft; | |
101 copiedDstRect.fTop += copiedSrcRect.fTop - srcRect.f Top; | |
102 copiedDstRect.fRight -= copiedSrcRect.fRight - srcRe ct.fRight; | |
103 copiedDstRect.fBottom -= copiedSrcRect.fBottom - src Rect.fBottom; | |
104 if (copiedDstRect.isEmpty() || | |
105 !copiedDstRect.intersect(SkIRect::MakeWH(kW, kH) )) { | |
106 expectedResult = false; | |
107 } | |
108 // To make the copied src rect correct we would appl y any dst clipping | |
109 // back to the src rect, but we don't use it again s o don't bother. | |
110 if (expectedResult != result) { | |
111 ERRORF(reporter, "Expected return value %d from copySurface, got " | |
112 "%d.", expectedResult, result); | |
113 continue; | |
114 } | |
115 | |
116 if (!expectedResult || !result) { | |
117 continue; | |
118 } | |
119 | |
120 sk_memset32(read.get(), 0, kW * kH); | |
121 if (!dst->readPixels(0, 0, kW, kH, baseDesc.fConfig, read.get(), | |
122 kRowBytes)) { | |
123 ERRORF(reporter, "Error calling readPixels"); | |
124 continue; | |
125 } | |
126 | |
127 bool abort = false; | |
128 // Validate that pixels inside copiedDstRect receive d the correct value | |
129 // from src and that those outside were not modified . | |
130 for (int y = 0; y < kH && !abort; ++y) { | |
131 for (int x = 0; x < kW; ++x) { | |
132 uint32_t r = read.get()[y * kW + x]; | |
133 if (copiedDstRect.contains(x, y)) { | |
134 int sx = x - dstOffset.fX; | |
135 int sy = y - dstOffset.fY; | |
136 uint32_t s = srcPixels.get()[sy * kW + s x]; | |
137 if (s != r) { | |
138 ERRORF(reporter, "Expected dst %d,%d to contain " | |
139 "0x%08x copied from src locat ion %d,%d. Got " | |
140 "0x%08x", x, y, s, sx, sy, r) ; | |
141 abort = true; | |
142 break; | |
143 } | |
144 } else { | |
145 uint32_t d = dstPixels.get()[y * kW + x] ; | |
146 if (d != r) { | |
147 ERRORF(reporter, "Expected dst %d,%d to be unmodified (" | |
148 "0x%08x). Got 0x%08x", x, y, d, r); | |
149 abort = true; | |
150 break; | |
151 } | |
152 } | |
153 } | |
154 } | |
155 } | |
156 } | |
157 } | |
158 } | |
159 } | |
160 } | |
161 } | |
162 #endif | |
OLD | NEW |