Skip to content

Commit 652124c

Browse files
bsalomonSkia Commit-Bot
authored and
Skia Commit-Bot
committed
sk_gpu_test::MakeTextureProxyFromData -> MakeTextureProxyViewFromData
Change-Id: Ie55a147566ef68a64e3b03d8cab701e54dbf1f0d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309780 Commit-Queue: Brian Salomon <[email protected]> Reviewed-by: Robert Phillips <[email protected]>
1 parent cab5886 commit 652124c

10 files changed

+50
-76
lines changed

gm/flippity.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,12 @@ static sk_sp<SkImage> make_reference_image(GrDirectContext* context,
132132

133133
auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
134134

135-
// TODO: make MakeTextureProxyFromData return a GrSurfaceProxyView
136-
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, origin,
137-
bm.info(), bm.getPixels(), bm.rowBytes());
138-
if (!proxy) {
135+
auto view = sk_gpu_test::MakeTextureProxyViewFromData(context, GrRenderable::kNo, origin,
136+
bm.info(), bm.getPixels(), bm.rowBytes());
137+
if (!view) {
139138
return nullptr;
140139
}
141140

142-
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
143-
GrColorType::kRGBA_8888);
144-
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
145141
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
146142
ii.colorType(), kOpaque_SkAlphaType, nullptr);
147143
}

tests/CopySurfaceTest.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
7878
for (const SkIRect& srcRect : kSrcRects) {
7979
for (const SkIPoint& dstPoint : kDstPoints) {
8080
for (const SkImageInfo& ii: kImageInfos) {
81-
auto src = sk_gpu_test::MakeTextureProxyFromData(
81+
auto srcView = sk_gpu_test::MakeTextureProxyViewFromData(
8282
dContext, sRenderable, sOrigin, ii, srcPixels.get(),
8383
kRowBytes);
84-
auto dst = sk_gpu_test::MakeTextureProxyFromData(
84+
auto dstView = sk_gpu_test::MakeTextureProxyViewFromData(
8585
dContext, dRenderable, dOrigin, ii, dstPixels.get(),
8686
kRowBytes);
8787

8888
// Should always work if the color type is RGBA, but may not work
8989
// for BGRA
9090
if (ii.colorType() == kRGBA_8888_SkColorType) {
91-
if (!src || !dst) {
91+
if (!srcView || !dstView) {
9292
ERRORF(reporter,
9393
"Could not create surfaces for copy surface test.");
9494
continue;
@@ -98,32 +98,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
9898
kBGRA_8888_SkColorType, GrRenderable::kNo).isValid()) {
9999
continue;
100100
}
101-
if (!src || !dst) {
101+
if (!srcView || !dstView) {
102102
ERRORF(reporter,
103103
"Could not create surfaces for copy surface test.");
104104
continue;
105105
}
106106
}
107107

108108
GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
109-
GrSwizzle dstSwizzle = dContext->priv().caps()->getReadSwizzle(
110-
dst->backendFormat(), grColorType);
111-
GrSurfaceProxyView dstView(std::move(dst), dOrigin, dstSwizzle);
112109
auto dstContext = GrSurfaceContext::Make(dContext,
113110
std::move(dstView),
114111
grColorType,
115112
ii.alphaType(), nullptr);
116113

117114
bool result = false;
118115
if (sOrigin == dOrigin) {
119-
result = dstContext->testCopy(src.get(), srcRect, dstPoint);
116+
result = dstContext->testCopy(srcView.proxy(),
117+
srcRect,
118+
dstPoint);
120119
} else if (dRenderable == GrRenderable::kYes) {
121120
SkASSERT(dstContext->asRenderTargetContext());
122-
GrSwizzle srcSwizzle = dContext->priv().caps()->getReadSwizzle(
123-
src->backendFormat(), grColorType);
124-
GrSurfaceProxyView view(std::move(src), sOrigin, srcSwizzle);
125121
result = dstContext->asRenderTargetContext()->blitTexture(
126-
std::move(view), srcRect, dstPoint);
122+
std::move(srcView), srcRect, dstPoint);
127123
}
128124

129125
bool expectedResult = true;

tests/FloatingPointTextureTest.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,16 @@ void runFPTest(skiatest::Reporter* reporter, GrDirectContext* dContext,
4949
}
5050

5151
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
52-
auto fpProxy = sk_gpu_test::MakeTextureProxyFromData(
52+
auto fpView = sk_gpu_test::MakeTextureProxyViewFromData(
5353
dContext, GrRenderable::kYes, origin,
54-
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
55-
controlPixelData.begin(), 0);
54+
{colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
55+
0);
5656
// Floating point textures are NOT supported everywhere
57-
if (!fpProxy) {
57+
if (!fpView) {
5858
continue;
5959
}
6060

61-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(fpProxy->backendFormat(),
62-
colorType);
63-
GrSurfaceProxyView view(std::move(fpProxy), origin, swizzle);
64-
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
61+
auto sContext = GrSurfaceContext::Make(dContext, std::move(fpView), colorType,
6562
kPremul_SkAlphaType, nullptr);
6663
REPORTER_ASSERT(reporter, sContext);
6764

@@ -70,7 +67,7 @@ void runFPTest(skiatest::Reporter* reporter, GrDirectContext* dContext,
7067
readBuffer.begin(), 0, {0, 0});
7168
REPORTER_ASSERT(reporter, result);
7269
REPORTER_ASSERT(reporter,
73-
0 == memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
70+
!memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.bytes()));
7471
}
7572
}
7673

tests/GrUploadPixelsTests.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
3232
FillPixelData(kWidth, kHeight, srcBuffer.get());
3333

3434
auto grCT = SkColorTypeToGrColorType(ct);
35-
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
35+
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
3636
dContext, renderable, kTopLeft_GrSurfaceOrigin,
3737
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
38-
REPORTER_ASSERT(reporter, proxy);
39-
if (proxy) {
40-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
41-
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
38+
REPORTER_ASSERT(reporter, view);
39+
if (view) {
4240
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
4341
nullptr);
4442

@@ -61,13 +59,11 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
6159
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 10, 2));
6260
}
6361

64-
proxy = sk_gpu_test::MakeTextureProxyFromData(
62+
view = sk_gpu_test::MakeTextureProxyViewFromData(
6563
dContext, renderable, kBottomLeft_GrSurfaceOrigin,
6664
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
67-
REPORTER_ASSERT(reporter, proxy);
68-
if (proxy) {
69-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
70-
GrSurfaceProxyView view(proxy, kBottomLeft_GrSurfaceOrigin, swizzle);
65+
REPORTER_ASSERT(reporter, view);
66+
if (view) {
7167
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType,
7268
nullptr);
7369

@@ -88,7 +84,6 @@ void basic_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
8884
REPORTER_ASSERT(reporter, result);
8985

9086
REPORTER_ASSERT(reporter, DoesFullBufferContainCorrectColor(srcBuffer, dstBuffer, 4, 5));
91-
9287
}
9388
}
9489

tests/PackedConfigsTextureTest.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,12 @@ static void run_test(skiatest::Reporter* reporter, GrDirectContext* dContext, in
115115

116116
for (auto origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
117117
auto grColorType = SkColorTypeToGrColorType(colorType);
118-
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
118+
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
119119
dContext, GrRenderable::kNo, origin,
120-
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H},
121-
controlPixelData.begin(), 0);
122-
SkASSERT(proxy);
120+
{grColorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, controlPixelData.begin(),
121+
0);
122+
SkASSERT(view);
123123

124-
GrSwizzle readSwizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
125-
grColorType);
126-
127-
GrSurfaceProxyView view(std::move(proxy), origin, readSwizzle);
128124
GrSurfaceContext sContext(dContext, std::move(view), grColorType, kPremul_SkAlphaType,
129125
nullptr);
130126

tests/ReadPixelsTest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
431431
// On the GPU we will also try reading back from a non-renderable texture.
432432
for (auto origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
433433
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
434-
sk_sp<GrTextureProxy> proxy = sk_gpu_test::MakeTextureProxyFromData(
434+
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
435435
dContext, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes());
436436
GrColorType grColorType = SkColorTypeToGrColorType(bmp.colorType());
437-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
438-
grColorType);
439-
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
440437
auto sContext = GrSurfaceContext::Make(dContext, std::move(view),
441438
grColorType, kPremul_SkAlphaType, nullptr);
442439
auto info = SkImageInfo::Make(DEV_W, DEV_H, kN32_SkColorType, kPremul_SkAlphaType);

tests/ReadWriteAlphaTest.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
186186

187187
auto origin = GrRenderable::kYes == renderable ? kBottomLeft_GrSurfaceOrigin
188188
: kTopLeft_GrSurfaceOrigin;
189-
auto proxy = sk_gpu_test::MakeTextureProxyFromData(
189+
auto view = sk_gpu_test::MakeTextureProxyViewFromData(
190190
dContext, renderable, origin,
191191
{info.fColorType, info.fAlphaType, nullptr, X_SIZE, Y_SIZE}, rgbaData, 0);
192-
if (!proxy) {
192+
if (!view) {
193193
continue;
194194
}
195195

196-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
197-
info.fColorType);
198-
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
199196
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), info.fColorType,
200197
kPremul_SkAlphaType, nullptr);
201198

tests/RectangleTextureTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ static void test_copy_to_surface(skiatest::Reporter* reporter,
102102

103103
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
104104
auto origin = dstContext->origin();
105-
auto src = sk_gpu_test::MakeTextureProxyFromData(
105+
auto srcView = sk_gpu_test::MakeTextureProxyViewFromData(
106106
dContext, renderable, origin,
107107
{GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, dstContext->width(),
108108
dstContext->height()},
109109
pixels.get(), 0);
110110
// If this assert ever fails we can add a fallback to do copy as draw, but until then we can
111111
// be more restrictive.
112-
SkAssertResult(dstContext->testCopy(src.get()));
112+
SkAssertResult(dstContext->testCopy(srcView.proxy()));
113113
TestReadPixels(reporter, dContext, dstContext, pixels.get(), testName);
114114
}
115115
}

tools/gpu/ProxyUtils.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121

2222
namespace sk_gpu_test {
2323

24-
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* dContext,
25-
GrRenderable renderable,
26-
GrSurfaceOrigin origin,
27-
const GrImageInfo& imageInfo,
28-
const void* data,
29-
size_t rowBytes) {
24+
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
25+
GrRenderable renderable,
26+
GrSurfaceOrigin origin,
27+
const GrImageInfo& imageInfo,
28+
const void* data,
29+
size_t rowBytes) {
3030
if (dContext->abandoned()) {
31-
return nullptr;
31+
return {};
3232
}
3333

3434
const GrCaps* caps = dContext->priv().caps();
3535

3636
const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
3737
if (!format.isValid()) {
38-
return nullptr;
38+
return {};
3939
}
4040
GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
4141

@@ -45,18 +45,18 @@ sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* dContext,
4545
SkBackingFit::kExact, SkBudgeted::kYes,
4646
GrProtected::kNo);
4747
if (!proxy) {
48-
return nullptr;
48+
return {};
4949
}
5050
GrSurfaceProxyView view(proxy, origin, swizzle);
5151
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
5252
imageInfo.alphaType(), imageInfo.refColorSpace());
5353
if (!sContext) {
54-
return nullptr;
54+
return {};
5555
}
5656
if (!sContext->writePixels(dContext, imageInfo, data, rowBytes, {0, 0})) {
57-
return nullptr;
57+
return {};
5858
}
59-
return proxy;
59+
return sContext->readSurfaceView();
6060
}
6161

6262
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,

tools/gpu/ProxyUtils.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class GrProgramInfo;
1919
namespace sk_gpu_test {
2020

2121
/** Makes a texture proxy containing the passed in color data. */
22-
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext*,
23-
GrRenderable,
24-
GrSurfaceOrigin,
25-
const GrImageInfo&,
26-
const void* data,
27-
size_t rowBytes);
22+
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext*,
23+
GrRenderable,
24+
GrSurfaceOrigin,
25+
const GrImageInfo&,
26+
const void* data,
27+
size_t rowBytes);
2828

2929
GrProgramInfo* CreateProgramInfo(const GrCaps*,
3030
SkArenaAlloc*,

0 commit comments

Comments
 (0)