Flutter Engine
The Flutter Engine
Functions
CopySurfaceTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/base/SkTemplates.h"
#include "src/core/SkMemset.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/SurfaceFillContext.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ProxyUtils.h"
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <memory>
#include <utility>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (CopySurface, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( CopySurface  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 40 of file CopySurfaceTest.cpp.

43 {
44 auto dContext = ctxInfo.directContext();
45
46 static const int kW = 10;
47 static const int kH = 10;
48 static const size_t kRowBytes = sizeof(uint32_t) * kW;
49
50 AutoTMalloc<uint32_t> srcPixels(kW * kH);
51 for (int i = 0; i < kW * kH; ++i) {
52 srcPixels.get()[i] = i;
53 }
54
55 AutoTMalloc<uint32_t> dstPixels(kW * kH);
56 for (int i = 0; i < kW * kH; ++i) {
57 dstPixels.get()[i] = ~i;
58 }
59
60 static const SkIRect kSrcRects[] {
61 { 0, 0, kW , kH },
62 {-1, -1, kW+1, kH+1},
63 { 1, 1, kW-1, kH-1},
64 { 5, 5, 6 , 6 },
65 };
66
67 static const SkIPoint kDstPoints[] {
68 { 0 , 0 },
69 { 1 , 1 },
70 { kW/2, kH/4},
71 { kW-1, kH-1},
72 { kW , kH },
73 { kW+1, kH+2},
74 {-1 , -1 },
75 };
76
77 static const SkImageInfo kImageInfos[] {
80 };
81
83
86 for (auto sRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
87 for (auto dRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
88 for (const SkIRect& srcRect : kSrcRects) {
89 for (const SkIPoint& dstPoint : kDstPoints) {
90 for (const SkImageInfo& ii: kImageInfos) {
91 GrCPixmap srcPM(ii, srcPixels.get(), kRowBytes);
92 GrPixmap dstPM(ii, dstPixels.get(), kRowBytes);
94 dContext, sRenderable, sOrigin, srcPM);
96 dContext, dRenderable, dOrigin, dstPM);
97
98 // Should always work if the color type is RGBA, but may not work
99 // for BGRA
100 if (ii.colorType() == kRGBA_8888_SkColorType) {
101 if (!srcView || !dstView) {
103 "Could not create surfaces for copy surface test.");
104 continue;
105 }
106 } else {
107 if (!dContext->defaultBackendFormat(
109 continue;
110 }
111 if (!srcView || !dstView) {
113 "Could not create surfaces for copy surface test.");
114 continue;
115 }
116 }
117
118 auto dstContext = dContext->priv().makeSC(std::move(dstView),
119 ii.colorInfo());
120
121 bool result = false;
122 if (sOrigin == dOrigin) {
123 result = dstContext->testCopy(srcView.refProxy(),
124 srcRect,
125 dstPoint);
126 } else if (dRenderable == GrRenderable::kYes) {
127 SkASSERT(dstContext->asFillContext());
128 result = dstContext->asFillContext()->blitTexture(
129 std::move(srcView), srcRect, dstPoint);
130 }
131
132 bool expectedResult = true;
133 SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft,
134 dstPoint.fY - srcRect.fTop };
135 SkIRect copiedDstRect = SkIRect::MakeXYWH(dstPoint.fX,
136 dstPoint.fY,
137 srcRect.width(),
138 srcRect.height());
139
140 SkIRect copiedSrcRect;
141 if (!copiedSrcRect.intersect(srcRect, SkIRect::MakeWH(kW, kH))) {
142 expectedResult = false;
143 } else {
144 // If the src rect was clipped, apply same clipping to each side
145 // of copied dst rect.
146 copiedDstRect.fLeft += copiedSrcRect.fLeft - srcRect.fLeft;
147 copiedDstRect.fTop += copiedSrcRect.fTop - srcRect.fTop;
148 copiedDstRect.fRight -= copiedSrcRect.fRight - srcRect.fRight;
149 copiedDstRect.fBottom -= copiedSrcRect.fBottom -
150 srcRect.fBottom;
151 }
152 if (copiedDstRect.isEmpty() ||
153 !copiedDstRect.intersect(SkIRect::MakeWH(kW, kH))) {
154 expectedResult = false;
155 }
156 if (sOrigin != dOrigin && dRenderable == GrRenderable::kNo) {
157 expectedResult = false;
158 }
159
160 // To make the copied src rect correct we would apply any dst
161 // clipping back to the src rect, but we don't use it again so
162 // don't bother.
163 if (expectedResult != result) {
164 ERRORF(reporter, "Expected return value %d from copySurface, "
165 "got %d.", expectedResult, result);
166 continue;
167 }
168
169 if (!expectedResult || !result) {
170 continue;
171 }
172
173 SkOpts::memset32(read.get(), 0, kW * kH);
174 GrPixmap readPM(ii, read.get(), kRowBytes);
175 if (!dstContext->readPixels(dContext, readPM, {0, 0})) {
176 ERRORF(reporter, "Error calling readPixels");
177 continue;
178 }
179
180 bool abort = false;
181 // Validate that pixels inside copiedDstRect received the correct
182 // value from src and that those outside were not modified.
183 for (int y = 0; y < kH && !abort; ++y) {
184 for (int x = 0; x < kW; ++x) {
185 uint32_t r = read.get()[y * kW + x];
186 if (copiedDstRect.contains(x, y)) {
187 int sx = x - dstOffset.fX;
188 int sy = y - dstOffset.fY;
189 uint32_t s = srcPixels.get()[sy * kW + sx];
190 if (s != r) {
191 ERRORF(reporter, "Expected dst %d,%d to contain "
192 "0x%08x copied from src location %d,%d. Got "
193 "0x%08x", x, y, s, sx, sy, r);
194 abort = true;
195 break;
196 }
197 } else {
198 uint32_t d = dstPixels.get()[y * kW + x];
199 if (d != r) {
200 ERRORF(reporter, "Expected dst %d,%d to be "
201 "unmodified (0x%08x). Got 0x%08x",
202 x, y, d, r);
203 abort = true;
204 break;
205 }
206 }
207 }
208 }
209 }
210 }
211 }
212 }
213 }
214 }
215 }
216}
reporter
Definition: FontMgrTest.cpp:39
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
static bool read(SkStream *stream, void *buffer, size_t amount)
#define ERRORF(r,...)
Definition: Test.h:293
constexpr int kH
constexpr int kW
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
struct MyStruct s
GAsyncResult * result
double y
double x
void(* memset32)(uint32_t[], uint32_t, int)
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext *dContext, GrRenderable renderable, GrSurfaceOrigin origin, GrCPixmap pixmap)
Definition: ProxyUtils.cpp:56
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30
Definition: SkRect.h:32
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
bool isEmpty() const
Definition: SkRect.h:202
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)