Have gpu yuv code speak in views.
Bug: skia:9556
Change-Id: Iaa071d53248dfcd6d9e1bd88b24c8b39e133ced2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269148
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp
index 073d48a..2ed22db 100644
--- a/gm/yuvtorgbeffect.cpp
+++ b/gm/yuvtorgbeffect.cpp
@@ -95,16 +95,15 @@
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override {
- sk_sp<GrTextureProxy> proxies[3];
+ GrSurfaceProxyView views[3];
for (int i = 0; i < 3; ++i) {
GrBitmapTextureMaker maker(context, fBitmaps[i]);
- auto[view, grCT] = maker.view(GrMipMapped::kNo);
- if (!view.proxy()) {
+ std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
+ if (!views[i]) {
*errorMsg = "Failed to create proxy";
return DrawResult::kFail;
}
- proxies[i] = view.asTextureProxyRef();
}
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
@@ -127,7 +126,7 @@
};
const auto& caps = *context->priv().caps();
std::unique_ptr<GrFragmentProcessor> fp(GrYUVtoRGBEffect::Make(
- proxies, yuvaIndices, static_cast<SkYUVColorSpace>(space),
+ views, yuvaIndices, static_cast<SkYUVColorSpace>(space),
GrSamplerState::Filter::kNearest, caps));
if (fp) {
GrPaint grPaint;
@@ -212,16 +211,15 @@
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override {
- sk_sp<GrTextureProxy> proxies[2];
+ GrSurfaceProxyView views[2];
for (int i = 0; i < 2; ++i) {
GrBitmapTextureMaker maker(context, fBitmaps[i]);
- auto[view, grCT] = maker.view(GrMipMapped::kNo);
- if (!view.proxy()) {
+ std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
+ if (!views[i]) {
*errorMsg = "Failed to create proxy";
return DrawResult::kFail;
}
- proxies[i] = view.asTextureProxyRef();
}
SkYUVAIndex yuvaIndices[4] = {
@@ -242,7 +240,7 @@
GrPaint grPaint;
grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
const auto& caps = *context->priv().caps();
- auto fp = GrYUVtoRGBEffect::Make(proxies, yuvaIndices,
+ auto fp = GrYUVtoRGBEffect::Make(views, yuvaIndices,
static_cast<SkYUVColorSpace>(space),
GrSamplerState::Filter::kNearest, caps);
if (fp) {
@@ -309,16 +307,15 @@
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override {
- sk_sp<GrTextureProxy> proxies[3];
+ GrSurfaceProxyView views[3];
for (int i = 0; i < 3; ++i) {
GrBitmapTextureMaker maker(context, fBitmaps[i]);
- auto[view, grCT] = maker.view(GrMipMapped::kNo);
- if (!view.proxy()) {
+ std::tie(views[i], std::ignore) = maker.view(GrMipMapped::kNo);
+ if (!views[i]) {
*errorMsg = "Failed to create proxy";
return DrawResult::kFail;
}
- proxies[i] = view.asTextureProxyRef();
}
// Draw a 2x2 grid of the YUV images.
@@ -353,7 +350,7 @@
const SkRect* domainPtr = j > 0 ? &domain : nullptr;
const auto& caps = *context->priv().caps();
std::unique_ptr<GrFragmentProcessor> fp(
- GrYUVtoRGBEffect::Make(proxies, yuvaIndices, kJPEG_SkYUVColorSpace,
+ GrYUVtoRGBEffect::Make(views, yuvaIndices, kJPEG_SkYUVColorSpace,
kFilters[i], caps, SkMatrix::I(), domainPtr));
if (fp) {
GrPaint grPaint;
diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp
index 2b6d87f..8361f6a 100644
--- a/src/gpu/GrImageTextureMaker.cpp
+++ b/src/gpu/GrImageTextureMaker.cpp
@@ -119,7 +119,7 @@
}
const auto& caps = *fImage->context()->priv().caps();
- auto fp = GrYUVtoRGBEffect::Make(fImage->fProxies, fImage->fYUVAIndices, fImage->fYUVColorSpace,
+ auto fp = GrYUVtoRGBEffect::Make(fImage->fViews, fImage->fYUVAIndices, fImage->fYUVColorSpace,
filter, caps, textureMatrix, domain);
if (fImage->fFromColorSpace) {
fp = GrColorSpaceXformEffect::Make(std::move(fp), fImage->fFromColorSpace.get(),
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 3b5e5d8..26074ac 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -120,7 +120,7 @@
return {};
}
- sk_sp<GrTextureProxy> yuvTextureProxies[SkYUVASizeInfo::kMaxCount];
+ GrSurfaceProxyView yuvViews[SkYUVASizeInfo::kMaxCount];
for (int i = 0; i < SkYUVASizeInfo::kMaxCount; ++i) {
if (yuvSizeInfo.fSizes[i].isEmpty()) {
SkASSERT(!yuvSizeInfo.fWidthBytes[i]);
@@ -153,14 +153,13 @@
bitmap.setImmutable();
GrBitmapTextureMaker maker(ctx, bitmap, GrBitmapTextureMaker::Cached::kNo, fit);
- auto[view, grCT] = maker.view(GrMipMapped::kNo);
- yuvTextureProxies[i] = view.asTextureProxyRef();
+ std::tie(yuvViews[i], std::ignore) = maker.view(GrMipMapped::kNo);
- if (!yuvTextureProxies[i]) {
+ if (!yuvViews[i]) {
return {};
}
- SkASSERT(yuvTextureProxies[i]->dimensions() == yuvSizeInfo.fSizes[i]);
+ SkASSERT(yuvViews[i].proxy()->dimensions() == yuvSizeInfo.fSizes[i]);
}
// TODO: investigate preallocating mip maps here
@@ -173,7 +172,7 @@
GrPaint paint;
const auto& caps = *ctx->priv().caps();
- auto yuvToRgbProcessor = GrYUVtoRGBEffect::Make(yuvTextureProxies, yuvaIndices, yuvColorSpace,
+ auto yuvToRgbProcessor = GrYUVtoRGBEffect::Make(yuvViews, yuvaIndices, yuvColorSpace,
GrSamplerState::Filter::kNearest, caps);
paint.addColorFragmentProcessor(std::move(yuvToRgbProcessor));
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp
index 9183b67..9571cad 100644
--- a/src/gpu/effects/GrYUVtoRGBEffect.cpp
+++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp
@@ -15,7 +15,7 @@
#include "src/sksl/SkSLCPP.h"
#include "src/sksl/SkSLUtil.h"
-std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(const sk_sp<GrTextureProxy> proxies[],
+std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(GrSurfaceProxyView views[],
const SkYUVAIndex yuvaIndices[4],
SkYUVColorSpace yuvColorSpace,
GrSamplerState::Filter filterMode,
@@ -25,7 +25,8 @@
int numPlanes;
SkAssertResult(SkYUVAIndex::AreValidIndices(yuvaIndices, &numPlanes));
- const SkISize YDimensions = proxies[yuvaIndices[SkYUVAIndex::kY_Index].fIndex]->dimensions();
+ const SkISize YDimensions =
+ views[yuvaIndices[SkYUVAIndex::kY_Index].fIndex].proxy()->dimensions();
// This promotion of nearest to bilinear for UV planes exists to mimic libjpeg[-turbo]'s
// do_fancy_upsampling option. However, skbug.com/9693.
@@ -34,7 +35,7 @@
: GrSamplerState::Filter::kBilerp;
std::unique_ptr<GrFragmentProcessor> planeFPs[4];
for (int i = 0; i < numPlanes; ++i) {
- SkISize dimensions = proxies[i]->dimensions();
+ SkISize dimensions = views[i].proxy()->dimensions();
SkTCopyOnFirstWrite<SkMatrix> planeMatrix(&localMatrix);
GrSamplerState::Filter planeFilter = filterMode;
SkRect planeDomain;
@@ -65,15 +66,12 @@
planeDomain = *domain;
}
- GrSurfaceOrigin origin = proxies[i]->origin();
- GrSwizzle swizzle = proxies[i]->textureSwizzle();
- GrSurfaceProxyView view(proxies[i], origin, swizzle);
if (domain) {
SkASSERT(planeFilter != GrSamplerState::Filter::kMipMap);
- planeFPs[i] = GrTextureEffect::MakeSubset(std::move(view), kUnknown_SkAlphaType,
+ planeFPs[i] = GrTextureEffect::MakeSubset(views[i], kUnknown_SkAlphaType,
*planeMatrix, planeFilter, planeDomain, caps);
} else {
- planeFPs[i] = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType, *planeMatrix,
+ planeFPs[i] = GrTextureEffect::Make(views[i], kUnknown_SkAlphaType, *planeMatrix,
planeFilter);
}
}
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.h b/src/gpu/effects/GrYUVtoRGBEffect.h
index 6ed3b63..1f2aee5 100644
--- a/src/gpu/effects/GrYUVtoRGBEffect.h
+++ b/src/gpu/effects/GrYUVtoRGBEffect.h
@@ -20,7 +20,7 @@
// to the multi-planar, varying resolution images that it has to sample. If 'domain' is provided
// it is the Y plane's domain. This will automatically inset for bilinear filtering, and only
// the clamp wrap mode is supported.
- static std::unique_ptr<GrFragmentProcessor> Make(const sk_sp<GrTextureProxy> proxies[],
+ static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView views[],
const SkYUVAIndex indices[4],
SkYUVColorSpace yuvColorSpace,
GrSamplerState::Filter filterMode,
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index e2000e9..82730b7 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -271,15 +271,15 @@
return nullptr;
}
- sk_sp<GrTextureProxy> tempTextureProxies[4];
+ GrSurfaceProxyView tempViews[4];
if (!SkImage_GpuBase::MakeTempTextureProxies(ctx, yuvaTextures, numTextures, yuvaIndices,
- origin, tempTextureProxies)) {
+ origin, tempViews)) {
return nullptr;
}
const SkRect rect = SkRect::MakeIWH(size.width(), size.height());
if (!RenderYUVAToRGBA(ctx, renderTargetContext, rect, yuvColorSpace, nullptr,
- tempTextureProxies, yuvaIndices)) {
+ tempViews, yuvaIndices)) {
return nullptr;
}
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 6502979..eded6b2 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -5,6 +5,8 @@
* found in the LICENSE file.
*/
+#include "src/image/SkImage_GpuBase.h"
+
#include "include/core/SkPromiseImageTexture.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
@@ -20,7 +22,6 @@
#include "src/gpu/GrTextureAdjuster.h"
#include "src/gpu/effects/GrYUVtoRGBEffect.h"
#include "src/image/SkImage_Gpu.h"
-#include "src/image/SkImage_GpuBase.h"
#include "src/image/SkReadPixelsRec.h"
SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrContext> context, SkISize size, uint32_t uniqueID,
@@ -60,7 +61,6 @@
bool SkImage_GpuBase::ValidateCompressedBackendTexture(const GrCaps* caps,
const GrBackendTexture& tex,
SkAlphaType at) {
-
if (!tex.isValid() || tex.width() <= 0 || tex.height() <= 0) {
return false;
}
@@ -116,9 +116,8 @@
const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
- GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
- this->colorType(),
- view->proxy()->backendFormat());
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
+ fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
@@ -148,10 +147,9 @@
GrColorType grColorType = SkColorTypeToGrColorType(this->colorType());
- GrSurfaceProxyView copyView =
- GrSurfaceProxy::Copy(context, view->proxy(), view->origin(), grColorType,
- GrMipMapped::kNo, subset, SkBackingFit::kExact,
- view->proxy()->isBudgeted());
+ GrSurfaceProxyView copyView = GrSurfaceProxy::Copy(
+ context, view->proxy(), view->origin(), grColorType, GrMipMapped::kNo, subset,
+ SkBackingFit::kExact, view->proxy()->isBudgeted());
if (!copyView.proxy()) {
return nullptr;
@@ -176,9 +174,8 @@
const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
- GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
- this->colorType(),
- view->proxy()->backendFormat());
+ GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
+ fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
@@ -206,7 +203,7 @@
auto direct = fContext->priv().asDirectContext();
if (!direct) {
// This image was created with a DDL context and cannot be instantiated.
- return GrBackendTexture(); // invalid
+ return GrBackendTexture(); // invalid
}
const GrSurfaceProxyView* view = this->view(direct);
@@ -217,7 +214,7 @@
auto resourceProvider = direct->priv().resourceProvider();
if (!proxy->instantiate(resourceProvider)) {
- return GrBackendTexture(); // invalid
+ return GrBackendTexture(); // invalid
}
}
@@ -231,7 +228,7 @@
}
return texture->getBackendTexture();
}
- return GrBackendTexture(); // invalid
+ return GrBackendTexture(); // invalid
}
GrTexture* SkImage_GpuBase::onGetTexture() const {
@@ -272,7 +269,7 @@
bool SkImage_GpuBase::MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
int numTextures, const SkYUVAIndex yuvaIndices[4],
GrSurfaceOrigin imageOrigin,
- sk_sp<GrTextureProxy> tempTextureProxies[4]) {
+ GrSurfaceProxyView tempViews[4]) {
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
const GrCaps* caps = ctx->priv().caps();
@@ -283,20 +280,21 @@
}
GrColorType grColorType = caps->getYUVAColorTypeFromBackendFormat(
- backendFormat,
- yuvaIndices[3].fIndex == textureIndex);
+ backendFormat, yuvaIndices[3].fIndex == textureIndex);
if (GrColorType::kUnknown == grColorType) {
return false;
}
SkASSERT(yuvaTextures[textureIndex].isValid());
- tempTextureProxies[textureIndex] = proxyProvider->wrapBackendTexture(
- yuvaTextures[textureIndex], grColorType, imageOrigin, kBorrow_GrWrapOwnership,
- GrWrapCacheable::kNo, kRead_GrIOType);
- if (!tempTextureProxies[textureIndex]) {
+ auto proxy = proxyProvider->wrapBackendTexture(yuvaTextures[textureIndex], grColorType,
+ imageOrigin, kBorrow_GrWrapOwnership,
+ GrWrapCacheable::kNo, kRead_GrIOType);
+ if (!proxy) {
return false;
}
+ GrSwizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), grColorType);
+ tempViews[textureIndex] = GrSurfaceProxyView(std::move(proxy), imageOrigin, swizzle);
// Check that each texture contains the channel data for the corresponding YUVA index
auto componentFlags = GrColorTypeComponentFlags(grColorType);
@@ -304,11 +302,11 @@
if (yuvaIndices[yuvaIndex].fIndex == textureIndex) {
switch (yuvaIndices[yuvaIndex].fChannel) {
case SkColorChannel::kR:
- // TODO: Chrome needs to be patched before this can be
- // enforced.
-// if (!(kRed_SkColorTypeComponentFlag & componentFlags)) {
-// return false;
-// }
+ // TODO: Chrome needs to be patched before this can be
+ // enforced.
+ // if (!(kRed_SkColorTypeComponentFlag & componentFlags)) {
+ // return false;
+ // }
break;
case SkColorChannel::kG:
if (!(kGreen_SkColorTypeComponentFlag & componentFlags)) {
@@ -336,7 +334,7 @@
bool SkImage_GpuBase::RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
const SkRect& rect, SkYUVColorSpace yuvColorSpace,
sk_sp<GrColorSpaceXform> colorSpaceXform,
- const sk_sp<GrTextureProxy> proxies[4],
+ GrSurfaceProxyView views[4],
const SkYUVAIndex yuvaIndices[4]) {
SkASSERT(renderTargetContext);
if (!renderTargetContext->asSurfaceProxy()) {
@@ -347,7 +345,7 @@
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
const auto& caps = *ctx->priv().caps();
- auto fp = GrYUVtoRGBEffect::Make(proxies, yuvaIndices, yuvColorSpace,
+ auto fp = GrYUVtoRGBEffect::Make(views, yuvaIndices, yuvColorSpace,
GrSamplerState::Filter::kNearest, caps);
if (colorSpaceXform) {
fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform));
@@ -361,10 +359,8 @@
sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
GrContext* context, int width, int height, GrSurfaceOrigin origin, GrColorType colorType,
GrBackendFormat backendFormat, GrMipMapped mipMapped,
- PromiseImageTextureFulfillProc fulfillProc,
- PromiseImageTextureReleaseProc releaseProc,
- PromiseImageTextureDoneProc doneProc,
- PromiseImageTextureContext textureContext,
+ PromiseImageTextureFulfillProc fulfillProc, PromiseImageTextureReleaseProc releaseProc,
+ PromiseImageTextureDoneProc doneProc, PromiseImageTextureContext textureContext,
PromiseImageApiVersion version) {
SkASSERT(context);
SkASSERT(width > 0 && height > 0);
@@ -480,7 +476,7 @@
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 2, "promise");
builder[0] = promiseTexture->uniqueID();
- builder[1] = (uint32_t) fColorType;
+ builder[1] = (uint32_t)fColorType;
builder.finish();
// A texture with this key may already exist from a different instance of this lazy
// callback. This could happen if the client fulfills a promise image with a texture
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index 6337ff1..cc59705 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -56,7 +56,7 @@
static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
int numTextures, const SkYUVAIndex [4],
GrSurfaceOrigin imageOrigin,
- sk_sp<GrTextureProxy> tempTextureProxies[4]);
+ GrSurfaceProxyView tempViews[4]);
static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
@@ -87,7 +87,7 @@
static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
const SkRect& rect, SkYUVColorSpace yuvColorSpace,
sk_sp<GrColorSpaceXform> colorSpaceXform,
- const sk_sp<GrTextureProxy> proxies[4],
+ GrSurfaceProxyView views[4],
const SkYUVAIndex yuvaIndices[4]);
sk_sp<GrContext> fContext;
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 57217c4..3f23a2e 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -31,8 +31,8 @@
static constexpr auto kAssumedColorType = kRGBA_8888_SkColorType;
SkImage_GpuYUVA::SkImage_GpuYUVA(sk_sp<GrContext> context, SkISize size, uint32_t uniqueID,
- SkYUVColorSpace colorSpace, sk_sp<GrTextureProxy> proxies[],
- GrColorType proxyColorTypes[], int numProxies,
+ SkYUVColorSpace colorSpace, GrSurfaceProxyView views[],
+ GrColorType proxyColorTypes[], int numViews,
const SkYUVAIndex yuvaIndices[4], GrSurfaceOrigin origin,
sk_sp<SkColorSpace> imageColorSpace)
: INHERITED(std::move(context), size, uniqueID, kAssumedColorType,
@@ -40,19 +40,19 @@
// although the planar data is always un-premul, the final interleaved RGB image
// is/would-be premul.
GetAlphaTypeFromYUVAIndices(yuvaIndices), std::move(imageColorSpace))
- , fNumProxies(numProxies)
+ , fNumViews(numViews)
, fYUVColorSpace(colorSpace)
, fOrigin(origin) {
// The caller should have done this work, just verifying
SkDEBUGCODE(int textureCount;)
SkASSERT(SkYUVAIndex::AreValidIndices(yuvaIndices, &textureCount));
- SkASSERT(textureCount == fNumProxies);
+ SkASSERT(textureCount == fNumViews);
- for (int i = 0; i < numProxies; ++i) {
- fProxies[i] = std::move(proxies[i]);
+ for (int i = 0; i < numViews; ++i) {
+ fViews[i] = std::move(views[i]);
fProxyColorTypes[i] = proxyColorTypes[i];
}
- memcpy(fYUVAIndices, yuvaIndices, 4*sizeof(SkYUVAIndex));
+ memcpy(fYUVAIndices, yuvaIndices, 4 * sizeof(SkYUVAIndex));
}
// For onMakeColorSpace()
@@ -62,7 +62,7 @@
// although the planar data is always un-premul, the final interleaved RGB image
// is/would-be premul.
GetAlphaTypeFromYUVAIndices(image->fYUVAIndices), std::move(targetCS))
- , fNumProxies(image->fNumProxies)
+ , fNumViews(image->fNumViews)
, fYUVColorSpace(image->fYUVColorSpace)
, fOrigin(image->fOrigin)
// Since null fFromColorSpace means no GrColorSpaceXform, we turn a null
@@ -70,14 +70,14 @@
, fFromColorSpace(image->colorSpace() ? image->refColorSpace() : SkColorSpace::MakeSRGB()) {
// The caller should have done this work, just verifying
SkDEBUGCODE(int textureCount;)
- SkASSERT(SkYUVAIndex::AreValidIndices(image->fYUVAIndices, &textureCount));
- SkASSERT(textureCount == fNumProxies);
+ SkASSERT(SkYUVAIndex::AreValidIndices(image->fYUVAIndices, &textureCount));
+ SkASSERT(textureCount == fNumViews);
if (image->fRGBView.proxy()) {
fRGBView = image->fRGBView; // we ref in this case, not move
} else {
- for (int i = 0; i < fNumProxies; ++i) {
- fProxies[i] = image->fProxies[i]; // we ref in this case, not move
+ for (int i = 0; i < fNumViews; ++i) {
+ fViews[i] = image->fViews[i]; // we ref in this case, not move
fProxyColorTypes[i] = image->fProxyColorTypes[i];
}
}
@@ -86,24 +86,25 @@
bool SkImage_GpuYUVA::setupMipmapsForPlanes(GrRecordingContext* context) const {
// We shouldn't get here if the planes were already flattened to RGBA.
- SkASSERT(fProxies[0] && !fRGBView.proxy());
+ SkASSERT(fViews[0].proxy() && !fRGBView.proxy());
if (!context || !fContext->priv().matches(context)) {
return false;
}
- for (int i = 0; i < fNumProxies; ++i) {
+ for (int i = 0; i < fNumViews; ++i) {
GrTextureProducer::CopyParams copyParams;
- int mipCount = SkMipMap::ComputeLevelCount(fProxies[i]->width(), fProxies[i]->height());
+ int mipCount = SkMipMap::ComputeLevelCount(fViews[i].proxy()->width(),
+ fViews[i].proxy()->height());
if (mipCount && GrGpu::IsACopyNeededForMips(fContext->priv().caps(),
- fProxies[i].get(),
+ fViews[i].asTextureProxy(),
GrSamplerState::Filter::kMipMap,
©Params)) {
- auto mippedView = GrCopyBaseMipMapToTextureProxy(context, fProxies[i].get(), fOrigin,
- fProxyColorTypes[i]);
+ auto mippedView = GrCopyBaseMipMapToTextureProxy(context, fViews[i].asTextureProxy(),
+ fOrigin, fProxyColorTypes[i]);
if (!mippedView.proxy()) {
return false;
}
- fProxies[i] = mippedView.asTextureProxyRef();
+ fViews[i] = std::move(mippedView);
}
}
return true;
@@ -116,9 +117,9 @@
return GrSemaphoresSubmitted::kNo;
}
- GrSurfaceProxy* proxies[4] = {fProxies[0].get(), fProxies[1].get(),
- fProxies[2].get(), fProxies[3].get()};
- int numProxies = fNumProxies;
+ GrSurfaceProxy* proxies[4] = {fViews[0].proxy(), fViews[1].proxy(), fViews[2].proxy(),
+ fViews[3].proxy()};
+ int numProxies = fNumViews;
if (fRGBView.proxy()) {
// Either we've already flushed the flattening draw or the flattening is unflushed. In the
// latter case it should still be ok to just pass fRGBView proxy because it in turn depends
@@ -129,9 +130,7 @@
return context->priv().flushSurfaces(proxies, numProxies, info);
}
-GrTextureProxy* SkImage_GpuYUVA::peekProxy() const {
- return fRGBView.asTextureProxy();
-}
+GrTextureProxy* SkImage_GpuYUVA::peekProxy() const { return fRGBView.asTextureProxy(); }
void SkImage_GpuYUVA::flattenToRGB(GrRecordingContext* context) const {
if (fRGBView.proxy()) {
@@ -157,15 +156,15 @@
}
const SkRect rect = SkRect::MakeIWH(this->width(), this->height());
if (!RenderYUVAToRGBA(fContext.get(), renderTargetContext.get(), rect, fYUVColorSpace,
- std::move(colorSpaceXform), fProxies, fYUVAIndices)) {
+ std::move(colorSpaceXform), fViews, fYUVAIndices)) {
return;
}
fRGBView = renderTargetContext->readSurfaceView();
SkASSERT(fRGBView.origin() == fOrigin);
SkASSERT(fRGBView.swizzle() == GrSwizzle());
- for (auto& p : fProxies) {
- p.reset();
+ for (auto& v : fViews) {
+ v.reset();
}
}
@@ -178,8 +177,8 @@
// need to generate mips for the proxy
GrColorType srcColorType = SkColorTypeToGrColorType(this->colorType());
- GrSurfaceProxyView mippedView = GrCopyBaseMipMapToTextureProxy(
- context, fRGBView.proxy(), fRGBView.origin(), srcColorType);
+ GrSurfaceProxyView mippedView = GrCopyBaseMipMapToTextureProxy(context, fRGBView.proxy(),
+ fRGBView.origin(), srcColorType);
if (mippedView.proxy()) {
fRGBView = std::move(mippedView);
return fRGBView;
@@ -199,9 +198,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
-sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorTypeAndColorSpace(GrRecordingContext*,
- SkColorType,
- sk_sp<SkColorSpace> targetCS) const {
+sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorTypeAndColorSpace(
+ GrRecordingContext*, SkColorType, sk_sp<SkColorSpace> targetCS) const {
// We explicitly ignore color type changes, for now.
// we may need a mutex here but for now we expect usage to be in a single thread
@@ -219,7 +217,7 @@
sk_sp<SkImage> SkImage_GpuYUVA::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {
return sk_make_sp<SkImage_GpuYUVA>(fContext, this->dimensions(), kNeedNewImageUniqueID,
- fYUVColorSpace, fProxies, fProxyColorTypes, fNumProxies,
+ fYUVColorSpace, fViews, fProxyColorTypes, fNumViews,
fYUVAIndices, fOrigin, std::move(newCS));
}
@@ -237,9 +235,9 @@
return nullptr;
}
- sk_sp<GrTextureProxy> tempTextureProxies[4];
+ GrSurfaceProxyView tempViews[4];
if (!SkImage_GpuBase::MakeTempTextureProxies(ctx, yuvaTextures, numTextures, yuvaIndices,
- imageOrigin, tempTextureProxies)) {
+ imageOrigin, tempViews)) {
return nullptr;
}
GrColorType proxyColorTypes[4];
@@ -249,16 +247,18 @@
}
return sk_make_sp<SkImage_GpuYUVA>(sk_ref_sp(ctx), imageSize, kNeedNewImageUniqueID, colorSpace,
- tempTextureProxies, proxyColorTypes, numTextures,
- yuvaIndices, imageOrigin, imageColorSpace);
+ tempViews, proxyColorTypes, numTextures, yuvaIndices,
+ imageOrigin, imageColorSpace);
}
-sk_sp<SkImage> SkImage::MakeFromYUVAPixmaps(
- GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[],
- const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin,
- bool buildMips, bool limitToMaxTextureSize, sk_sp<SkColorSpace> imageColorSpace) {
+sk_sp<SkImage> SkImage::MakeFromYUVAPixmaps(GrContext* context, SkYUVColorSpace yuvColorSpace,
+ const SkPixmap yuvaPixmaps[],
+ const SkYUVAIndex yuvaIndices[4], SkISize imageSize,
+ GrSurfaceOrigin imageOrigin, bool buildMips,
+ bool limitToMaxTextureSize,
+ sk_sp<SkColorSpace> imageColorSpace) {
if (!context) {
- return nullptr; // until we impl this for raster backend
+ return nullptr; // until we impl this for raster backend
}
int numPixmaps;
@@ -271,7 +271,7 @@
}
// Make proxies
- sk_sp<GrTextureProxy> tempTextureProxies[4];
+ GrSurfaceProxyView tempViews[4];
GrColorType proxyColorTypes[4];
for (int i = 0; i < numPixmaps; ++i) {
const SkPixmap* pixmap = &yuvaPixmaps[i];
@@ -280,10 +280,9 @@
int maxDim = SkTMax(yuvaPixmaps[i].width(), yuvaPixmaps[i].height());
if (limitToMaxTextureSize && maxDim > maxTextureSize) {
float scale = static_cast<float>(maxTextureSize) / maxDim;
- int newWidth = SkTMin(static_cast<int>(yuvaPixmaps[i].width() * scale),
- maxTextureSize);
- int newHeight = SkTMin(static_cast<int>(yuvaPixmaps[i].height() * scale),
- maxTextureSize);
+ int newWidth = SkTMin(static_cast<int>(yuvaPixmaps[i].width() * scale), maxTextureSize);
+ int newHeight =
+ SkTMin(static_cast<int>(yuvaPixmaps[i].height() * scale), maxTextureSize);
SkImageInfo info = yuvaPixmaps[i].info().makeWH(newWidth, newHeight);
if (!resized.tryAlloc(info) ||
!yuvaPixmaps[i].scalePixels(resized, kLow_SkFilterQuality)) {
@@ -297,19 +296,17 @@
GrBitmapTextureMaker bitmapMaker(context, bmp);
GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo;
GrSurfaceProxyView view;
- std::tie(view, proxyColorTypes[i]) = bitmapMaker.view(mipMapped);
- if (!view.proxy()) {
+ std::tie(tempViews[i], proxyColorTypes[i]) = bitmapMaker.view(mipMapped);
+ if (!tempViews[i]) {
return nullptr;
}
- tempTextureProxies[i] = view.asTextureProxyRef();
}
return sk_make_sp<SkImage_GpuYUVA>(sk_ref_sp(context), imageSize, kNeedNewImageUniqueID,
- yuvColorSpace, tempTextureProxies, proxyColorTypes,
- numPixmaps, yuvaIndices, imageOrigin, imageColorSpace);
+ yuvColorSpace, tempViews, proxyColorTypes, numPixmaps,
+ yuvaIndices, imageOrigin, imageColorSpace);
}
-
/////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(
GrContext* context,
@@ -356,8 +353,8 @@
SkAlphaType at = (-1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex) ? kPremul_SkAlphaType
: kOpaque_SkAlphaType;
- SkImageInfo info = SkImageInfo::Make(imageWidth, imageHeight, kAssumedColorType,
- at, imageColorSpace);
+ SkImageInfo info =
+ SkImageInfo::Make(imageWidth, imageHeight, kAssumedColorType, at, imageColorSpace);
if (!SkImageInfoIsValid(info)) {
return nullptr;
}
@@ -375,29 +372,31 @@
}
// Get lazy proxies
- sk_sp<GrTextureProxy> proxies[4];
+ GrSurfaceProxyView views[4];
GrColorType proxyColorTypes[4];
for (int texIdx = 0; texIdx < numTextures; ++texIdx) {
GrColorType colorType = context->priv().caps()->getYUVAColorTypeFromBackendFormat(
- yuvaFormats[texIdx],
- yuvaIndices[3].fIndex == texIdx);
+ yuvaFormats[texIdx], yuvaIndices[3].fIndex == texIdx);
if (GrColorType::kUnknown == colorType) {
return nullptr;
}
- proxies[texIdx] = MakePromiseImageLazyProxy(
+ auto proxy = MakePromiseImageLazyProxy(
context, yuvaSizes[texIdx].width(), yuvaSizes[texIdx].height(), imageOrigin,
colorType, yuvaFormats[texIdx], GrMipMapped::kNo, textureFulfillProc,
textureReleaseProc, promiseDoneProc, textureContexts[texIdx], version);
++proxiesCreated;
- if (!proxies[texIdx]) {
+ if (!proxy) {
return nullptr;
}
+ GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
+ colorType);
+ views[texIdx] = GrSurfaceProxyView(std::move(proxy), imageOrigin, swizzle);
proxyColorTypes[texIdx] = colorType;
}
return sk_make_sp<SkImage_GpuYUVA>(sk_ref_sp(context), SkISize{imageWidth, imageHeight},
- kNeedNewImageUniqueID, yuvColorSpace, proxies,
+ kNeedNewImageUniqueID, yuvColorSpace, views,
proxyColorTypes, numTextures, yuvaIndices, imageOrigin,
std::move(imageColorSpace));
}
diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h
index 914a1fc..6688d14 100644
--- a/src/image/SkImage_GpuYUVA.h
+++ b/src/image/SkImage_GpuYUVA.h
@@ -25,7 +25,7 @@
friend class GrYUVAImageTextureMaker;
SkImage_GpuYUVA(sk_sp<GrContext>, SkISize size, uint32_t uniqueID, SkYUVColorSpace,
- sk_sp<GrTextureProxy> proxies[], GrColorType proxyColorTypes[], int numProxies,
+ GrSurfaceProxyView views[], GrColorType proxyColorTypes[], int numViews,
const SkYUVAIndex[4], GrSurfaceOrigin, sk_sp<SkColorSpace>);
GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
@@ -37,7 +37,7 @@
const GrSurfaceProxyView* view(GrRecordingContext* context) const override;
bool onIsTextureBacked() const override {
- SkASSERT(fProxies[0] || fRGBView.proxy());
+ SkASSERT(fViews[0].proxy() || fRGBView.proxy());
return true;
}
@@ -56,7 +56,7 @@
#if GR_TEST_UTILS
bool testingOnly_IsFlattened() const {
// We should only have the flattened proxy or the planar proxies at one point in time.
- SkASSERT(SkToBool(fRGBView.proxy()) != SkToBool(fProxies[0]));
+ SkASSERT(SkToBool(fRGBView.proxy()) != SkToBool(fViews[0].proxy()));
return SkToBool(fRGBView.proxy());
}
#endif
@@ -86,9 +86,9 @@
// This array will usually only be sparsely populated.
// The actual non-null fields are dictated by the 'fYUVAIndices' indices
- mutable sk_sp<GrTextureProxy> fProxies[4];
+ mutable GrSurfaceProxyView fViews[4];
mutable GrColorType fProxyColorTypes[4];
- int fNumProxies;
+ int fNumViews;
SkYUVAIndex fYUVAIndices[4];
const SkYUVColorSpace fYUVColorSpace;
GrSurfaceOrigin fOrigin;