This is split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors)
Change-Id: I302e6b4c1ffed449a990288ec06f2dfdcdadf1f8
Reviewed-on: https://skia-review.googlesource.com/9448
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
kLockTexturePathCount);
GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider());
if (tex2) {
- return set_key_and_return(ctx->resourceProvider(), SkSafeRef(tex2), key);
+ return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key);
}
}
}
if (!ctx->contextPriv().disableGpuYUVConversion()) {
ScopedGenerator generator(fSharedGenerator);
Generator_GrYUVProvider provider(generator);
- sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true);
- if (tex) {
+ if (sk_sp<GrTextureProxy> proxy = provider.refAsTextureProxy(ctx, desc, true)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
- return set_key_and_return(ctx->resourceProvider(), tex.release(), key);
+ GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider());
+ if (tex2) {
+ return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key);
+ }
}
}
SkYUVColorSpace colorSpace);
};
-static bool convert_texture(GrTexture* src, GrRenderTargetContext* dst, int dstW, int dstH,
- SkYUVColorSpace colorSpace, MakeFPProc proc) {
+static bool convert_proxy(GrContext* context, sk_sp<GrTextureProxy> src,
+ GrRenderTargetContext* dst, int dstW, int dstH,
+ SkYUVColorSpace colorSpace, MakeFPProc proc) {
SkScalar xScale = SkIntToScalar(src->width()) / dstW;
SkScalar yScale = SkIntToScalar(src->height()) / dstH;
filter = GrSamplerParams::kBilerp_FilterMode;
}
- sk_sp<GrFragmentProcessor> fp(
- GrSimpleTextureEffect::Make(src, nullptr, SkMatrix::MakeScale(xScale, yScale), filter));
+ sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(context, std::move(src), nullptr,
+ SkMatrix::MakeScale(xScale, yScale),
+ filter));
if (!fp) {
return false;
}
return true;
}
-bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* const planes[3],
+bool GrTextureToYUVPlanes(GrContext* context, sk_sp<GrTextureProxy> proxy,
+ const SkISize sizes[3], void* const planes[3],
const size_t rowBytes[3], SkYUVColorSpace colorSpace) {
- if (GrContext* context = texture->getContext()) {
+ if (!context) {
+ return false;
+ }
+
+ {
// Depending on the relative sizes of the y, u, and v planes we may do 1 to 3 draws/
// readbacks.
sk_sp<GrRenderTargetContext> yuvRenderTargetContext;
// Do all the draws before any readback.
if (yuvRenderTargetContext) {
- if (!convert_texture(texture, yuvRenderTargetContext.get(),
- sizes[0].fWidth, sizes[0].fHeight,
- colorSpace, GrYUVEffect::MakeRGBToYUV)) {
+ if (!convert_proxy(context, std::move(proxy), yuvRenderTargetContext.get(),
+ sizes[0].fWidth, sizes[0].fHeight,
+ colorSpace, GrYUVEffect::MakeRGBToYUV)) {
return false;
}
} else {
SkASSERT(yRenderTargetContext);
- if (!convert_texture(texture, yRenderTargetContext.get(),
- sizes[0].fWidth, sizes[0].fHeight,
- colorSpace, GrYUVEffect::MakeRGBToY)) {
+ if (!convert_proxy(context, proxy, yRenderTargetContext.get(),
+ sizes[0].fWidth, sizes[0].fHeight,
+ colorSpace, GrYUVEffect::MakeRGBToY)) {
return false;
}
if (uvRenderTargetContext) {
- if (!convert_texture(texture, uvRenderTargetContext.get(),
- sizes[1].fWidth, sizes[1].fHeight,
- colorSpace, GrYUVEffect::MakeRGBToUV)) {
+ if (!convert_proxy(context, std::move(proxy), uvRenderTargetContext.get(),
+ sizes[1].fWidth, sizes[1].fHeight,
+ colorSpace, GrYUVEffect::MakeRGBToUV)) {
return false;
}
} else {
SkASSERT(uRenderTargetContext && vRenderTargetContext);
- if (!convert_texture(texture, uRenderTargetContext.get(),
- sizes[1].fWidth, sizes[1].fHeight,
- colorSpace, GrYUVEffect::MakeRGBToU)) {
+ if (!convert_proxy(context, proxy, uRenderTargetContext.get(),
+ sizes[1].fWidth, sizes[1].fHeight,
+ colorSpace, GrYUVEffect::MakeRGBToU)) {
return false;
}
- if (!convert_texture(texture, vRenderTargetContext.get(),
- sizes[2].fWidth, sizes[2].fHeight,
- colorSpace, GrYUVEffect::MakeRGBToV)) {
+ if (!convert_proxy(context, std::move(proxy), vRenderTargetContext.get(),
+ sizes[2].fWidth, sizes[2].fHeight,
+ colorSpace, GrYUVEffect::MakeRGBToV)) {
return false;
}
}
#include "SkImageInfo.h"
#include "SkSize.h"
-class GrTexture;
+class GrContext;
+class GrTextureProxy;
-bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize[3], void* const planes[3],
+bool GrTextureToYUVPlanes(GrContext*, sk_sp<GrTextureProxy>,
+ const SkISize[3], void* const planes[3],
const size_t rowBytes[3], SkYUVColorSpace);
#endif
return true;
}
-sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
- const GrSurfaceDesc& desc,
- bool useCache) {
+sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx,
+ const GrSurfaceDesc& desc,
+ bool useCache) {
SkYUVPlanesCache::Info yuvInfo;
void* planes[3];
YUVScoper scoper;
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r);
- return renderTargetContext->asTexture();
+ return renderTargetContext->asTextureProxyRef();
}
virtual ~GrYUVProvider() {}
/**
- * On success, this returns a texture that has converted the YUV data from the provider
+ * On success, this returns a texture proxy that has converted the YUV data from the provider
* into a form that is supported by the GPU (typically transformed into RGB). If useCache
* is true, then the texture will automatically have a key added, so it can be retrieved
* from the cache (assuming it is requested by a provider w/ the same genID).
*
* On failure (e.g. the provider had no data), this returns NULL.
*/
- sk_sp<GrTexture> refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache);
+ sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*, const GrSurfaceDesc&, bool useCache);
virtual uint32_t onGetID() = 0;
#include "SkPicture.h"
#include "SkPixelRef.h"
#include "SkPixelSerializer.h"
+#include "SkRGBAToYUV.h"
#include "SkReadPixelsRec.h"
#include "SkSpecialImage.h"
#include "SkStream.h"
}
}
+bool SkImage_Base::onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
+ const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
+ return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
}
-#if SK_SUPPORT_GPU
-#include "GrTextureToYUVPlanes.h"
-#endif
-
-#include "SkRGBAToYUV.h"
-
bool SkImage::readYUV8Planes(const SkISize sizes[3], void* const planes[3],
const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
-#if SK_SUPPORT_GPU
- if (GrTexture* texture = as_IB(this)->peekTexture()) {
- if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace)) {
- return true;
- }
- }
-#endif
- return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace);
+ return as_IB(this)->onReadYUV8Planes(sizes, planes, rowBytes, colorSpace);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
virtual const SkBitmap* onPeekBitmap() const { return nullptr; }
+ virtual bool onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
+ const size_t rowBytes[3], SkYUVColorSpace colorSpace) const;
+
virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY, CachingHint) const = 0;
#include "GrTextureAdjuster.h"
#include "GrTexturePriv.h"
#include "GrTextureProxy.h"
+#include "GrTextureToYUVPlanes.h"
#include "effects/GrYUVEffect.h"
#include "SkCanvas.h"
#include "SkCrossContextImageData.h"
}
}
+bool SkImage_Gpu::onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
+ const size_t rowBytes[3], SkYUVColorSpace colorSpace) const {
+ if (sk_sp<GrTextureProxy> proxy = as_IB(this)->asTextureProxyRef()) {
+ if (GrTextureToYUVPlanes(fTexture->getContext(), std::move(proxy), sizes, planes,
+ rowBytes, colorSpace)) {
+ return true;
+ }
+ }
+
+ return INHERITED::onReadYUV8Planes(sizes, planes, rowBytes, colorSpace);
+}
+
bool SkImage_Gpu::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint) const {
if (!SkImageInfoValidConversion(dstInfo, this->onImageInfo())) {
*uniqueID = this->uniqueID();
return fTexture;
}
+
+ bool onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
+ const size_t rowBytes[3], SkYUVColorSpace colorSpace) const override;
+
bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY, CachingHint) const override;