Update GrSurface/RenderTargetContexts to take and store GrSurfaceProxyViews.

Bug: skia:9556
Change-Id: Ie1aed1b16c237e9c9d1b582ac4ff02fdaaad238f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263205
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Greg Daniel 2020-01-14 09:56:04 -05:00 committed by Skia Commit-Bot
parent 34386800a2
commit 3912a4b1da
25 changed files with 194 additions and 135 deletions

View File

@ -191,9 +191,11 @@ bool SkDeferredDisplayListRecorder::init() {
grColorType);
SkASSERT(readSwizzle == proxy->textureSwizzle());
auto rtc = std::make_unique<GrRenderTargetContext>(fContext.get(), std::move(proxy),
grColorType, fCharacterization.origin(),
readSwizzle, outputSwizzle,
GrSurfaceProxyView readView(proxy, fCharacterization.origin(), readSwizzle);
GrSurfaceProxyView outputView(std::move(proxy), fCharacterization.origin(), outputSwizzle);
auto rtc = std::make_unique<GrRenderTargetContext>(fContext.get(), std::move(readView),
std::move(outputView), grColorType,
fCharacterization.refColorSpace(),
&fCharacterization.surfaceProps());
fSurface = SkSurface_Gpu::MakeWrappedRenderTarget(fContext.get(), std::move(rtc));

View File

@ -451,7 +451,10 @@ public:
if (!rec) {
return false;
}
auto sContext = GrSurfaceContext::Make(fContext, fTextureProxy, fColorType,
// TODO: Store a GrSurfaceProxyView on SkSpecialImage_Gpu instead of just a GrTextureProxy
GrSurfaceProxyView view(fTextureProxy, fTextureProxy->origin(),
fTextureProxy->textureSwizzle());
auto sContext = GrSurfaceContext::Make(fContext, std::move(view), fColorType,
this->alphaType(), fColorSpace);
if (!sContext) {
return false;

View File

@ -153,9 +153,12 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(format, colorType);
GrSwizzle outSwizzle = context->priv().caps()->getOutputSwizzle(format, colorType);
return std::make_unique<GrRenderTargetContext>(context, std::move(proxy), colorType, origin,
readSwizzle, outSwizzle, std::move(colorSpace),
surfaceProps, managedOps);
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView outputView(std::move(proxy), origin, outSwizzle);
return std::make_unique<GrRenderTargetContext>(context, std::move(readView),
std::move(outputView), colorType,
std::move(colorSpace), surfaceProps, managedOps);
}
std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::Make(
@ -351,20 +354,21 @@ std::unique_ptr<GrRenderTargetContext> GrRenderTargetContext::MakeFromVulkanSeco
// stack. When this occurs with a closed GrOpsTask, a new one will be allocated
// when the renderTargetContext attempts to use it (via getOpsTask).
GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context,
sk_sp<GrSurfaceProxy> proxy,
GrSurfaceProxyView readView,
GrSurfaceProxyView outputView,
GrColorType colorType,
GrSurfaceOrigin origin,
GrSwizzle readSwizzle,
GrSwizzle outSwizzle,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps,
bool managedOpsTask)
: GrSurfaceContext(context, std::move(proxy), colorType, kPremul_SkAlphaType,
std::move(colorSpace), origin, readSwizzle)
, fOutputSwizzle(outSwizzle)
, fOpsTask(sk_ref_sp(fSurfaceProxy->getLastOpsTask()))
: GrSurfaceContext(context, std::move(readView), colorType, kPremul_SkAlphaType,
std::move(colorSpace))
, fOutputView(std::move(outputView))
, fOpsTask(sk_ref_sp(this->asSurfaceProxy()->getLastOpsTask()))
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fManagedOpsTask(managedOpsTask) {
SkASSERT(this->asSurfaceProxy() == fOutputView.proxy());
SkASSERT(this->origin() == fOutputView.origin());
fTextTarget.reset(new TextTarget(this));
SkDEBUGCODE(this->validate();)
}
@ -372,7 +376,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context,
#ifdef SK_DEBUG
void GrRenderTargetContext::onValidate() const {
if (fOpsTask && !fOpsTask->isClosed()) {
SkASSERT(fSurfaceProxy->getLastRenderTask() == fOpsTask.get());
SkASSERT(fOutputView.proxy()->getLastRenderTask() == fOpsTask.get());
}
}
#endif
@ -557,7 +561,7 @@ void GrRenderTargetContext::drawPaint(const GrClip& clip,
const SkMatrix& viewMatrix) {
// Start with the render target, since that is the maximum content we could possibly fill.
// drawFilledQuad() will automatically restrict it to clip bounds for us if possible.
SkRect r = fSurfaceProxy->getBoundsRect();
SkRect r = this->asSurfaceProxy()->getBoundsRect();
if (!paint.numTotalFragmentProcessors()) {
// The paint is trivial so we won't need to use local coordinates, so skip calculating the
// inverse view matrix.
@ -621,7 +625,7 @@ GrRenderTargetContext::QuadOptimization GrRenderTargetContext::attemptQuadOptimi
if (stencilSettings) {
// Must use size at which the rendertarget will ultimately be allocated so that stencil
// buffer updates on approximately sized render targets don't get corrupted.
rtRect = fSurfaceProxy->backingStoreBoundsRect();
rtRect = this->asSurfaceProxy()->backingStoreBoundsRect();
} else {
// Use the logical size of the render target, which allows for "fullscreen" clears even if
// the render target has an approximate backing fit
@ -1694,7 +1698,7 @@ void GrRenderTargetContext::asyncRescaleAndReadPixels(
}
bool needsRescale = srcRect.width() != info.width() || srcRect.height() != info.height();
auto colorTypeOfFinalContext = this->colorInfo().colorType();
auto backendFormatOfFinalContext = fSurfaceProxy->backendFormat();
auto backendFormatOfFinalContext = this->asSurfaceProxy()->backendFormat();
if (needsRescale) {
colorTypeOfFinalContext = dstCT;
backendFormatOfFinalContext = this->caps()->getDefaultBackendFormat(dstCT,
@ -1742,11 +1746,11 @@ void GrRenderTargetContext::asyncRescaleAndReadPixels(
callback(context, nullptr);
return;
}
sk_sp<GrTextureProxy> texProxy = sk_ref_sp(fSurfaceProxy->asTextureProxy());
sk_sp<GrTextureProxy> texProxy = this->asTextureProxyRef();
SkRect srcRectToDraw = SkRect::Make(srcRect);
// If the src is not texturable first try to make a copy to a texture.
if (!texProxy) {
texProxy = GrSurfaceProxy::Copy(fContext, fSurfaceProxy.get(),
texProxy = GrSurfaceProxy::Copy(fContext, this->asSurfaceProxy(),
GrMipMapped::kNo, srcRect, SkBackingFit::kApprox,
SkBudgeted::kNo);
if (!texProxy) {
@ -2132,7 +2136,7 @@ GrSemaphoresSubmitted GrRenderTargetContext::flush(SkSurface::BackendSurfaceAcce
SkDEBUGCODE(this->validate();)
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext);
return this->drawingManager()->flushSurface(fSurfaceProxy.get(), access, info);
return this->drawingManager()->flushSurface(this->asSurfaceProxy(), access, info);
}
bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores,
@ -2319,7 +2323,7 @@ SkBudgeted GrRenderTargetContextPriv::isBudgeted() const {
SkDEBUGCODE(fRenderTargetContext->validate();)
return fRenderTargetContext->fSurfaceProxy->isBudgeted();
return fRenderTargetContext->asSurfaceProxy()->isBudgeted();
}
void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip,
@ -2506,7 +2510,8 @@ bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op
return false;
}
if (this->caps()->textureBarrierSupport() && !fSurfaceProxy->requiresManualMSAAResolve()) {
if (this->caps()->textureBarrierSupport() &&
!this->asSurfaceProxy()->requiresManualMSAAResolve()) {
if (this->asTextureProxy()) {
// The render target is a texture, so we can read from it directly in the shader. The XP
// will be responsible to detect this situation and request a texture barrier.
@ -2516,7 +2521,7 @@ bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op
}
}
SkIRect copyRect = SkIRect::MakeSize(fSurfaceProxy->dimensions());
SkIRect copyRect = SkIRect::MakeSize(this->asSurfaceProxy()->dimensions());
SkIRect clippedRect;
clip.getConservativeBounds(
@ -2530,7 +2535,7 @@ bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op
// performance we may ignore the clip when the draw is entirely inside the clip is float
// space but will hit pixels just outside the clip when actually rasterizing.
clippedRect.outset(1, 1);
clippedRect.intersect(SkIRect::MakeSize(fSurfaceProxy->dimensions()));
clippedRect.intersect(SkIRect::MakeSize(this->asSurfaceProxy()->dimensions()));
}
SkIRect opIBounds;
opBounds.roundOut(&opIBounds);
@ -2560,7 +2565,7 @@ bool GrRenderTargetContext::setupDstProxyView(const GrClip& clip, const GrOp& op
fit = SkBackingFit::kApprox;
}
sk_sp<GrTextureProxy> newProxy =
GrSurfaceProxy::Copy(fContext, fSurfaceProxy.get(), GrMipMapped::kNo, copyRect,
GrSurfaceProxy::Copy(fContext, this->asSurfaceProxy(), GrMipMapped::kNo, copyRect,
fit, SkBudgeted::kYes, restrictions.fRectsMustMatch);
SkASSERT(newProxy);

View File

@ -106,9 +106,9 @@ public:
GrRecordingContext*, const SkImageInfo&, const GrVkDrawableInfo&,
const SkSurfaceProps*);
GrRenderTargetContext(GrRecordingContext*, sk_sp<GrSurfaceProxy>, GrColorType,
GrSurfaceOrigin, GrSwizzle readSwizzle, GrSwizzle outSwizzle,
sk_sp<SkColorSpace>, const SkSurfaceProps*, bool managedOpsTask = true);
GrRenderTargetContext(GrRecordingContext*, GrSurfaceProxyView readView,
GrSurfaceProxyView outputView, GrColorType, sk_sp<SkColorSpace>,
const SkSurfaceProps*, bool managedOpsTask = true);
~GrRenderTargetContext() override;
@ -543,13 +543,13 @@ public:
bool wrapsVkSecondaryCB() const { return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
GrMipMapped mipMapped() const;
GrSurfaceProxyView outputSurfaceView() {
return { fSurfaceProxy, fOrigin, fOutputSwizzle };
}
// TODO: See if it makes sense for this to return a const& instead and require the callers to
// make a copy (which refs the proxy) if needed.
GrSurfaceProxyView outputSurfaceView() { return fOutputView; }
// This entry point should only be called if the backing GPU object is known to be
// instantiated.
GrRenderTarget* accessRenderTarget() { return fSurfaceProxy->peekRenderTarget(); }
GrRenderTarget* accessRenderTarget() { return this->asSurfaceProxy()->peekRenderTarget(); }
GrRenderTargetContext* asRenderTargetContext() override { return this; }
@ -560,7 +560,7 @@ public:
GrTextTarget* textTarget() { return fTextTarget.get(); }
#if GR_TEST_UTILS
bool testingOnly_IsInstantiated() const { return fSurfaceProxy->isInstantiated(); }
bool testingOnly_IsInstantiated() const { return this->asSurfaceProxy()->isInstantiated(); }
void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
GrOpsTask* testingOnly_PeekLastOpsTask() { return fOpsTask.get(); }
#endif
@ -683,7 +683,7 @@ private:
std::unique_ptr<GrTextTarget> fTextTarget;
GrSwizzle fOutputSwizzle;
GrSurfaceProxyView fOutputView;
// In MDB-mode the GrOpsTask can be closed by some other renderTargetContext that has picked
// it up. For this reason, the GrOpsTask should only ever be accessed via 'getOpsTask'.

View File

@ -88,7 +88,7 @@ public:
* guaranteed to match the uniqueID of the underlying GrRenderTarget - beware!
*/
GrSurfaceProxy::UniqueID uniqueID() const {
return fRenderTargetContext->fSurfaceProxy->uniqueID();
return fRenderTargetContext->asSurfaceProxy()->uniqueID();
}
uint32_t testingOnly_getOpsTaskID();

View File

@ -28,7 +28,7 @@
#define RETURN_FALSE_IF_ABANDONED if (this->fContext->priv().abandoned()) { return false; }
std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
sk_sp<GrSurfaceProxy> proxy,
GrSurfaceProxyView readView,
GrColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace) {
@ -39,25 +39,23 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* con
if (context->priv().abandoned()) {
return nullptr;
}
GrSurfaceProxy* proxy = readView.proxy();
SkASSERT(proxy && proxy->asTextureProxy());
// TODO: These should be passed in directly or as GrSurfaceProxyView
GrSurfaceOrigin origin = proxy->origin();
GrSwizzle readSwizzle = proxy->textureSwizzle();
std::unique_ptr<GrSurfaceContext> surfaceContext;
if (GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy()) {
if (proxy->asRenderTargetProxy()) {
SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType);
// Will we ever want a swizzle that is not the default output swizzle for the format and
// colorType here? If so we will need to manually pass that in.
GrSwizzle outSwizzle = context->priv().caps()->getOutputSwizzle(proxy->backendFormat(),
colorType);
surfaceContext.reset(new GrRenderTargetContext(context, sk_ref_sp(rtProxy), colorType,
origin, readSwizzle, outSwizzle,
GrSurfaceProxyView outputView(readView.proxyRef(), readView.origin(), outSwizzle);
surfaceContext.reset(new GrRenderTargetContext(context, std::move(readView),
std::move(outputView), colorType,
std::move(colorSpace), nullptr));
} else {
surfaceContext.reset(new GrSurfaceContext(context, std::move(proxy), colorType, alphaType,
std::move(colorSpace), origin, readSwizzle));
surfaceContext.reset(new GrSurfaceContext(context, std::move(readView), colorType,
alphaType, std::move(colorSpace)));
}
return surfaceContext;
}
@ -92,7 +90,9 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(
return nullptr;
}
return GrSurfaceContext::Make(context, std::move(proxy), colorType, alphaType,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, colorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return GrSurfaceContext::Make(context, std::move(view), colorType, alphaType,
std::move(colorSpace));
}
@ -102,17 +102,13 @@ std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(
// stack. When this occurs with a closed GrOpsTask, a new one will be allocated
// when the renderTargetContext attempts to use it (via getOpsTask).
GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context,
sk_sp<GrSurfaceProxy> proxy,
GrSurfaceProxyView readView,
GrColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace,
GrSurfaceOrigin origin,
GrSwizzle readSwizzle)
sk_sp<SkColorSpace> colorSpace)
: fContext(context)
, fSurfaceProxy(std::move(proxy))
, fOrigin(origin)
, fColorInfo(colorType, alphaType, std::move(colorSpace))
, fReadSwizzle(readSwizzle) {
, fReadView(std::move(readView))
, fColorInfo(colorType, alphaType, std::move(colorSpace)) {
SkASSERT(!context->priv().abandoned());
}
@ -393,8 +389,9 @@ bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* s
return false;
}
SkASSERT(tempProxy->textureSwizzle() == tempReadSwizzle);
GrSurfaceContext tempCtx(direct, tempProxy, colorType, alphaType,
this->colorInfo().refColorSpace(), tempOrigin, tempReadSwizzle);
GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle);
GrSurfaceContext tempCtx(direct, std::move(tempView), colorType, alphaType,
this->colorInfo().refColorSpace());
// In the fast path we always write the srcData to the temp context as though it were RGBA.
// When the data is really BGRA the write will cause the R and B channels to be swapped in
@ -732,10 +729,10 @@ GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorTy
#ifdef SK_DEBUG
void GrSurfaceContext::validate() const {
SkASSERT(fSurfaceProxy);
fSurfaceProxy->validate(fContext);
SkASSERT(fReadView.proxy());
fReadView.proxy()->validate(fContext);
SkASSERT(fContext->priv().caps()->areColorTypeAndFormatCompatible(
this->colorInfo().colorType(), fSurfaceProxy->backendFormat()));
this->colorInfo().colorType(), fReadView.proxy()->backendFormat()));
this->onValidate();
}

View File

@ -38,7 +38,8 @@ class GrSurfaceContext {
public:
// If the passed in GrSurfaceProxy is renderable this will return a GrRenderTargetContext,
// otherwise it will return a GrSurfaceContext.
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, sk_sp<GrSurfaceProxy>,
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
GrSurfaceProxyView readView,
GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*, const SkISize& dimensions,
@ -50,20 +51,20 @@ public:
// If it is known that the GrSurfaceProxy is not renderable, you can directly call the the ctor
// here to make a GrSurfaceContext on the stack.
GrSurfaceContext(GrRecordingContext*, sk_sp<GrSurfaceProxy>, GrColorType, SkAlphaType,
sk_sp<SkColorSpace>, GrSurfaceOrigin, GrSwizzle readSwizzle);
GrSurfaceContext(GrRecordingContext*, GrSurfaceProxyView readView, GrColorType, SkAlphaType,
sk_sp<SkColorSpace>);
virtual ~GrSurfaceContext() = default;
const GrColorInfo& colorInfo() const { return fColorInfo; }
GrSurfaceOrigin origin() const { return fOrigin; }
const GrSwizzle& readSwizzle() const { return fReadSwizzle; }
GrSurfaceProxyView readSurfaceView() {
return { this->asSurfaceProxyRef(), fOrigin, fReadSwizzle };
}
GrSurfaceOrigin origin() const { return fReadView.origin(); }
GrSwizzle readSwizzle() const { return fReadView.swizzle(); }
// TODO: See if it makes sense for this to return a const& instead and require the callers to
// make a copy (which refs the proxy) if needed.
GrSurfaceProxyView readSurfaceView() { return fReadView; }
int width() const { return fSurfaceProxy->width(); }
int height() const { return fSurfaceProxy->height(); }
int width() const { return fReadView.proxy()->width(); }
int height() const { return fReadView.proxy()->height(); }
const GrCaps* caps() const;
@ -92,22 +93,20 @@ public:
bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
GrContext* direct = nullptr);
GrSurfaceProxy* asSurfaceProxy() { return fSurfaceProxy.get(); }
const GrSurfaceProxy* asSurfaceProxy() const { return fSurfaceProxy.get(); }
sk_sp<GrSurfaceProxy> asSurfaceProxyRef() { return fSurfaceProxy; }
GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
sk_sp<GrSurfaceProxy> asSurfaceProxyRef() { return fReadView.proxyRef(); }
GrTextureProxy* asTextureProxy() { return fSurfaceProxy->asTextureProxy(); }
const GrTextureProxy* asTextureProxy() const { return fSurfaceProxy->asTextureProxy(); }
sk_sp<GrTextureProxy> asTextureProxyRef() {
return sk_ref_sp(fSurfaceProxy->asTextureProxy());
}
GrTextureProxy* asTextureProxy() { return fReadView.asTextureProxy(); }
const GrTextureProxy* asTextureProxy() const { return fReadView.asTextureProxy(); }
sk_sp<GrTextureProxy> asTextureProxyRef() { return fReadView.asTextureProxyRef(); }
GrRenderTargetProxy* asRenderTargetProxy() { return fSurfaceProxy->asRenderTargetProxy(); }
GrRenderTargetProxy* asRenderTargetProxy() { return fReadView.asRenderTargetProxy(); }
const GrRenderTargetProxy* asRenderTargetProxy() const {
return fSurfaceProxy->asRenderTargetProxy();
return fReadView.asRenderTargetProxy();
}
sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() {
return sk_ref_sp(fSurfaceProxy->asRenderTargetProxy());
return fReadView.asRenderTargetProxyRef();
}
virtual GrRenderTargetContext* asRenderTargetContext() { return nullptr; }
@ -140,8 +139,7 @@ protected:
GrRecordingContext* fContext;
sk_sp<GrSurfaceProxy> fSurfaceProxy;
GrSurfaceOrigin fOrigin;
GrSurfaceProxyView fReadView;
// The rescaling step of asyncRescaleAndReadPixels[YUV420]().
std::unique_ptr<GrRenderTargetContext> rescale(const SkImageInfo& info, const SkIRect& srcRect,
@ -189,7 +187,6 @@ private:
}
GrColorInfo fColorInfo;
GrSwizzle fReadSwizzle;
typedef SkRefCnt INHERITED;
};

View File

@ -10,6 +10,7 @@
#include "include/core/SkRefCnt.h"
#include "include/gpu/GrTypes.h"
#include "src/gpu/GrRenderTargetProxy.h"
#include "src/gpu/GrSurfaceProxy.h"
#include "src/gpu/GrSwizzle.h"
@ -37,6 +38,8 @@ public:
bool operator!=(const GrSurfaceProxyView& other) const { return !(*this == other); }
GrSurfaceProxy* proxy() const { return fProxy.get(); }
sk_sp<GrSurfaceProxy> proxyRef() const { return fProxy; }
GrTextureProxy* asTextureProxy() const {
if (!fProxy) {
return nullptr;
@ -44,10 +47,7 @@ public:
return fProxy->asTextureProxy();
}
sk_sp<GrTextureProxy> asTextureProxyRef() const {
if (!fProxy) {
return nullptr;
}
return sk_ref_sp<GrTextureProxy>(fProxy->asTextureProxy());
return sk_ref_sp<GrTextureProxy>(this->asTextureProxy());
}
GrRenderTargetProxy* asRenderTargetProxy() const {
@ -57,8 +57,12 @@ public:
return fProxy->asRenderTargetProxy();
}
sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() const {
return sk_ref_sp<GrRenderTargetProxy>(this->asRenderTargetProxy());
}
GrSurfaceOrigin origin() const { return fOrigin; }
const GrSwizzle& swizzle() const { return fSwizzle; }
GrSwizzle swizzle() const { return fSwizzle; }
void reset() {
*this = {};

View File

@ -83,20 +83,21 @@ void GrAtlasManager::addGlyphToBulkAndSetUseToken(GrDrawOpAtlas::BulkUseTokenUpd
* Write the contents of the surface proxy to a PNG. Returns true if successful.
* @param filename Full path to desired file
*/
static bool save_pixels(GrContext* context, GrSurfaceProxy* sProxy, GrColorType colorType,
static bool save_pixels(GrContext* context, GrSurfaceProxyView view, GrColorType colorType,
const char* filename) {
if (!sProxy) {
if (!view.proxy()) {
return false;
}
SkImageInfo ii =
SkImageInfo::Make(sProxy->dimensions(), kRGBA_8888_SkColorType, kPremul_SkAlphaType);
SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
SkBitmap bm;
if (!bm.tryAllocPixels(ii)) {
return false;
}
auto sContext = GrSurfaceContext::Make(context, sk_ref_sp(sProxy), colorType,
auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
kUnknown_SkAlphaType, nullptr);
if (!sContext || !sContext->asTextureProxy()) {
return false;
@ -141,7 +142,7 @@ void GrAtlasManager::dump(GrContext* context) const {
filename.printf("fontcache_%d%d%d.png", gDumpCount, i, pageIdx);
#endif
auto ct = mask_format_to_gr_color_type(AtlasIndexToMaskFormat(i));
save_pixels(context, views[pageIdx].proxy(), ct, filename.c_str());
save_pixels(context, views[pageIdx], ct, filename.c_str());
}
}
}

View File

@ -621,9 +621,9 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
SkAlphaType at = pixmap.alphaType();
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(proxy, surfaceOrigin, swizzle);
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, at,
std::move(view), cs);
view, cs);
if (!image) {
return nullptr;
}
@ -633,9 +633,9 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
return nullptr;
}
GrSurfaceContext surfaceContext(context, std::move(proxy),
GrSurfaceContext surfaceContext(context, std::move(view),
SkColorTypeToGrColorType(pixmap.colorType()),
pixmap.alphaType(), cs, surfaceOrigin, swizzle);
pixmap.alphaType(), cs);
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
std::move(cs));

View File

@ -114,12 +114,12 @@ bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
}
}
sk_sp<GrTextureProxy> texProxy = this->asTextureProxyRef(direct);
GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
this->colorType(),
texProxy->backendFormat());
view.proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, std::move(texProxy), grColorType,
auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType,
this->alphaType(), this->refColorSpace());
if (!sContext) {
return false;
@ -175,12 +175,12 @@ bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels,
return false;
}
sk_sp<GrTextureProxy> texProxy = this->asTextureProxyRef(direct);
GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
this->colorType(),
texProxy->backendFormat());
view.proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, std::move(texProxy), grColorType,
auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType,
this->alphaType(), this->refColorSpace());
if (!sContext) {
return false;

View File

@ -98,14 +98,16 @@ sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
false,
GrSurfaceProxy::UseAllocator::kYes);
const GrSwizzle& readSwizzle = caps->getReadSwizzle(backendFormat, grColorType);
const GrSwizzle& outputSwizzle = caps->getOutputSwizzle(backendFormat, grColorType);
GrSwizzle readSwizzle = caps->getReadSwizzle(backendFormat, grColorType);
GrSwizzle outputSwizzle = caps->getOutputSwizzle(backendFormat, grColorType);
SkASSERT(readSwizzle == proxy->textureSwizzle());
auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(proxy),
grColorType, origin,
readSwizzle, outputSwizzle,
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView outputView(std::move(proxy), origin, outputSwizzle);
auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(readView),
std::move(outputView), grColorType,
colorSpace, surfaceProps);
sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(context, std::move(rtc));
@ -186,9 +188,11 @@ sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
SkASSERT(readSwizzle == proxy->textureSwizzle());
auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(proxy),
grColorType, origin,
readSwizzle, outputSwizzle,
GrSurfaceProxyView readView(proxy, origin, readSwizzle);
GrSurfaceProxyView outputView(std::move(proxy), origin, outputSwizzle);
auto rtc = std::make_unique<GrRenderTargetContext>(context, std::move(readView),
std::move(outputView), grColorType,
colorSpace, surfaceProps);
sk_sp<SkSurface> surface = SkSurface_Gpu::MakeWrappedRenderTarget(context, std::move(rtc));

View File

@ -105,7 +105,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
}
GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
auto dstContext = GrSurfaceContext::Make(context, std::move(dst),
GrSwizzle dstSwizzle = context->priv().caps()->getReadSwizzle(
dst->backendFormat(), grColorType);
GrSurfaceProxyView dstView(std::move(dst), dOrigin, dstSwizzle);
auto dstContext = GrSurfaceContext::Make(context,
std::move(dstView),
grColorType,
ii.alphaType(), nullptr);

View File

@ -56,7 +56,10 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context, T min, T max, T
continue;
}
auto sContext = GrSurfaceContext::Make(context, std::move(fpProxy), colorType,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(fpProxy->backendFormat(),
colorType);
GrSurfaceProxyView view(std::move(fpProxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, sContext);

View File

@ -301,7 +301,11 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
{kSize, kSize}, combo.fColorType, combo.fFormat, renderable, 1,
kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes, GrProtected::kNo);
if (proxy) {
auto texCtx = GrSurfaceContext::Make(context, std::move(proxy),
GrSwizzle swizzle = caps->getReadSwizzle(combo.fFormat,
combo.fColorType);
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
swizzle);
auto texCtx = GrSurfaceContext::Make(context, std::move(view),
combo.fColorType,
kPremul_SkAlphaType, nullptr);
@ -399,7 +403,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
kTopLeft_GrSurfaceOrigin,
kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType);
auto surfContext = GrSurfaceContext::Make(context, proxy, GrColorType::kRGBA_8888,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
auto surfContext = GrSurfaceContext::Make(context, std::move(view), GrColorType::kRGBA_8888,
kPremul_SkAlphaType, nullptr);
// Read pixels should work with a read-only texture.

View File

@ -72,7 +72,9 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context,
}
REPORTER_ASSERT(reporter, wrappedProxy);
auto surfaceContext = GrSurfaceContext::Make(context, std::move(wrappedProxy), grCT,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(), grCT);
GrSurfaceProxyView view(std::move(wrappedProxy), kTopLeft_GrSurfaceOrigin, swizzle);
auto surfaceContext = GrSurfaceContext::Make(context, std::move(view), grCT,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, surfaceContext);

View File

@ -35,8 +35,10 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct),
kPremul_SkAlphaType, nullptr);
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), grCT, kPremul_SkAlphaType,
nullptr);
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);
@ -62,8 +64,10 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo
{grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0);
REPORTER_ASSERT(reporter, proxy);
if (proxy) {
auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct),
kPremul_SkAlphaType, nullptr);
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), grCT);
GrSurfaceProxyView view(proxy, kBottomLeft_GrSurfaceOrigin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), grCT, kPremul_SkAlphaType,
nullptr);
SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType);

View File

@ -123,8 +123,9 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context, int array
GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
grColorType);
GrSurfaceContext sContext(context, std::move(proxy), grColorType, kPremul_SkAlphaType,
nullptr, origin, readSwizzle);
GrSurfaceProxyView view(std::move(proxy), origin, readSwizzle);
GrSurfaceContext sContext(context, std::move(view), grColorType, kPremul_SkAlphaType,
nullptr);
if (!sContext.readPixels(dstInfo, readBuffer.begin(), 0, {0, 0})) {
// We only require this to succeed if the format is renderable.

View File

@ -342,9 +342,14 @@ bool log_pixels(GrColor* pixels, int widthHeight, SkString* dst) {
}
bool log_texture_proxy(GrContext* context, sk_sp<GrTextureProxy> src, SkString* dst) {
auto sContext = GrSurfaceContext::Make(context, src, GrColorType::kRGBA_8888, kLogAlphaType,
nullptr);
SkImageInfo ii = SkImageInfo::Make(src->dimensions(), kRGBA_8888_SkColorType, kLogAlphaType);
GrSurfaceOrigin origin = src->origin();
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(src->backendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(std::move(src), origin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), GrColorType::kRGBA_8888,
kLogAlphaType, nullptr);
SkBitmap bm;
SkAssertResult(bm.tryAllocPixels(ii));
SkAssertResult(sContext->readPixels(ii, bm.getPixels(), bm.rowBytes(), {0, 0}));

View File

@ -426,8 +426,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
sk_sp<GrTextureProxy> proxy = sk_gpu_test::MakeTextureProxyFromData(
context, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes());
auto sContext = GrSurfaceContext::Make(context, std::move(proxy),
SkColorTypeToGrColorType(bmp.colorType()), kPremul_SkAlphaType, nullptr);
GrColorType grColorType = SkColorTypeToGrColorType(bmp.colorType());
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
grColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view),
grColorType, kPremul_SkAlphaType, nullptr);
auto info = SkImageInfo::Make(DEV_W, DEV_H, kN32_SkColorType, kPremul_SkAlphaType);
test_readpixels_texture(reporter, std::move(sContext), info);
}

View File

@ -74,7 +74,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
ERRORF(reporter, "Could not create alpha texture.");
return;
}
auto sContext = GrSurfaceContext::Make(context, std::move(proxy), GrColorType::kAlpha_8,
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kAlpha_8);
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), GrColorType::kAlpha_8,
kPremul_SkAlphaType, nullptr);
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));
@ -193,7 +198,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
continue;
}
auto sContext = GrSurfaceContext::Make(context, std::move(proxy), info.fColorType,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
info.fColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), info.fColorType,
kPremul_SkAlphaType, nullptr);
for (auto rowBytes : kRowBytes) {

View File

@ -192,7 +192,10 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
TestCopyFromSurface(reporter, context, rectProxy.get(), GrColorType::kRGBA_8888, refPixels,
"RectangleTexture-copy-from");
auto rectContext = GrSurfaceContext::Make(context, std::move(rectProxy),
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(rectangleTex.getBackendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(std::move(rectProxy), origin, swizzle);
auto rectContext = GrSurfaceContext::Make(context, std::move(view),
GrColorType::kRGBA_8888, kPremul_SkAlphaType,
nullptr);
SkASSERT(rectContext);

View File

@ -782,8 +782,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
auto makeImageSurfaceContext = [context](SkSurface* surface) {
sk_sp<SkImage> i(surface->makeImageSnapshot());
SkImage_Gpu* gpuImage = (SkImage_Gpu*)as_IB(i);
sk_sp<GrTextureProxy> proxy = gpuImage->asTextureProxyRef(context);
return GrSurfaceContext::Make(context, std::move(proxy),
return GrSurfaceContext::Make(context, gpuImage->asSurfaceProxyViewRef(context),
SkColorTypeToGrColorType(i->colorType()), kPremul_SkAlphaType,
gpuImage->refColorSpace());
};

View File

@ -84,7 +84,11 @@ void TestCopyFromSurface(skiatest::Reporter* reporter,
SkBackingFit::kExact, SkBudgeted::kYes);
SkASSERT(dstProxy);
auto dstContext = GrSurfaceContext::Make(context, std::move(dstProxy), colorType,
GrSurfaceOrigin origin = dstProxy->origin();
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(dstProxy->backendFormat(),
colorType);
GrSurfaceProxyView view(std::move(dstProxy), origin, swizzle);
auto dstContext = GrSurfaceContext::Make(context, std::move(view), colorType,
kPremul_SkAlphaType, nullptr);
SkASSERT(dstContext);

View File

@ -46,7 +46,9 @@ sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
if (!proxy) {
return nullptr;
}
auto sContext = GrSurfaceContext::Make(context, proxy, imageInfo.colorType(),
GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
GrSurfaceProxyView view(proxy, origin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), imageInfo.colorType(),
imageInfo.alphaType(), imageInfo.refColorSpace());
if (!sContext) {
return nullptr;