Skip to content

Commit c95b589

Browse files
Adlai-HollerSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Reland "Migrate GrSurfaceContext readPixels to take direct context"
This reverts commit cf0d08e. Reason for revert: fix codegen Original change's description: > Revert "Migrate GrSurfaceContext readPixels to take direct context" > > This reverts commit d169e19. > > Reason for revert: broke chrome via code generator > > Original change's description: > > Migrate GrSurfaceContext readPixels to take direct context > > > > After this lands we'll proceed up the stack and add the direct > > context requirement to the public API and SkImage. > > > > Bug: skia:104662 > > Change-Id: I4b2d779a7fcd65eec68e631757821ac8e136ddba > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309044 > > Commit-Queue: Adlai Holler <[email protected]> > > Reviewed-by: Robert Phillips <[email protected]> > > [email protected],[email protected] > > Change-Id: I6126f2dca4bc902c903512ac486e22841cc472e5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309281 > Reviewed-by: Adlai Holler <[email protected]> > Commit-Queue: Adlai Holler <[email protected]> [email protected],[email protected] Bug: skia:104662 Change-Id: If899edab54d031a3619a4bbab90d13738679c037 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309319 Commit-Queue: Adlai Holler <[email protected]> Reviewed-by: Adlai Holler <[email protected]>
1 parent 5240e18 commit c95b589

32 files changed

+451
-381
lines changed

src/gpu/GrSurfaceContext.cpp

Lines changed: 85 additions & 86 deletions
Large diffs are not rendered by default.

src/gpu/GrSurfaceContext.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,35 @@ class GrSurfaceContext {
7575

7676
/**
7777
* Reads a rectangle of pixels from the render target context.
78+
* @param dContext The direct context to use
7879
* @param dstInfo image info for the destination
7980
* @param dst destination pixels for the read
8081
* @param rowBytes bytes in a row of 'dst'
8182
* @param srcPt offset w/in the surface context from which to read
82-
* @param direct The direct context to use. If null will use our GrRecordingContext if it
8383
* is a GrDirectContext and fail otherwise.
8484
*/
85-
bool readPixels(const GrImageInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt,
86-
GrDirectContext* direct = nullptr);
85+
bool readPixels(GrDirectContext* dContext,
86+
const GrImageInfo& dstInfo,
87+
void* dst,
88+
size_t rowBytes,
89+
SkIPoint srcPt);
8790

8891
using ReadPixelsCallback = SkImage::ReadPixelsCallback;
8992
using ReadPixelsContext = SkImage::ReadPixelsContext;
9093
using RescaleGamma = SkImage::RescaleGamma;
9194

9295
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixels.
93-
void asyncRescaleAndReadPixels(const SkImageInfo& info,
96+
void asyncRescaleAndReadPixels(GrDirectContext*,
97+
const SkImageInfo& info,
9498
const SkIRect& srcRect,
9599
RescaleGamma rescaleGamma,
96100
SkFilterQuality rescaleQuality,
97101
ReadPixelsCallback callback,
98-
ReadPixelsContext context);
102+
ReadPixelsContext callbackContext);
99103

100104
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixelsYUV420.
101-
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
105+
void asyncRescaleAndReadPixelsYUV420(GrDirectContext*,
106+
SkYUVColorSpace yuvColorSpace,
102107
sk_sp<SkColorSpace> dstColorSpace,
103108
const SkIRect& srcRect,
104109
SkISize dstSize,
@@ -110,15 +115,17 @@ class GrSurfaceContext {
110115
/**
111116
* Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the
112117
* renderTargetContext at the specified position.
118+
* @param dContext The direct context to use
113119
* @param srcInfo image info for the source pixels
114120
* @param src source for the write
115121
* @param rowBytes bytes in a row of 'src'
116122
* @param dstPt offset w/in the surface context at which to write
117-
* @param direct The direct context to use. If null will use our GrRecordingContext if it
118-
* is a GrDirectContext and fail otherwise.
119123
*/
120-
bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
121-
GrDirectContext* direct = nullptr);
124+
bool writePixels(GrDirectContext* dContext,
125+
const GrImageInfo& srcInfo,
126+
const void* src,
127+
size_t rowBytes,
128+
SkIPoint dstPt);
122129

123130
GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
124131
const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
@@ -204,10 +211,11 @@ class GrSurfaceContext {
204211
PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
205212

206213
// The async read step of asyncRescaleAndReadPixels()
207-
void asyncReadPixels(const SkIRect& rect,
208-
SkColorType colorType,
209-
ReadPixelsCallback callback,
210-
ReadPixelsContext context);
214+
void asyncReadPixels(GrDirectContext*,
215+
const SkIRect& srcRect,
216+
SkColorType,
217+
ReadPixelsCallback,
218+
ReadPixelsContext);
211219

212220
private:
213221
friend class GrSurfaceProxy; // for copy

src/gpu/SkGpuDevice.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,26 @@ sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(SkSpecialImage* srcImg,
183183
bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) {
184184
ASSERT_SINGLE_OWNER
185185

186-
if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
186+
// Context TODO: Elevate direct context requirement to public API
187+
auto dContext = fContext->asDirectContext();
188+
if (!dContext || !SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
187189
return false;
188190
}
189191

190-
return fRenderTargetContext->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), {x, y});
192+
return fRenderTargetContext->readPixels(dContext, pm.info(), pm.writable_addr(), pm.rowBytes(),
193+
{x, y});
191194
}
192195

193196
bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) {
194197
ASSERT_SINGLE_OWNER
195198

196-
if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
199+
// Context TODO: Elevate direct context requirement to public API
200+
auto dContext = fContext->asDirectContext();
201+
if (!dContext || !SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
197202
return false;
198203
}
199204

200-
return fRenderTargetContext->writePixels(pm.info(), pm.addr(), pm.rowBytes(), {x, y});
205+
return fRenderTargetContext->writePixels(dContext, pm.info(), pm.addr(), pm.rowBytes(), {x, y});
201206
}
202207

203208
bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {

src/gpu/effects/GrConfigConversionEffect.fp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ in fragmentProcessor inputFP;
1616
}
1717

1818
@class {
19-
static bool TestForPreservingPMConversions(GrDirectContext* context);
19+
static bool TestForPreservingPMConversions(GrDirectContext* dContext);
2020
}
2121

2222
@cppEnd {
23-
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* context) {
23+
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
2424
static constexpr int kSize = 256;
2525
static constexpr GrColorType kColorType = GrColorType::kRGBA_8888;
2626
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
@@ -47,9 +47,9 @@ in fragmentProcessor inputFP;
4747
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
4848

4949
auto readRTC = GrRenderTargetContext::Make(
50-
context, kColorType, nullptr, SkBackingFit::kExact, {kSize, kSize});
50+
dContext, kColorType, nullptr, SkBackingFit::kExact, {kSize, kSize});
5151
auto tempRTC = GrRenderTargetContext::Make(
52-
context, kColorType, nullptr, SkBackingFit::kExact, {kSize, kSize});
52+
dContext, kColorType, nullptr, SkBackingFit::kExact, {kSize, kSize});
5353
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
5454
return false;
5555
}
@@ -64,7 +64,7 @@ in fragmentProcessor inputFP;
6464
bitmap.installPixels(ii, srcData, 4 * kSize);
6565
bitmap.setImmutable();
6666

67-
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
67+
GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
6868
auto dataView = maker.view(GrMipmapped::kNo);
6969
if (!dataView) {
7070
return false;
@@ -83,7 +83,7 @@ in fragmentProcessor inputFP;
8383
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
8484

8585
readRTC->fillRectToRect(nullptr, std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, kRect);
86-
if (!readRTC->readPixels(ii, firstRead, 0, {0, 0})) {
86+
if (!readRTC->readPixels(dContext, ii, firstRead, 0, {0, 0})) {
8787
return false;
8888
}
8989

@@ -107,7 +107,7 @@ in fragmentProcessor inputFP;
107107

108108
readRTC->fillRectToRect(nullptr, std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, kRect);
109109

110-
if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) {
110+
if (!readRTC->readPixels(dContext, ii, secondRead, 0, {0, 0})) {
111111
return false;
112112
}
113113

src/gpu/effects/generated/GrConfigConversionEffect.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
2828
(void)pmConversion;
2929

3030
fragBuilder->forceHighPrecision();
31-
SkString _sample5748 = this->invokeChild(0, args);
31+
SkString _sample5773 = this->invokeChild(0, args);
3232
fragBuilder->codeAppendf(
3333
R"SkSL(%s = floor(%s * 255.0 + 0.5) / 255.0;
3434
@switch (%d) {
@@ -40,7 +40,7 @@ class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
4040
break;
4141
}
4242
)SkSL",
43-
args.fOutputColor, _sample5748.c_str(), (int)_outer.pmConversion, args.fOutputColor,
43+
args.fOutputColor, _sample5773.c_str(), (int)_outer.pmConversion, args.fOutputColor,
4444
args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor,
4545
args.fOutputColor, args.fOutputColor);
4646
}
@@ -86,7 +86,7 @@ std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(
8686
}
8787
#endif
8888

89-
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* context) {
89+
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
9090
static constexpr int kSize = 256;
9191
static constexpr GrColorType kColorType = GrColorType::kRGBA_8888;
9292
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
@@ -112,9 +112,9 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* c
112112
const SkImageInfo ii =
113113
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
114114

115-
auto readRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
115+
auto readRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
116116
{kSize, kSize});
117-
auto tempRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
117+
auto tempRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
118118
{kSize, kSize});
119119
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
120120
return false;
@@ -130,7 +130,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* c
130130
bitmap.installPixels(ii, srcData, 4 * kSize);
131131
bitmap.setImmutable();
132132

133-
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
133+
GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
134134
auto dataView = maker.view(GrMipmapped::kNo);
135135
if (!dataView) {
136136
return false;
@@ -149,7 +149,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* c
149149
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
150150

151151
readRTC->fillRectToRect(nullptr, std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, kRect);
152-
if (!readRTC->readPixels(ii, firstRead, 0, {0, 0})) {
152+
if (!readRTC->readPixels(dContext, ii, firstRead, 0, {0, 0})) {
153153
return false;
154154
}
155155

@@ -173,7 +173,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* c
173173

174174
readRTC->fillRectToRect(nullptr, std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, kRect);
175175

176-
if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) {
176+
if (!readRTC->readPixels(dContext, ii, secondRead, 0, {0, 0})) {
177177
return false;
178178
}
179179

src/gpu/effects/generated/GrConfigConversionEffect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class GrConfigConversionEffect : public GrFragmentProcessor {
2626
public:
27-
static bool TestForPreservingPMConversions(GrDirectContext* context);
27+
static bool TestForPreservingPMConversions(GrDirectContext* dContext);
2828

2929
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp,
3030
PMConversion pmConversion) {

src/gpu/text/GrAtlasManager.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,26 @@ void GrAtlasManager::addGlyphToBulkAndSetUseToken(GrDrawOpAtlas::BulkUseTokenUpd
219219
* Write the contents of the surface proxy to a PNG. Returns true if successful.
220220
* @param filename Full path to desired file
221221
*/
222-
static bool save_pixels(GrDirectContext* context, GrSurfaceProxyView view, GrColorType colorType,
222+
static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrColorType colorType,
223223
const char* filename) {
224224
if (!view.proxy()) {
225225
return false;
226226
}
227227

228-
SkImageInfo ii =
229-
SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
230-
kPremul_SkAlphaType);
228+
auto ii = SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
229+
kPremul_SkAlphaType);
231230
SkBitmap bm;
232231
if (!bm.tryAllocPixels(ii)) {
233232
return false;
234233
}
235234

236-
auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
235+
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
237236
kUnknown_SkAlphaType, nullptr);
238237
if (!sContext || !sContext->asTextureProxy()) {
239238
return false;
240239
}
241240

242-
bool result = sContext->readPixels(ii, bm.getPixels(), bm.rowBytes(), {0, 0});
241+
bool result = sContext->readPixels(dContext, ii, bm.getPixels(), bm.rowBytes(), {0, 0});
243242
if (!result) {
244243
SkDebugf("------ failed to read pixels for %s\n", filename);
245244
return false;

src/image/SkImage_Gpu.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,21 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info,
126126
SkFilterQuality rescaleQuality,
127127
ReadPixelsCallback callback,
128128
ReadPixelsContext context) {
129+
auto dContext = fContext->asDirectContext();
130+
if (!dContext) {
131+
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
132+
callback(context, nullptr);
133+
return;
134+
}
129135
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
130-
auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
136+
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
131137
this->refColorSpace());
132138
if (!ctx) {
133139
callback(context, nullptr);
134140
return;
135141
}
136-
ctx->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
142+
ctx->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleQuality,
143+
callback, context);
137144
}
138145

139146
void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -144,14 +151,21 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpac
144151
SkFilterQuality rescaleQuality,
145152
ReadPixelsCallback callback,
146153
ReadPixelsContext context) {
154+
auto dContext = fContext->asDirectContext();
155+
if (!dContext) {
156+
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
157+
callback(context, nullptr);
158+
return;
159+
}
147160
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
148-
auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
161+
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
149162
this->refColorSpace());
150163
if (!ctx) {
151164
callback(context, nullptr);
152165
return;
153166
}
154-
ctx->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
167+
ctx->asyncRescaleAndReadPixelsYUV420(dContext,
168+
yuvColorSpace,
155169
std::move(dstColorSpace),
156170
srcRect,
157171
dstSize,
@@ -660,13 +674,13 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
660674
return nullptr;
661675
}
662676

663-
auto direct = GrAsDirectContext(context);
664-
if (!direct) {
677+
auto dContext = GrAsDirectContext(context);
678+
if (!dContext) {
665679
SkDebugf("Direct context required\n");
666680
return nullptr;
667681
}
668682

669-
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(direct,
683+
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
670684
hardwareBuffer,
671685
bufferDesc.format,
672686
true);
@@ -680,7 +694,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
680694
GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr;
681695

682696
GrBackendTexture backendTexture =
683-
GrAHardwareBufferUtils::MakeBackendTexture(direct, hardwareBuffer,
697+
GrAHardwareBufferUtils::MakeBackendTexture(dContext, hardwareBuffer,
684698
bufferDesc.width, bufferDesc.height,
685699
&deleteImageProc, &updateImageProc,
686700
&deleteImageCtx, false, backendFormat, true);
@@ -697,7 +711,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
697711

698712
GrColorType grColorType = SkColorTypeToGrColorType(colorType);
699713

700-
GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
714+
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
701715
if (!proxyProvider) {
702716
return nullptr;
703717
}
@@ -712,26 +726,26 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
712726
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
713727
SkAlphaType at = pixmap.alphaType();
714728

715-
GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(backendFormat, grColorType);
729+
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
716730
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
717-
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, view,
731+
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), kNeedNewImageUniqueID, view,
718732
colorType, at, cs);
719733
if (!image) {
720734
return nullptr;
721735
}
722736

723-
GrDrawingManager* drawingManager = direct->priv().drawingManager();
737+
GrDrawingManager* drawingManager = dContext->priv().drawingManager();
724738
if (!drawingManager) {
725739
return nullptr;
726740
}
727741

728-
GrSurfaceContext surfaceContext(direct, std::move(view),
742+
GrSurfaceContext surfaceContext(dContext, std::move(view),
729743
SkColorTypeToGrColorType(pixmap.colorType()),
730744
pixmap.alphaType(), cs);
731745

732746
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
733747
std::move(cs));
734-
surfaceContext.writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
748+
surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
735749

736750
GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()};
737751
drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);

0 commit comments

Comments
 (0)