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

Commit ecbb0fb

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Simplify view getters on GrTextureProducer.
The only thing that affects the view returned is whether it ought to be MIP mapped or not. So don't take a whole GrSamplerState. The view() function won't ever change the colortype so just query GrTextureProducer rather than having view() return a tuple. The rest is transitively reaching through callers and callees of GrTextureProducer::view() to only pass filter or GrMipMapped instead of GrSamplerState. Also, some params that indicate whether MIPs are requested are changed from bool to GrMipMapped. And some minor style stuff (mainly de-yoda-ifying GrMipMapped checks, using GrSurfaceProxyView operator bool()). Change-Id: Ia184aa793cf51d42642ea3bb0521ce06da2efb10 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274205 Reviewed-by: Brian Osman <[email protected]> Commit-Queue: Brian Salomon <[email protected]>
1 parent 71a20b2 commit ecbb0fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+272
-330
lines changed

gm/fpcoordinateoverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, ctx, rtCtx, canvas, 512, 512,
8383
SkBitmap bmp;
8484
GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
8585
GrBitmapTextureMaker maker(ctx, bmp);
86-
auto[view, grCT] = maker.view(GrMipMapped::kNo);
86+
auto view = maker.view(GrMipMapped::kNo);
8787
std::unique_ptr<GrFragmentProcessor> imgFP =
8888
GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
8989
auto fp = std::unique_ptr<GrFragmentProcessor>(new SampleCoordEffect(std::move(imgFP)));

gm/image_pict.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ class TextureGenerator : public SkImageGenerator {
184184
}
185185
protected:
186186
GrSurfaceProxyView onGenerateTexture(GrRecordingContext* ctx, const SkImageInfo& info,
187-
const SkIPoint& origin,
188-
bool willBeMipped) override {
187+
const SkIPoint& origin, GrMipMapped mipMapped) override {
189188
SkASSERT(ctx);
190189
SkASSERT(ctx == fCtx.get());
191190

@@ -197,8 +196,6 @@ class TextureGenerator : public SkImageGenerator {
197196
return fView;
198197
}
199198

200-
GrMipMapped mipMapped = willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo;
201-
202199
// TODO: When we update this function to return a view instead of just a proxy then we can
203200
// remove the extra ref that happens when we call asTextureProxyRef.
204201
return GrSurfaceProxy::Copy(
@@ -273,8 +270,7 @@ class ImageCacheratorGM : public skiagm::GM {
273270
}
274271

275272
static void draw_as_tex(SkCanvas* canvas, SkImage* image, SkScalar x, SkScalar y) {
276-
GrSurfaceProxyView view =
277-
as_IB(image)->refView(canvas->getGrContext(), GrSamplerState::Filter::kBilerp);
273+
GrSurfaceProxyView view = as_IB(image)->refView(canvas->getGrContext(), GrMipMapped::kNo);
278274
if (!view) {
279275
// show placeholder if we have no texture
280276
SkPaint paint;

gm/texelsubset.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class TexelSubset : public GpuGM {
8181
context->priv().caps()->mipMapSupport()
8282
? GrMipMapped::kYes : GrMipMapped::kNo;
8383
GrBitmapTextureMaker maker(context, fBitmap);
84-
auto[view, grCT] = maker.view(mipMapped);
85-
if (!view.proxy()) {
84+
auto view = maker.view(mipMapped);
85+
if (!view) {
8686
*errorMsg = "Failed to create proxy.";
8787
return DrawResult::kFail;
8888
}
@@ -115,7 +115,7 @@ class TexelSubset : public GpuGM {
115115
fBitmap.extractSubset(&subsetBmp, texelSubset);
116116
subsetBmp.setImmutable();
117117
GrBitmapTextureMaker subsetMaker(context, subsetBmp);
118-
auto[subsetView, subsetCT] = subsetMaker.view(mipMapped);
118+
auto subsetView = subsetMaker.view(mipMapped);
119119

120120
SkRect localRect = SkRect::Make(fBitmap.bounds()).makeOutset(kDrawPad, kDrawPad);
121121

gm/yuvtorgbeffect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class YUVtoRGBEffect : public GpuGM {
9999

100100
for (int i = 0; i < 3; ++i) {
101101
GrBitmapTextureMaker maker(context, fBitmaps[i]);
102-
std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
102+
views[i] = maker.view(GrMipMapped::kNo);
103103
if (!views[i]) {
104104
*errorMsg = "Failed to create proxy";
105105
return DrawResult::kFail;
@@ -215,7 +215,7 @@ class YUVNV12toRGBEffect : public GpuGM {
215215

216216
for (int i = 0; i < 2; ++i) {
217217
GrBitmapTextureMaker maker(context, fBitmaps[i]);
218-
std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
218+
views[i] = maker.view(GrMipMapped::kNo);
219219
if (!views[i]) {
220220
*errorMsg = "Failed to create proxy";
221221
return DrawResult::kFail;
@@ -311,7 +311,7 @@ class YUVtoRGBDomainEffect : public GpuGM {
311311

312312
for (int i = 0; i < 3; ++i) {
313313
GrBitmapTextureMaker maker(context, fBitmaps[i]);
314-
std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
314+
views[i] = maker.view(GrMipMapped::kNo);
315315
if (!views[i]) {
316316
*errorMsg = "Failed to create proxy";
317317
return DrawResult::kFail;

include/core/SkImageGenerator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class SK_API SkImageGenerator {
140140
* overhead in later allocating mips and copying of the base layer.
141141
*/
142142
GrSurfaceProxyView generateTexture(GrRecordingContext*, const SkImageInfo& info,
143-
const SkIPoint& origin, bool willNeedMipMaps);
143+
const SkIPoint& origin, GrMipMapped);
144144

145145
bool texturesAreCacheable() const { return this->onTexturesAreCacheable(); }
146146
#endif
@@ -183,8 +183,7 @@ class SK_API SkImageGenerator {
183183
};
184184

185185
virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&,
186-
const SkIPoint&,
187-
bool willNeedMipMaps); // returns nullptr
186+
const SkIPoint&, GrMipMapped); // returns nullptr
188187
virtual bool onTexturesAreCacheable() const { return true; }
189188
#endif
190189

src/core/SkImageGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ bool SkImageGenerator::getYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
6464
GrSurfaceProxyView SkImageGenerator::generateTexture(GrRecordingContext* ctx,
6565
const SkImageInfo& info,
6666
const SkIPoint& origin,
67-
bool willNeedMipMaps) {
67+
GrMipMapped mipMapped) {
6868
SkIRect srcRect = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height());
6969
if (!SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(srcRect)) {
7070
return {};
7171
}
72-
return this->onGenerateTexture(ctx, info, origin, willNeedMipMaps);
72+
return this->onGenerateTexture(ctx, info, origin, mipMapped);
7373
}
7474

7575
GrSurfaceProxyView SkImageGenerator::onGenerateTexture(GrRecordingContext*,
7676
const SkImageInfo&,
7777
const SkIPoint&,
78-
bool willNeedMipMaps) {
78+
GrMipMapped) {
7979
return {};
8080
}
8181
#endif

src/core/SkPictureImageGenerator.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class SkPictureImageGenerator : public SkImageGenerator {
2424
override;
2525

2626
#if SK_SUPPORT_GPU
27-
GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&,
28-
const SkIPoint&, bool willNeedMipMaps) override;
27+
GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, const SkIPoint&,
28+
GrMipMapped) override;
2929
#endif
3030

3131
private:
@@ -93,18 +93,18 @@ bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
9393
#include "include/private/GrRecordingContext.h"
9494
#include "src/gpu/GrRecordingContextPriv.h"
9595

96-
GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(
97-
GrRecordingContext* ctx, const SkImageInfo& info,
98-
const SkIPoint& origin, bool willNeedMipMaps) {
96+
GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(GrRecordingContext* ctx,
97+
const SkImageInfo& info,
98+
const SkIPoint& origin,
99+
GrMipMapped mipMapped) {
99100
SkASSERT(ctx);
100101

101102
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
102103

103104
// CONTEXT TODO: remove this use of 'backdoor' to create an SkSkSurface
104-
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx->priv().backdoor(),
105-
SkBudgeted::kYes, info, 0,
106-
kTopLeft_GrSurfaceOrigin, &props,
107-
willNeedMipMaps));
105+
auto surface = SkSurface::MakeRenderTarget(ctx->priv().backdoor(), SkBudgeted::kYes, info, 0,
106+
kTopLeft_GrSurfaceOrigin, &props,
107+
mipMapped == GrMipMapped::kYes);
108108
if (!surface) {
109109
return {};
110110
}
@@ -119,7 +119,8 @@ GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(
119119
}
120120
const GrSurfaceProxyView* view = as_IB(image)->view(ctx);
121121
SkASSERT(view);
122-
SkASSERT(!willNeedMipMaps || GrMipMapped::kYes == view->asTextureProxy()->mipMapped());
122+
SkASSERT(mipMapped == GrMipMapped::kNo ||
123+
view->asTextureProxy()->mipMapped() == GrMipMapped::kYes);
123124
return *view;
124125
}
125126
#endif

src/gpu/GrAHardwareBufferImageGenerator.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext*
186186
return GrSurfaceProxyView(std::move(texProxy), fSurfaceOrigin, readSwizzle);
187187
}
188188

189-
GrSurfaceProxyView GrAHardwareBufferImageGenerator::onGenerateTexture(
190-
GrRecordingContext* context, const SkImageInfo& info,
191-
const SkIPoint& origin, bool willNeedMipMaps) {
189+
GrSurfaceProxyView GrAHardwareBufferImageGenerator::onGenerateTexture(GrRecordingContext* context,
190+
const SkImageInfo& info,
191+
const SkIPoint& origin,
192+
GrMipMapped mipMapped) {
192193
GrSurfaceProxyView texProxyView = this->makeView(context);
193194
if (!texProxyView.proxy()) {
194195
return {};
@@ -204,8 +205,6 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::onGenerateTexture(
204205
// Otherwise, make a copy for the requested subset.
205206
SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, info.width(), info.height());
206207

207-
GrMipMapped mipMapped = willNeedMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
208-
209208
GrColorType grColorType = SkColorTypeToGrColorType(this->getInfo().colorType());
210209
return GrSurfaceProxy::Copy(context, texProxyView.proxy(), texProxyView.origin(), grColorType,
211210
mipMapped, subset, SkBackingFit::kExact,

src/gpu/GrAHardwareBufferImageGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class GrAHardwareBufferImageGenerator : public SkImageGenerator {
4242

4343
bool onIsValid(GrContext*) const override;
4444

45-
GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&,
46-
const SkIPoint&, bool willNeedMipMaps) override;
45+
GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, const SkIPoint&,
46+
GrMipMapped) override;
4747

4848
private:
4949
GrAHardwareBufferImageGenerator(const SkImageInfo&, AHardwareBuffer*, SkAlphaType,

src/gpu/GrBackendTextureImageGenerator.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ void GrBackendTextureImageGenerator::ReleaseRefHelper_TextureReleaseProc(void* c
9393
refHelper->unref();
9494
}
9595

96-
GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
97-
GrRecordingContext* context, const SkImageInfo& info,
98-
const SkIPoint& origin, bool willNeedMipMaps) {
96+
GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(GrRecordingContext* context,
97+
const SkImageInfo& info,
98+
const SkIPoint& origin,
99+
GrMipMapped mipMapped) {
99100
SkASSERT(context);
100101

101102
if (context->backend() != fBackendTexture.backend()) {
@@ -144,7 +145,8 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
144145

145146
GrColorType grColorType = SkColorTypeToGrColorType(info.colorType());
146147

147-
GrMipMapped mipMapped = fBackendTexture.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;
148+
GrMipMapped textureIsMipMapped = fBackendTexture.hasMipMaps() ? GrMipMapped::kYes
149+
: GrMipMapped::kNo;
148150

149151
// Ganesh assumes that, when wrapping a mipmapped backend texture from a client, that its
150152
// mipmaps are fully fleshed out.
@@ -155,12 +157,11 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
155157

156158
// Must make copies of member variables to capture in the lambda since this image generator may
157159
// be deleted before we actually execute the lambda.
158-
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
159-
[
160-
refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture,
161-
grColorType
162-
](GrResourceProvider * resourceProvider)
163-
->GrSurfaceProxy::LazyCallbackResult {
160+
sk_sp<GrTextureProxy> proxy =
161+
proxyProvider->createLazyProxy(
162+
[refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture,
163+
grColorType](GrResourceProvider* resourceProvider)
164+
-> GrSurfaceProxy::LazyCallbackResult {
164165
if (refHelper->fSemaphore) {
165166
resourceProvider->priv().gpu()->waitSemaphore(
166167
refHelper->fSemaphore.get());
@@ -201,22 +202,22 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
201202
return {std::move(tex), true,
202203
GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
203204
},
204-
backendFormat, fBackendTexture.dimensions(), readSwizzle, GrRenderable::kNo, 1,
205-
mipMapped, mipMapsStatus, GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact,
206-
SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
205+
backendFormat, fBackendTexture.dimensions(), readSwizzle, GrRenderable::kNo, 1,
206+
textureIsMipMapped, mipMapsStatus, GrInternalSurfaceFlags::kReadOnly,
207+
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo,
208+
GrSurfaceProxy::UseAllocator::kYes);
207209
if (!proxy) {
208210
return {};
209211
}
210212

211213
if (origin.isZero() && info.dimensions() == fBackendTexture.dimensions() &&
212-
(!willNeedMipMaps || GrMipMapped::kYes == proxy->mipMapped())) {
214+
(mipMapped == GrMipMapped::kNo || proxy->mipMapped() == GrMipMapped::kYes)) {
213215
// If the caller wants the entire texture and we have the correct mip support, we're done
214216
return GrSurfaceProxyView(std::move(proxy), fSurfaceOrigin, readSwizzle);
215217
} else {
216218
// Otherwise, make a copy of the requested subset. Make sure our temporary is renderable,
217219
// because Vulkan will want to do the copy as a draw. All other copies would require a
218220
// layout change in Vulkan and we do not change the layout of borrowed images.
219-
GrMipMapped mipMapped = willNeedMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
220221
SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, info.width(), info.height());
221222

222223
return GrSurfaceProxy::Copy(

0 commit comments

Comments
 (0)