Switch GrYUVProvider over to GrTextureProxies
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>
This commit is contained in:
parent
f141fff87a
commit
538f1a36e3
@ -557,7 +557,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -581,11 +581,13 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,9 @@ namespace {
|
||||
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;
|
||||
@ -31,8 +32,9 @@ static bool convert_texture(GrTexture* src, GrRenderTargetContext* dst, int dstW
|
||||
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;
|
||||
}
|
||||
@ -48,9 +50,14 @@ static bool convert_texture(GrTexture* src, GrRenderTargetContext* dst, int dstW
|
||||
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;
|
||||
@ -114,34 +121,34 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,11 @@
|
||||
#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
|
||||
|
@ -84,9 +84,9 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v
|
||||
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;
|
||||
@ -159,5 +159,5 @@ sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
|
||||
|
||||
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r);
|
||||
|
||||
return renderTargetContext->asTexture();
|
||||
return renderTargetContext->asTextureProxyRef();
|
||||
}
|
||||
|
@ -28,14 +28,14 @@ public:
|
||||
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;
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "SkPicture.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkPixelSerializer.h"
|
||||
#include "SkRGBAToYUV.h"
|
||||
#include "SkReadPixelsRec.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkStream.h"
|
||||
@ -211,28 +212,20 @@ SkImage_Base::~SkImage_Base() {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -41,6 +41,9 @@ public:
|
||||
|
||||
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;
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "GrTextureAdjuster.h"
|
||||
#include "GrTexturePriv.h"
|
||||
#include "GrTextureProxy.h"
|
||||
#include "GrTextureToYUVPlanes.h"
|
||||
#include "effects/GrYUVEffect.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkCrossContextImageData.h"
|
||||
@ -134,6 +135,18 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
|
||||
}
|
||||
}
|
||||
|
||||
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())) {
|
||||
|
@ -49,6 +49,10 @@ public:
|
||||
*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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user