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

Commit 694ff17

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Revert "Revert changes to unbreak bots."
This reverts commit 49721c8. Reason for revert: fixed double usage of plane release context in YUVUtils. Original change's description: > Revert changes to unbreak bots. > > f01a9d9 > is the culprit > > > Revert "GrRefCntedCallback has Make function." > > This reverts commit b2c4214. > > Revert "Add SkImage::MakeFromYUVATexturesCopyToExternal" > > This reverts commit f01a9d9. > > Bug: skia:10632 > Change-Id: Ief076f168b63ff8ca15b607163a13d5f52a733d2 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331798 > Reviewed-by: Brian Salomon <[email protected]> > Commit-Queue: Brian Salomon <[email protected]> [email protected] Change-Id: I41cdfe0d5b8587f85fae0c804c059c0d6ff92800 Bug: skia:10632 Change-Id: I41cdfe0d5b8587f85fae0c804c059c0d6ff92800 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331876 Commit-Queue: Brian Salomon <[email protected]> Reviewed-by: Brian Salomon <[email protected]>
1 parent 8cdba3e commit 694ff17

21 files changed

+264
-153
lines changed

RELEASE_NOTES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ Milestone 88
2727
which wraps an SkYUVAInfo and compatible set of GrBackendTextures. The provides
2828
a more complete and structured specification of the planar configuration. Previous
2929
version is deprecated.
30+
Already deprecated MakeFromYUVATexturesCopyToExternal added to replace other deprecated
31+
APIs. It's not recommended that clients use this and instead use the pattern described
32+
in the API comment.
3033
https://review.skia.org/317762
34+
https://review.skia.org/329956
3135

3236
* Add field to GrContextOptions to disable mipmap support even if the backend
3337
supports it.

gm/wacky_yuv_formats.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ class WackyYUVFormatsGM : public GM {
752752
case Type::kFromGenerator:
753753
name += "_imggen";
754754
break;
755+
case Type::kFromTexturesCopyToExternal:
756+
name += "_fromtextureswithcopy";
757+
break;
755758
}
756759

757760
return name;
@@ -943,6 +946,9 @@ DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false,
943946
DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false,
944947
/* subset */ false,
945948
WackyYUVFormatsGM::Type::kFromPixmaps);)
949+
DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false,
950+
/* subset */ false,
951+
WackyYUVFormatsGM::Type::kFromTexturesCopyToExternal);)
946952

947953
class YUVMakeColorSpaceGM : public GpuGM {
948954
public:

include/core/SkImage.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,46 @@ class SK_API SkImage : public SkRefCnt {
428428
TextureReleaseProc textureReleaseProc = nullptr,
429429
ReleaseContext releaseContext = nullptr);
430430

431+
/** Deprecated.
432+
Creates an SkImage from YUV[A] planar textures by copying them to another caller-provided
433+
texture and retaining that result texture in the SkImage. This should be preferred over
434+
MakeFromYUVTexturesCopyWithExternalBackend and MakeFromNV12TexturesCopyWithExternalBackend.
435+
However, this is deprecated and instead clients should make a SkSurface from
436+
'rgbaResultTexture` using SkSurface::MakeFromBackendTexture, make an image from the planes
437+
using MakeFromYUVATextures, and finally draw the image to the surface.
438+
439+
Note that the draw that converts to RGBA is not issued to the underlying API until a flush/
440+
submit occurs so the YUVA textures are not safe to delete or overwrite until yuvaReleaseProc
441+
is called.
442+
443+
The dimensions of the result RGBA texture must match the dimensions of the YUVA planar data.
444+
445+
@param context GPU context
446+
@param yuvaTextures A set of textures containing YUVA data and a description of the
447+
data and transformation to RGBA.
448+
@param rgbaResultTexture The renderable texture that will hold the result of the conversion
449+
to RGBA and be retained in the resulting SkImage.
450+
@param colorType colorType of the result as stored in rgbaResultTexture. Must be
451+
compatible with the texture's format.
452+
@param imageColorSpace range of colors of the resulting image after conversion to RGB;
453+
may be nullptr
454+
@param yuvaReleaseProc called when the backend textures in 'yuvaTextures' can be released
455+
@param yuvaReleaseContext state passed to yuvaReleaseProc
456+
@param rgbaReleaseProc called when the 'rgbaResultTexture' can be released
457+
@param rgbaReleaseContext state passed to rgbaReleaseProc
458+
@return created SkImage, or nullptr
459+
*/
460+
static sk_sp<SkImage> MakeFromYUVATexturesCopyToExternal(
461+
GrRecordingContext* context,
462+
const GrYUVABackendTextures& yuvaTextures,
463+
const GrBackendTexture& rgbaResultTexture,
464+
SkColorType colorType,
465+
sk_sp<SkColorSpace> imageColorSpace = nullptr,
466+
TextureReleaseProc yuvaReleaseProc = nullptr,
467+
ReleaseContext yuvaReleaseContext = nullptr,
468+
TextureReleaseProc rgbaReleaseProc = nullptr,
469+
ReleaseContext rgbaReleaseContext = nullptr);
470+
431471
/**
432472
Deprecated. Use version that takes GrYUVABackendTextures.
433473

include/core/SkYUVAPixmaps.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ class SK_API SkYUVAPixmapInfo {
171171
*/
172172
class SK_API SkYUVAPixmaps {
173173
public:
174+
using DataType = SkYUVAPixmapInfo::DataType;
174175
static constexpr auto kMaxPlanes = SkYUVAPixmapInfo::kMaxPlanes;
175176

177+
static SkColorType RecommendedRGBAColorType(DataType);
178+
176179
/** Allocate space for pixmaps' pixels in the SkYUVAPixmaps. */
177180
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo& yuvaPixmapInfo);
178181

@@ -217,6 +220,8 @@ class SK_API SkYUVAPixmaps {
217220

218221
const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
219222

223+
DataType dataType() const { return fDataType; }
224+
220225
SkYUVAPixmapInfo pixmapsInfo() const;
221226

222227
/** Number of pixmap planes or 0 if this SkYUVAPixmaps is invalid. */
@@ -250,11 +255,12 @@ class SK_API SkYUVAPixmaps {
250255

251256
private:
252257
SkYUVAPixmaps(const SkYUVAPixmapInfo&, sk_sp<SkData>);
253-
SkYUVAPixmaps(const SkYUVAInfo&, const SkPixmap[kMaxPlanes]);
258+
SkYUVAPixmaps(const SkYUVAInfo&, DataType, const SkPixmap[kMaxPlanes]);
254259

255-
SkYUVAInfo fYUVAInfo;
256260
std::array<SkPixmap, kMaxPlanes> fPlanes = {};
257261
sk_sp<SkData> fData;
262+
SkYUVAInfo fYUVAInfo;
263+
DataType fDataType;
258264
};
259265

260266
//////////////////////////////////////////////////////////////////////////////

include/private/GrTypesPriv.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,19 +1205,29 @@ static constexpr GrColorType GrMaskFormatToColorType(GrMaskFormat format) {
12051205
/**
12061206
* Ref-counted object that calls a callback from its destructor.
12071207
*/
1208-
class GrRefCntedCallback : public SkRefCnt {
1208+
class GrRefCntedCallback : public SkNVRefCnt<GrRefCntedCallback> {
12091209
public:
12101210
using Context = void*;
12111211
using Callback = void (*)(Context);
12121212

1213-
GrRefCntedCallback(Callback proc, Context ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {
1214-
SkASSERT(proc);
1213+
static sk_sp<GrRefCntedCallback> Make(Callback proc, Context ctx) {
1214+
if (!proc) {
1215+
return nullptr;
1216+
}
1217+
return sk_sp<GrRefCntedCallback>(new GrRefCntedCallback(proc, ctx));
12151218
}
1216-
~GrRefCntedCallback() override { fReleaseProc ? fReleaseProc(fReleaseCtx) : void(); }
1219+
1220+
~GrRefCntedCallback() { fReleaseProc(fReleaseCtx); }
12171221

12181222
Context context() const { return fReleaseCtx; }
12191223

12201224
private:
1225+
GrRefCntedCallback(Callback proc, Context ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {}
1226+
GrRefCntedCallback(const GrRefCntedCallback&) = delete;
1227+
GrRefCntedCallback(GrRefCntedCallback&&) = delete;
1228+
GrRefCntedCallback& operator=(const GrRefCntedCallback&) = delete;
1229+
GrRefCntedCallback& operator=(GrRefCntedCallback&&) = delete;
1230+
12211231
Callback fReleaseProc;
12221232
Context fReleaseCtx;
12231233
};

src/core/SkYUVAPixmaps.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ bool SkYUVAPixmapInfo::isSupported(const SupportedDataTypes& supportedDataTypes)
177177

178178
//////////////////////////////////////////////////////////////////////////////
179179

180+
SkColorType SkYUVAPixmaps::RecommendedRGBAColorType(DataType dataType) {
181+
switch (dataType) {
182+
case DataType::kUnorm8: return kRGBA_8888_SkColorType;
183+
// F16 has better GPU support than 16 bit unorm. Often "16" bit unorm values are actually
184+
// lower precision.
185+
case DataType::kUnorm16: return kRGBA_F16_SkColorType;
186+
case DataType::kFloat16: return kRGBA_F16_SkColorType;
187+
case DataType::kUnorm10_Unorm2: return kRGBA_1010102_SkColorType;
188+
}
189+
SkUNREACHABLE;
190+
}
191+
180192
SkYUVAPixmaps SkYUVAPixmaps::Allocate(const SkYUVAPixmapInfo& yuvaPixmapInfo) {
181193
if (!yuvaPixmapInfo.isValid()) {
182194
return {};
@@ -223,7 +235,7 @@ SkYUVAPixmaps SkYUVAPixmaps::FromExternalMemory(const SkYUVAPixmapInfo& yuvaPixm
223235
}
224236
SkPixmap pixmaps[kMaxPlanes];
225237
yuvaPixmapInfo.initPixmapsFromSingleAllocation(memory, pixmaps);
226-
return SkYUVAPixmaps(yuvaPixmapInfo.yuvaInfo(), pixmaps);
238+
return SkYUVAPixmaps(yuvaPixmapInfo.yuvaInfo(), yuvaPixmapInfo.dataType(), pixmaps);
227239
}
228240

229241
SkYUVAPixmaps SkYUVAPixmaps::FromExternalPixmaps(const SkYUVAInfo& yuvaInfo,
@@ -235,23 +247,27 @@ SkYUVAPixmaps SkYUVAPixmaps::FromExternalPixmaps(const SkYUVAInfo& yuvaInfo,
235247
colorTypes[i] = pixmaps[i].colorType();
236248
rowBytes[i] = pixmaps[i].rowBytes();
237249
}
238-
if (!SkYUVAPixmapInfo(yuvaInfo, colorTypes, rowBytes).isValid()) {
250+
SkYUVAPixmapInfo yuvaPixmapInfo(yuvaInfo, colorTypes, rowBytes);
251+
if (!yuvaPixmapInfo.isValid()) {
239252
return {};
240253
}
241-
return SkYUVAPixmaps(yuvaInfo, pixmaps);
254+
return SkYUVAPixmaps(yuvaInfo, yuvaPixmapInfo.dataType(), pixmaps);
242255
}
243256

244257
SkYUVAPixmaps::SkYUVAPixmaps(const SkYUVAPixmapInfo& yuvaPixmapInfo, sk_sp<SkData> data)
245-
: fYUVAInfo(yuvaPixmapInfo.yuvaInfo())
246-
, fData(std::move(data)) {
258+
: fData(std::move(data))
259+
, fYUVAInfo(yuvaPixmapInfo.yuvaInfo())
260+
, fDataType(yuvaPixmapInfo.dataType()) {
247261
SkASSERT(yuvaPixmapInfo.isValid());
248262
SkASSERT(yuvaPixmapInfo.computeTotalBytes() <= fData->size());
249263
SkAssertResult(yuvaPixmapInfo.initPixmapsFromSingleAllocation(fData->writable_data(),
250264
fPlanes.data()));
251265
}
252266

253-
SkYUVAPixmaps::SkYUVAPixmaps(const SkYUVAInfo& yuvaInfo, const SkPixmap pixmaps[kMaxPlanes])
254-
: fYUVAInfo(yuvaInfo) {
267+
SkYUVAPixmaps::SkYUVAPixmaps(const SkYUVAInfo& yuvaInfo,
268+
DataType dataType,
269+
const SkPixmap pixmaps[kMaxPlanes])
270+
: fYUVAInfo(yuvaInfo), fDataType(dataType) {
255271
std::copy_n(pixmaps, yuvaInfo.numPlanes(), fPlanes.data());
256272
}
257273

src/gpu/GrBackendTextureImageGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
127127
// The ref we add to fRefHelper here will be passed into and owned by the
128128
// GrRefCntedCallback.
129129
fRefHelper->ref();
130-
releaseProcHelper.reset(
131-
new GrRefCntedCallback(ReleaseRefHelper_TextureReleaseProc, fRefHelper));
130+
releaseProcHelper =
131+
GrRefCntedCallback::Make(ReleaseRefHelper_TextureReleaseProc, fRefHelper);
132132
fRefHelper->fBorrowingContextReleaseProc = releaseProcHelper.get();
133133
}
134134
fRefHelper->fBorrowingContextID = context->priv().contextID();

src/gpu/GrDirectContext.cpp

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,7 @@ GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
511511
GrProtected isProtected,
512512
GrGpuFinishedProc finishedProc,
513513
GrGpuFinishedContext finishedContext) {
514-
sk_sp<GrRefCntedCallback> finishedCallback;
515-
if (finishedProc) {
516-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
517-
}
514+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
518515

519516
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
520517
if (this->abandoned()) {
@@ -535,10 +532,7 @@ GrBackendTexture GrDirectContext::createBackendTexture(int width, int height,
535532
GrProtected isProtected,
536533
GrGpuFinishedProc finishedProc,
537534
GrGpuFinishedContext finishedContext) {
538-
sk_sp<GrRefCntedCallback> finishedCallback;
539-
if (finishedProc) {
540-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
541-
}
535+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
542536

543537
if (this->abandoned()) {
544538
return {};
@@ -566,10 +560,7 @@ GrBackendTexture GrDirectContext::createBackendTexture(const SkPixmap srcData[],
566560
GrGpuFinishedContext finishedContext) {
567561
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
568562

569-
sk_sp<GrRefCntedCallback> finishedCallback;
570-
if (finishedProc) {
571-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
572-
}
563+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
573564

574565
if (this->abandoned()) {
575566
return {};
@@ -606,10 +597,7 @@ bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTextur
606597
const SkColor4f& color,
607598
GrGpuFinishedProc finishedProc,
608599
GrGpuFinishedContext finishedContext) {
609-
sk_sp<GrRefCntedCallback> finishedCallback;
610-
if (finishedProc) {
611-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
612-
}
600+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
613601

614602
if (this->abandoned()) {
615603
return false;
@@ -624,10 +612,7 @@ bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTextur
624612
const SkColor4f& color,
625613
GrGpuFinishedProc finishedProc,
626614
GrGpuFinishedContext finishedContext) {
627-
sk_sp<GrRefCntedCallback> finishedCallback;
628-
if (finishedProc) {
629-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
630-
}
615+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
631616

632617
if (this->abandoned()) {
633618
return false;
@@ -651,10 +636,7 @@ bool GrDirectContext::updateBackendTexture(const GrBackendTexture& backendTextur
651636
int numLevels,
652637
GrGpuFinishedProc finishedProc,
653638
GrGpuFinishedContext finishedContext) {
654-
sk_sp<GrRefCntedCallback> finishedCallback;
655-
if (finishedProc) {
656-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
657-
}
639+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
658640

659641
if (this->abandoned()) {
660642
return false;
@@ -711,10 +693,7 @@ GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int
711693
GrGpuFinishedProc finishedProc,
712694
GrGpuFinishedContext finishedContext) {
713695
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
714-
sk_sp<GrRefCntedCallback> finishedCallback;
715-
if (finishedProc) {
716-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
717-
}
696+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
718697

719698
if (this->abandoned()) {
720699
return {};
@@ -749,10 +728,7 @@ GrBackendTexture GrDirectContext::createCompressedBackendTexture(int width, int
749728
GrGpuFinishedProc finishedProc,
750729
GrGpuFinishedContext finishedContext) {
751730
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
752-
sk_sp<GrRefCntedCallback> finishedCallback;
753-
if (finishedProc) {
754-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
755-
}
731+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
756732

757733
if (this->abandoned()) {
758734
return {};
@@ -781,10 +757,7 @@ bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& bac
781757
const SkColor4f& color,
782758
GrGpuFinishedProc finishedProc,
783759
GrGpuFinishedContext finishedContext) {
784-
sk_sp<GrRefCntedCallback> finishedCallback;
785-
if (finishedProc) {
786-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
787-
}
760+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
788761

789762
if (this->abandoned()) {
790763
return false;
@@ -799,10 +772,7 @@ bool GrDirectContext::updateCompressedBackendTexture(const GrBackendTexture& bac
799772
size_t dataSize,
800773
GrGpuFinishedProc finishedProc,
801774
GrGpuFinishedContext finishedContext) {
802-
sk_sp<GrRefCntedCallback> finishedCallback;
803-
if (finishedProc) {
804-
finishedCallback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
805-
}
775+
auto finishedCallback = GrRefCntedCallback::Make(finishedProc, finishedContext);
806776

807777
if (this->abandoned()) {
808778
return false;
@@ -824,10 +794,7 @@ bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendText
824794
GrBackendSurfaceMutableState* previousState,
825795
GrGpuFinishedProc finishedProc,
826796
GrGpuFinishedContext finishedContext) {
827-
sk_sp<GrRefCntedCallback> callback;
828-
if (finishedProc) {
829-
callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
830-
}
797+
auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext);
831798

832799
if (this->abandoned()) {
833800
return false;
@@ -842,10 +809,7 @@ bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& b
842809
GrBackendSurfaceMutableState* previousState,
843810
GrGpuFinishedProc finishedProc,
844811
GrGpuFinishedContext finishedContext) {
845-
sk_sp<GrRefCntedCallback> callback;
846-
if (finishedProc) {
847-
callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
848-
}
812+
auto callback = GrRefCntedCallback::Make(finishedProc, finishedContext);
849813

850814
if (this->abandoned()) {
851815
return false;

src/gpu/GrSurface.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class GrSurface : public GrGpuResource {
5151
typedef void* ReleaseCtx;
5252
typedef void (*ReleaseProc)(ReleaseCtx);
5353
void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
54-
sk_sp<GrRefCntedCallback> helper(new GrRefCntedCallback(proc, ctx));
55-
this->setRelease(std::move(helper));
54+
this->setRelease(GrRefCntedCallback::Make(proc, ctx));
5655
}
5756

5857
/**

src/gpu/GrTexture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GrTexture : virtual public GrSurface {
6464
void addIdleProc(GrRefCntedCallback::Callback callback,
6565
GrRefCntedCallback::Context context,
6666
IdleState state) {
67-
this->addIdleProc(sk_make_sp<GrRefCntedCallback>(callback, context), state);
67+
this->addIdleProc(GrRefCntedCallback::Make(callback, context), state);
6868
}
6969

7070
GrTextureType textureType() const { return fTextureType; }

0 commit comments

Comments
 (0)