Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cf0d08e

Browse files
Adlai-HollerSkia Commit-Bot
authored andcommitted
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]>
1 parent 109ff20 commit cf0d08e

30 files changed

+371
-441
lines changed

src/gpu/GrSurfaceContext.cpp

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

src/gpu/GrSurfaceContext.h

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

7676
/**
7777
* Reads a rectangle of pixels from the render target context.
78-
* @param dContext The direct context to use
7978
* @param dstInfo image info for the destination
8079
* @param dst destination pixels for the read
8180
* @param rowBytes bytes in a row of 'dst'
8281
* @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(GrDirectContext* dContext,
86-
const GrImageInfo& dstInfo,
87-
void* dst,
88-
size_t rowBytes,
89-
SkIPoint srcPt);
85+
bool readPixels(const GrImageInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt,
86+
GrDirectContext* direct = nullptr);
9087

9188
using ReadPixelsCallback = SkImage::ReadPixelsCallback;
9289
using ReadPixelsContext = SkImage::ReadPixelsContext;
9390
using RescaleGamma = SkImage::RescaleGamma;
9491

9592
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixels.
96-
void asyncRescaleAndReadPixels(GrDirectContext*,
97-
const SkImageInfo& info,
93+
void asyncRescaleAndReadPixels(const SkImageInfo& info,
9894
const SkIRect& srcRect,
9995
RescaleGamma rescaleGamma,
10096
SkFilterQuality rescaleQuality,
10197
ReadPixelsCallback callback,
102-
ReadPixelsContext callbackContext);
98+
ReadPixelsContext context);
10399

104100
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixelsYUV420.
105-
void asyncRescaleAndReadPixelsYUV420(GrDirectContext*,
106-
SkYUVColorSpace yuvColorSpace,
101+
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
107102
sk_sp<SkColorSpace> dstColorSpace,
108103
const SkIRect& srcRect,
109104
SkISize dstSize,
@@ -115,17 +110,15 @@ class GrSurfaceContext {
115110
/**
116111
* Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the
117112
* renderTargetContext at the specified position.
118-
* @param dContext The direct context to use
119113
* @param srcInfo image info for the source pixels
120114
* @param src source for the write
121115
* @param rowBytes bytes in a row of 'src'
122116
* @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.
123119
*/
124-
bool writePixels(GrDirectContext* dContext,
125-
const GrImageInfo& srcInfo,
126-
const void* src,
127-
size_t rowBytes,
128-
SkIPoint dstPt);
120+
bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
121+
GrDirectContext* direct = nullptr);
129122

130123
GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
131124
const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
@@ -211,11 +204,10 @@ class GrSurfaceContext {
211204
PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
212205

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

220212
private:
221213
friend class GrSurfaceProxy; // for copy

src/gpu/SkGpuDevice.cpp

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

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

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

196193
bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) {
197194
ASSERT_SINGLE_OWNER
198195

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

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

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

src/gpu/effects/generated/GrConfigConversionEffect.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(
8181
}
8282
#endif
8383

84-
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
84+
bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* context) {
8585
static constexpr int kSize = 256;
8686
static constexpr GrColorType kColorType = GrColorType::kRGBA_8888;
8787
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
@@ -107,9 +107,9 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* d
107107
const SkImageInfo ii =
108108
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
109109

110-
auto readRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
110+
auto readRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
111111
{kSize, kSize});
112-
auto tempRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
112+
auto tempRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
113113
{kSize, kSize});
114114
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
115115
return false;
@@ -125,7 +125,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* d
125125
bitmap.installPixels(ii, srcData, 4 * kSize);
126126
bitmap.setImmutable();
127127

128-
GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
128+
GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
129129
auto dataView = maker.view(GrMipmapped::kNo);
130130
if (!dataView) {
131131
return false;
@@ -144,7 +144,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* d
144144
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
145145

146146
readRTC->fillRectToRect(nullptr, std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, kRect);
147-
if (!readRTC->readPixels(dContext, ii, firstRead, 0, {0, 0})) {
147+
if (!readRTC->readPixels(ii, firstRead, 0, {0, 0})) {
148148
return false;
149149
}
150150

@@ -168,7 +168,7 @@ bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* d
168168

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

171-
if (!readRTC->readPixels(dContext, ii, secondRead, 0, {0, 0})) {
171+
if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) {
172172
return false;
173173
}
174174

src/gpu/text/GrAtlasManager.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,27 @@ 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* dContext, GrSurfaceProxyView view, GrColorType colorType,
222+
static bool save_pixels(GrDirectContext* context, GrSurfaceProxyView view, GrColorType colorType,
223223
const char* filename) {
224224
if (!view.proxy()) {
225225
return false;
226226
}
227227

228-
auto ii = SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
229-
kPremul_SkAlphaType);
228+
SkImageInfo ii =
229+
SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
230+
kPremul_SkAlphaType);
230231
SkBitmap bm;
231232
if (!bm.tryAllocPixels(ii)) {
232233
return false;
233234
}
234235

235-
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
236+
auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
236237
kUnknown_SkAlphaType, nullptr);
237238
if (!sContext || !sContext->asTextureProxy()) {
238239
return false;
239240
}
240241

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

src/image/SkImage_Gpu.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,14 @@ 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-
}
135129
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
136-
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
130+
auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
137131
this->refColorSpace());
138132
if (!ctx) {
139133
callback(context, nullptr);
140134
return;
141135
}
142-
ctx->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleQuality,
143-
callback, context);
136+
ctx->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
144137
}
145138

146139
void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -151,21 +144,14 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpac
151144
SkFilterQuality rescaleQuality,
152145
ReadPixelsCallback callback,
153146
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-
}
160147
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
161-
auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
148+
auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
162149
this->refColorSpace());
163150
if (!ctx) {
164151
callback(context, nullptr);
165152
return;
166153
}
167-
ctx->asyncRescaleAndReadPixelsYUV420(dContext,
168-
yuvColorSpace,
154+
ctx->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
169155
std::move(dstColorSpace),
170156
srcRect,
171157
dstSize,
@@ -679,13 +665,13 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
679665
return nullptr;
680666
}
681667

682-
auto dContext = GrAsDirectContext(context);
683-
if (!dContext) {
668+
auto direct = GrAsDirectContext(context);
669+
if (!direct) {
684670
SkDebugf("Direct context required\n");
685671
return nullptr;
686672
}
687673

688-
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
674+
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(direct,
689675
hardwareBuffer,
690676
bufferDesc.format,
691677
true);
@@ -699,7 +685,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
699685
GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr;
700686

701687
GrBackendTexture backendTexture =
702-
GrAHardwareBufferUtils::MakeBackendTexture(dContext, hardwareBuffer,
688+
GrAHardwareBufferUtils::MakeBackendTexture(direct, hardwareBuffer,
703689
bufferDesc.width, bufferDesc.height,
704690
&deleteImageProc, &updateImageProc,
705691
&deleteImageCtx, false, backendFormat, true);
@@ -716,7 +702,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
716702

717703
GrColorType grColorType = SkColorTypeToGrColorType(colorType);
718704

719-
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
705+
GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
720706
if (!proxyProvider) {
721707
return nullptr;
722708
}
@@ -731,26 +717,26 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
731717
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
732718
SkAlphaType at = pixmap.alphaType();
733719

734-
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
720+
GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(backendFormat, grColorType);
735721
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
736-
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), kNeedNewImageUniqueID, view,
722+
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, view,
737723
colorType, at, cs);
738724
if (!image) {
739725
return nullptr;
740726
}
741727

742-
GrDrawingManager* drawingManager = dContext->priv().drawingManager();
728+
GrDrawingManager* drawingManager = direct->priv().drawingManager();
743729
if (!drawingManager) {
744730
return nullptr;
745731
}
746732

747-
GrSurfaceContext surfaceContext(dContext, std::move(view),
733+
GrSurfaceContext surfaceContext(direct, std::move(view),
748734
SkColorTypeToGrColorType(pixmap.colorType()),
749735
pixmap.alphaType(), cs);
750736

751737
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
752738
std::move(cs));
753-
surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
739+
surfaceContext.writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
754740

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

src/image/SkImage_GpuBase.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ bool SkImage_GpuBase::ValidateCompressedBackendTexture(const GrCaps* caps,
8686
//////////////////////////////////////////////////////////////////////////////////////////////////
8787

8888
bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
89-
auto dContext = fContext->asDirectContext();
90-
if (!dContext) {
89+
auto direct = fContext->asDirectContext();
90+
if (!direct) {
9191
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
9292
return false;
9393
}
@@ -112,19 +112,18 @@ bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
112112
}
113113
}
114114

115-
const GrSurfaceProxyView* view = this->view(dContext);
115+
const GrSurfaceProxyView* view = this->view(direct);
116116
SkASSERT(view);
117117
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
118118
fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
119119

120-
auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
120+
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
121121
this->refColorSpace());
122122
if (!sContext) {
123123
return false;
124124
}
125125

126-
if (!sContext->readPixels(dContext, pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
127-
{0, 0})) {
126+
if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), {0, 0})) {
128127
return false;
129128
}
130129

@@ -158,8 +157,8 @@ sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(const SkIRect& subset,
158157

159158
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
160159
int srcX, int srcY, CachingHint) const {
161-
auto dContext = fContext->asDirectContext();
162-
if (!dContext) {
160+
auto direct = fContext->asDirectContext();
161+
if (!direct) {
163162
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
164163
return false;
165164
}
@@ -168,18 +167,18 @@ bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels,
168167
return false;
169168
}
170169

171-
const GrSurfaceProxyView* view = this->view(dContext);
170+
const GrSurfaceProxyView* view = this->view(direct);
172171
SkASSERT(view);
173172
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
174-
dContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
173+
fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
175174

176-
auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
175+
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
177176
this->refColorSpace());
178177
if (!sContext) {
179178
return false;
180179
}
181180

182-
return sContext->readPixels(dContext, dstInfo, dstPixels, dstRB, {srcX, srcY});
181+
return sContext->readPixels(dstInfo, dstPixels, dstRB, {srcX, srcY});
183182
}
184183

185184
GrSurfaceProxyView SkImage_GpuBase::refView(GrRecordingContext* context,

0 commit comments

Comments
 (0)