Store GrSurfaceProxyView on SkImage.
Bug: skia:9556 Change-Id: I57340db52ce2e317acb6d1f88190460186350f5d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259435 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
d0840ecf58
commit
81b98978bc
@ -26,6 +26,7 @@
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "include/private/SkTArray.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/image/SkImage_Base.h"
|
||||
#include "src/image/SkImage_Gpu.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
@ -130,14 +131,18 @@ static sk_sp<SkImage> make_reference_image(GrContext* context,
|
||||
|
||||
auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
|
||||
|
||||
// TODO: make MakeTextureProxyFromData return a GrSurfaceProxyView
|
||||
auto proxy = sk_gpu_test::MakeTextureProxyFromData(context, GrRenderable::kNo, origin,
|
||||
bm.info(), bm.getPixels(), bm.rowBytes());
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSwizzle swizzle = context->priv().caps()->getTextureSwizzle(proxy->backendFormat(),
|
||||
GrColorType::kRGBA_8888);
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
|
||||
std::move(proxy), nullptr);
|
||||
std::move(view), nullptr);
|
||||
}
|
||||
|
||||
// Here we're converting from a matrix that is intended for UVs to a matrix that is intended
|
||||
|
@ -281,10 +281,16 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: The asTextureProxyRef which takes a sampler and adjust needs to return a
|
||||
// GrSurfaceProxyView instead. For now we just grab the info off the proxy.
|
||||
GrSurfaceOrigin origin = proxy->origin();
|
||||
const GrSwizzle& swizzle = proxy->textureSwizzle();
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
|
||||
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
|
||||
sk_sp<SkImage> texImage(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()),
|
||||
image->uniqueID(), kPremul_SkAlphaType,
|
||||
std::move(proxy), image->refColorSpace()));
|
||||
std::move(view), image->refColorSpace()));
|
||||
canvas->drawImage(texImage.get(), x, y);
|
||||
}
|
||||
|
||||
|
@ -370,9 +370,14 @@ sk_sp<SkSpecialImage> SkSpecialImage::CopyFromRaster(const SkIRect& subset,
|
||||
static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, sk_sp<GrTextureProxy> proxy,
|
||||
SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {
|
||||
// CONTEXT TODO: remove this use of 'backdoor' to create an SkImage
|
||||
// TODO: Once SkSpecialImage stores a GrSurfaceProxyView instead of a proxy, use that to create
|
||||
// the view here.
|
||||
GrSurfaceOrigin origin = proxy->origin();
|
||||
const GrSwizzle& swizzle = proxy->textureSwizzle();
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context->priv().backdoor()),
|
||||
kNeedNewImageUniqueID, alphaType,
|
||||
std::move(proxy), std::move(colorSpace));
|
||||
std::move(view), std::move(colorSpace));
|
||||
}
|
||||
|
||||
class SkSpecialImage_Gpu : public SkSpecialImage_Base {
|
||||
@ -407,6 +412,9 @@ public:
|
||||
SkRect dst = SkRect::MakeXYWH(x, y,
|
||||
this->subset().width(), this->subset().height());
|
||||
|
||||
GrSurfaceOrigin origin = fTextureProxy->origin();
|
||||
const GrSwizzle& swizzle = fTextureProxy->textureSwizzle();
|
||||
GrSurfaceProxyView view(fTextureProxy, origin, swizzle);
|
||||
// TODO: In this instance we know we're going to draw a sub-portion of the backing
|
||||
// texture into the canvas so it is okay to wrap it in an SkImage. This poses
|
||||
// some problems for full deferral however in that when the deferred SkImage_Gpu
|
||||
@ -415,7 +423,7 @@ public:
|
||||
// to be tightened (if it is deferred).
|
||||
sk_sp<SkImage> img =
|
||||
sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()), this->uniqueID(),
|
||||
fAlphaType, fTextureProxy, fColorSpace));
|
||||
fAlphaType, std::move(view), fColorSpace));
|
||||
|
||||
canvas->drawImageRect(img, this->subset(),
|
||||
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
|
@ -288,8 +288,7 @@ sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format,
|
||||
|
||||
SkASSERT(views[index].proxy()->priv().isExact());
|
||||
sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
|
||||
kPremul_SkAlphaType, views[index].asTextureProxyRef(),
|
||||
nullptr));
|
||||
kPremul_SkAlphaType, views[index], nullptr));
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "include/private/SkTDArray.h"
|
||||
#include "src/gpu/GrSurfaceProxyView.h"
|
||||
#include "src/gpu/GrTextureProxy.h"
|
||||
|
||||
class GrRecordingContext;
|
||||
@ -57,6 +58,13 @@ public:
|
||||
// that single backing proxy will be returned.
|
||||
virtual GrTextureProxy* peekProxy() const { return nullptr; }
|
||||
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const { return nullptr; }
|
||||
|
||||
// This returns a copy of the GrSurfaceProxyView which essentially refs the contained
|
||||
// GrSurfaceProxy. Callers should check if the proxy of the returned view is null.
|
||||
virtual GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext*) const {
|
||||
return GrSurfaceProxyView();
|
||||
}
|
||||
|
||||
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&,
|
||||
SkScalar scaleAdjust[2]) const = 0;
|
||||
virtual sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext*,
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "src/gpu/gl/GrGLTexture.h"
|
||||
#include "src/image/SkImage_Gpu.h"
|
||||
|
||||
static SkColorType proxy_color_type(GrTextureProxy* proxy) {
|
||||
static SkColorType proxy_color_type(GrSurfaceProxy* proxy) {
|
||||
SkColorType colorType;
|
||||
if (!GrPixelConfigToColorType(proxy->config(), &colorType)) {
|
||||
colorType = kUnknown_SkColorType;
|
||||
@ -55,10 +55,10 @@ static SkColorType proxy_color_type(GrTextureProxy* proxy) {
|
||||
}
|
||||
|
||||
SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, SkAlphaType at,
|
||||
sk_sp<GrTextureProxy> proxy, sk_sp<SkColorSpace> colorSpace)
|
||||
: INHERITED(std::move(context), proxy->backingStoreDimensions(), uniqueID,
|
||||
proxy_color_type(proxy.get()), at, colorSpace)
|
||||
, fProxy(std::move(proxy)) {}
|
||||
GrSurfaceProxyView view, sk_sp<SkColorSpace> colorSpace)
|
||||
: INHERITED(std::move(context), view.proxy()->backingStoreDimensions(), uniqueID,
|
||||
proxy_color_type(view.proxy()), at, colorSpace)
|
||||
, fView(std::move(view)) {}
|
||||
|
||||
SkImage_Gpu::~SkImage_Gpu() {}
|
||||
|
||||
@ -67,7 +67,7 @@ GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrContext* context, const GrFlushInfo
|
||||
return GrSemaphoresSubmitted::kNo;
|
||||
}
|
||||
|
||||
GrSurfaceProxy* p[1] = {fProxy.get()};
|
||||
GrSurfaceProxy* p[1] = {fView.proxy()};
|
||||
return context->priv().flushSurfaces(p, 1, info);
|
||||
}
|
||||
|
||||
@ -82,8 +82,6 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* con
|
||||
targetCS.get(), this->alphaType());
|
||||
SkASSERT(xform || targetCT != this->colorType());
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef(context);
|
||||
|
||||
auto renderTargetContext = context->priv().makeDeferredRenderTargetContextWithFallback(
|
||||
SkBackingFit::kExact, this->width(), this->height(), SkColorTypeToGrColorType(targetCT),
|
||||
nullptr);
|
||||
@ -93,6 +91,7 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* con
|
||||
|
||||
GrPaint paint;
|
||||
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
||||
sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef(context);
|
||||
paint.addColorTextureProcessor(std::move(proxy), this->alphaType(), SkMatrix::I());
|
||||
if (xform) {
|
||||
paint.addColorFragmentProcessor(std::move(xform));
|
||||
@ -106,11 +105,11 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* con
|
||||
|
||||
// MDB: this call is okay bc we know 'renderTargetContext' was exact
|
||||
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
|
||||
renderTargetContext->asTextureProxyRef(), std::move(targetCS));
|
||||
renderTargetContext->textureSurfaceView(), std::move(targetCS));
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {
|
||||
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(), fProxy,
|
||||
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(), fView,
|
||||
std::move(newCS));
|
||||
}
|
||||
|
||||
@ -135,7 +134,10 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(proxy),
|
||||
|
||||
GrSwizzle swizzle = ctx->priv().caps()->getTextureSwizzle(proxy->backendFormat(), colorType);
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(view),
|
||||
std::move(colorSpace));
|
||||
}
|
||||
|
||||
@ -191,13 +193,16 @@ sk_sp<SkImage> SkImage::MakeFromCompressed(GrContext* context, sk_sp<SkData> dat
|
||||
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
||||
sk_sp<GrTextureProxy> proxy = proxyProvider->createCompressedTextureProxy(
|
||||
width, height, SkBudgeted::kYes, type, std::move(data));
|
||||
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
// TODO: remove asserts when proxy doesn't hold origin or swizzle
|
||||
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
|
||||
SkASSERT(proxy->textureSwizzle() == GrSwizzle());
|
||||
GrSurfaceProxyView view(std::move(proxy));
|
||||
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
|
||||
std::move(proxy), nullptr);
|
||||
std::move(view), nullptr);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorSpace yuvColorSpace,
|
||||
@ -227,7 +232,7 @@ sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorS
|
||||
SkAlphaType at = GetAlphaTypeFromYUVAIndices(yuvaIndices);
|
||||
// MDB: this call is okay bc we know 'renderTargetContext' was exact
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at,
|
||||
renderTargetContext->asTextureProxyRef(),
|
||||
renderTargetContext->textureSurfaceView(),
|
||||
renderTargetContext->colorInfo().refColorSpace());
|
||||
}
|
||||
|
||||
@ -359,11 +364,15 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
|
||||
static sk_sp<SkImage> create_image_from_producer(GrContext* context, GrTextureProducer* producer,
|
||||
SkAlphaType at, uint32_t id,
|
||||
GrMipMapped mipMapped) {
|
||||
// TODO: have texture producer return a GrSurfaceProxyView
|
||||
sk_sp<GrTextureProxy> proxy(producer->refTextureProxy(mipMapped));
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, at, std::move(proxy),
|
||||
GrSurfaceOrigin origin = proxy->origin();
|
||||
const GrSwizzle& swizzle = proxy->textureSwizzle();
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, at, std::move(view),
|
||||
sk_ref_sp(producer->colorSpace()));
|
||||
}
|
||||
|
||||
@ -454,8 +463,10 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
GrSwizzle swizzle = context->priv().caps()->getTextureSwizzle(backendFormat, grColorType);
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, alphaType,
|
||||
std::move(proxy), std::move(colorSpace));
|
||||
std::move(view), std::move(colorSpace));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -584,8 +595,10 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
|
||||
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
|
||||
SkAlphaType at = pixmap.alphaType();
|
||||
|
||||
GrSwizzle swizzle = context->priv().caps()->getTextureSwizzle(backendFormat, grColorType);
|
||||
GrSurfaceProxyView view(proxy, surfaceOrigin, swizzle);
|
||||
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, at,
|
||||
proxy, cs);
|
||||
std::move(view), cs);
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "src/core/SkImagePriv.h"
|
||||
#include "src/gpu/GrGpuResourcePriv.h"
|
||||
#include "src/gpu/GrSurfaceProxyPriv.h"
|
||||
#include "src/gpu/GrSurfaceProxyView.h"
|
||||
#include "src/gpu/SkGr.h"
|
||||
#include "src/image/SkImage_GpuBase.h"
|
||||
|
||||
@ -22,21 +23,25 @@ struct SkYUVAIndex;
|
||||
|
||||
class SkImage_Gpu : public SkImage_GpuBase {
|
||||
public:
|
||||
SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
|
||||
SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, SkAlphaType, GrSurfaceProxyView,
|
||||
sk_sp<SkColorSpace>);
|
||||
~SkImage_Gpu() override;
|
||||
|
||||
GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
|
||||
|
||||
GrTextureProxy* peekProxy() const override {
|
||||
return fProxy.get();
|
||||
return fView.asTextureProxy();
|
||||
}
|
||||
sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const override {
|
||||
return fProxy;
|
||||
return fView.asTextureProxyRef();
|
||||
}
|
||||
|
||||
GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext* context) const override {
|
||||
return fView;
|
||||
}
|
||||
|
||||
bool onIsTextureBacked() const override {
|
||||
SkASSERT(fProxy);
|
||||
SkASSERT(fView.proxy());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -70,7 +75,7 @@ public:
|
||||
GrRenderTargetContext*);
|
||||
|
||||
private:
|
||||
sk_sp<GrTextureProxy> fProxy;
|
||||
GrSurfaceProxyView fView;
|
||||
|
||||
typedef SkImage_GpuBase INHERITED;
|
||||
};
|
||||
|
@ -124,9 +124,15 @@ sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(GrRecordingContext* context,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceProxyView currView = this->asSurfaceProxyViewRef(context);
|
||||
if (!currView.proxy()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceProxyView view(std::move(copyProxy), currView.origin(), currView.swizzle());
|
||||
// MDB: this call is okay bc we know 'sContext' was kExact
|
||||
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
|
||||
std::move(copyProxy), this->refColorSpace());
|
||||
std::move(view), this->refColorSpace());
|
||||
}
|
||||
|
||||
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
|
||||
|
@ -168,10 +168,6 @@ sk_sp<GrTextureProxy> SkImage_GpuYUVA::asTextureProxyRef(GrRecordingContext* con
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> SkImage_GpuYUVA::asMippedTextureProxyRef(GrRecordingContext* context) const {
|
||||
if (!context || !fContext->priv().matches(context)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// if invalid or already has miplevels
|
||||
auto proxy = this->asTextureProxyRef(context);
|
||||
if (!proxy || GrMipMapped::kYes == fRGBProxy->mipMapped()) {
|
||||
@ -189,6 +185,17 @@ sk_sp<GrTextureProxy> SkImage_GpuYUVA::asMippedTextureProxyRef(GrRecordingContex
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceProxyView SkImage_GpuYUVA::asSurfaceProxyViewRef(GrRecordingContext* context) const {
|
||||
auto proxy = this->asTextureProxyRef(context);
|
||||
if (!proxy) {
|
||||
return GrSurfaceProxyView();
|
||||
}
|
||||
|
||||
GrSurfaceOrigin origin = proxy->origin();
|
||||
const GrSwizzle& swizzle = proxy->textureSwizzle();
|
||||
return {std::move(proxy), origin, swizzle};
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorTypeAndColorSpace(GrRecordingContext*,
|
||||
|
@ -35,6 +35,8 @@ public:
|
||||
GrTextureProxy* peekProxy() const override;
|
||||
sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const override;
|
||||
|
||||
GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext* context) const override;
|
||||
|
||||
bool onIsTextureBacked() const override {
|
||||
SkASSERT(fProxies[0] || fRGBProxy);
|
||||
return true;
|
||||
|
@ -122,8 +122,9 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
|
||||
// The renderTargetContext coming out of SkGpuDevice should always be exact and the
|
||||
// above copy creates a kExact surfaceContext.
|
||||
SkASSERT(srcProxy->priv().isExact());
|
||||
GrSurfaceProxyView view(std::move(srcProxy), rtc->origin(), rtc->textureSwizzle());
|
||||
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, info.alphaType(),
|
||||
std::move(srcProxy), info.refColorSpace());
|
||||
std::move(view), info.refColorSpace());
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@ -255,9 +256,10 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
|
||||
// Possibly we could skip making an image here if SkGpuDevice exposed a lower level way
|
||||
// of drawing a texture proxy.
|
||||
const SkImageInfo info = fDevice->imageInfo();
|
||||
GrSurfaceProxyView view(std::move(srcProxy), rtc->origin(), rtc->textureSwizzle());
|
||||
sk_sp<SkImage> image;
|
||||
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, info.alphaType(),
|
||||
std::move(srcProxy), info.refColorSpace());
|
||||
std::move(view), info.refColorSpace());
|
||||
canvas->drawImage(image, x, y, paint);
|
||||
return true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user