Pass description of GrSurface to GrSurfaceProxy lazy callbacks.
Also make GrDynamicAtlas directly use the GrSurface callback type rather than go through a springboard. Change-Id: I3e3c155bbc1e2e794e0d6828b0ea3c64c6a7f3e9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/283226 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
78be37f5cd
commit
63410e921c
@ -153,7 +153,8 @@ bool SkDeferredDisplayListRecorder::init() {
|
||||
GrSwizzle readSwizzle = caps->getReadSwizzle(fCharacterization.backendFormat(), grColorType);
|
||||
|
||||
sk_sp<GrRenderTargetProxy> proxy = proxyProvider->createLazyRenderTargetProxy(
|
||||
[lazyProxyData](GrResourceProvider* resourceProvider) {
|
||||
[lazyProxyData](GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc&) {
|
||||
// The proxy backing the destination surface had better have been instantiated
|
||||
// prior to the proxy backing the DLL's surface. Steal its GrRenderTarget.
|
||||
SkASSERT(lazyProxyData->fReplayDest->peekSurface());
|
||||
|
@ -117,8 +117,6 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext*
|
||||
AHardwareBuffer* hardwareBuffer = fHardwareBuffer;
|
||||
AHardwareBuffer_acquire(hardwareBuffer);
|
||||
|
||||
const bool isProtectedContent = fIsProtectedContent;
|
||||
|
||||
class AutoAHBRelease {
|
||||
public:
|
||||
AutoAHBRelease(AHardwareBuffer* ahb) : fAhb(ahb) {}
|
||||
@ -140,21 +138,25 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext*
|
||||
};
|
||||
|
||||
sk_sp<GrTextureProxy> texProxy = proxyProvider->createLazyProxy(
|
||||
[direct, buffer = AutoAHBRelease(hardwareBuffer), width, height, isProtectedContent,
|
||||
backendFormat](
|
||||
GrResourceProvider* resourceProvider) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
[direct, buffer = AutoAHBRelease(hardwareBuffer)](
|
||||
GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc)
|
||||
-> GrSurfaceProxy::LazyCallbackResult {
|
||||
GrAHardwareBufferUtils::DeleteImageProc deleteImageProc = nullptr;
|
||||
GrAHardwareBufferUtils::UpdateImageProc updateImageProc = nullptr;
|
||||
GrAHardwareBufferUtils::TexImageCtx texImageCtx = nullptr;
|
||||
|
||||
bool isProtected = desc.fProtected == GrProtected::kYes;
|
||||
GrBackendTexture backendTex =
|
||||
GrAHardwareBufferUtils::MakeBackendTexture(direct, buffer.get(),
|
||||
width, height,
|
||||
GrAHardwareBufferUtils::MakeBackendTexture(direct,
|
||||
buffer.get(),
|
||||
desc.fDimensions.width(),
|
||||
desc.fDimensions.height(),
|
||||
&deleteImageProc,
|
||||
&updateImageProc,
|
||||
&texImageCtx,
|
||||
isProtectedContent,
|
||||
backendFormat,
|
||||
isProtected,
|
||||
desc.fFormat,
|
||||
false);
|
||||
if (!backendTex.isValid()) {
|
||||
return {};
|
||||
@ -179,7 +181,7 @@ GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext*
|
||||
},
|
||||
backendFormat, {width, height}, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
||||
GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact,
|
||||
SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
|
||||
SkBudgeted::kNo, GrProtected(fIsProtectedContent), GrSurfaceProxy::UseAllocator::kYes);
|
||||
|
||||
GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType);
|
||||
|
||||
|
@ -161,7 +161,8 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
|
||||
// be deleted before we actually execute the lambda.
|
||||
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
|
||||
[refHelper = fRefHelper, releaseProcHelper, backendTexture = fBackendTexture](
|
||||
GrResourceProvider* resourceProvider) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc&) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
if (refHelper->fSemaphore) {
|
||||
resourceProvider->priv().gpu()->waitSemaphore(refHelper->fSemaphore.get());
|
||||
}
|
||||
|
@ -46,8 +46,10 @@ private:
|
||||
};
|
||||
|
||||
sk_sp<GrTextureProxy> GrDynamicAtlas::MakeLazyAtlasProxy(
|
||||
const LazyInstantiateAtlasCallback& callback, GrColorType colorType,
|
||||
InternalMultisample internalMultisample, const GrCaps& caps,
|
||||
LazyInstantiateAtlasCallback&& callback,
|
||||
GrColorType colorType,
|
||||
InternalMultisample internalMultisample,
|
||||
const GrCaps& caps,
|
||||
GrSurfaceProxy::UseAllocator useAllocator) {
|
||||
GrBackendFormat format = caps.getDefaultBackendFormat(colorType, GrRenderable::kYes);
|
||||
|
||||
@ -56,12 +58,8 @@ sk_sp<GrTextureProxy> GrDynamicAtlas::MakeLazyAtlasProxy(
|
||||
sampleCount = caps.internalMultisampleCount(format);
|
||||
}
|
||||
|
||||
auto instantiate = [cb = std::move(callback), format, sampleCount](GrResourceProvider* rp) {
|
||||
return cb(rp, format, sampleCount);
|
||||
};
|
||||
|
||||
sk_sp<GrTextureProxy> proxy =
|
||||
GrProxyProvider::MakeFullyLazyProxy(std::move(instantiate), format, GrRenderable::kYes,
|
||||
GrProxyProvider::MakeFullyLazyProxy(std::move(callback), format, GrRenderable::kYes,
|
||||
sampleCount, GrProtected::kNo, caps, useAllocator);
|
||||
|
||||
return proxy;
|
||||
@ -85,12 +83,11 @@ void GrDynamicAtlas::reset(SkISize initialSize, const GrCaps& caps) {
|
||||
fTopNode = nullptr;
|
||||
fDrawBounds.setEmpty();
|
||||
fTextureProxy = MakeLazyAtlasProxy(
|
||||
[this](GrResourceProvider* resourceProvider, const GrBackendFormat& format,
|
||||
int sampleCount) {
|
||||
[this](GrResourceProvider* resourceProvider, const LazyAtlasDesc& desc) {
|
||||
if (!fBackingTexture) {
|
||||
fBackingTexture = resourceProvider->createTexture(
|
||||
{fWidth, fHeight}, format, GrRenderable::kYes, sampleCount,
|
||||
GrMipMapped::kNo, SkBudgeted::kYes, GrProtected::kNo);
|
||||
{fWidth, fHeight}, desc.fFormat, desc.fRenderable, desc.fSampleCnt,
|
||||
desc.fMipMapped, desc.fBudgeted, desc.fProtected);
|
||||
}
|
||||
return GrSurfaceProxy::LazyCallbackResult(fBackingTexture);
|
||||
},
|
||||
|
@ -27,23 +27,25 @@ public:
|
||||
static constexpr GrSurfaceOrigin kTextureOrigin = kTopLeft_GrSurfaceOrigin;
|
||||
static constexpr int kPadding = 1; // Amount of padding below and to the right of each path.
|
||||
|
||||
using LazyInstantiateAtlasCallback = std::function<GrSurfaceProxy::LazyCallbackResult(
|
||||
GrResourceProvider*, const GrBackendFormat&, int sampleCount)>;
|
||||
using LazyAtlasDesc = GrSurfaceProxy::LazySurfaceDesc;
|
||||
using LazyInstantiateAtlasCallback = GrSurfaceProxy::LazyInstantiateCallback;
|
||||
|
||||
enum class InternalMultisample : bool {
|
||||
kNo = false,
|
||||
kYes = true
|
||||
};
|
||||
|
||||
static sk_sp<GrTextureProxy> MakeLazyAtlasProxy(const LazyInstantiateAtlasCallback&,
|
||||
GrColorType colorType, InternalMultisample,
|
||||
const GrCaps&, GrSurfaceProxy::UseAllocator);
|
||||
static sk_sp<GrTextureProxy> MakeLazyAtlasProxy(LazyInstantiateAtlasCallback&&,
|
||||
GrColorType colorType,
|
||||
InternalMultisample,
|
||||
const GrCaps&,
|
||||
GrSurfaceProxy::UseAllocator);
|
||||
|
||||
GrDynamicAtlas(GrColorType colorType, InternalMultisample, SkISize initialSize,
|
||||
int maxAtlasSize, const GrCaps&);
|
||||
virtual ~GrDynamicAtlas();
|
||||
|
||||
void reset(SkISize initialSize, const GrCaps& caps);
|
||||
void reset(SkISize initialSize, const GrCaps& desc);
|
||||
|
||||
GrTextureProxy* textureProxy() const { return fTextureProxy.get(); }
|
||||
bool isInstantiated() const { return fTextureProxy->isInstantiated(); }
|
||||
|
@ -317,12 +317,13 @@ sk_sp<GrTextureProxy> GrProxyProvider::createNonMippedProxyFromBitmap(const SkBi
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
|
||||
[dims, format, bitmap, fit, colorType, budgeted](GrResourceProvider* resourceProvider) {
|
||||
[bitmap](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) {
|
||||
SkASSERT(desc.fMipMapped == GrMipMapped::kNo);
|
||||
GrMipLevel mipLevel = { bitmap.getPixels(), bitmap.rowBytes() };
|
||||
|
||||
auto colorType = SkColorTypeToGrColorType(bitmap.colorType());
|
||||
return LazyCallbackResult(resourceProvider->createTexture(
|
||||
dims, format, colorType, GrRenderable::kNo, 1, budgeted, fit,
|
||||
GrProtected::kNo, mipLevel));
|
||||
desc.fDimensions, desc.fFormat, colorType, desc.fRenderable,
|
||||
desc.fSampleCnt, desc.fBudgeted, desc.fFit, desc.fProtected, mipLevel));
|
||||
},
|
||||
format, dims, GrRenderable::kNo, 1, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated,
|
||||
GrInternalSurfaceFlags::kNone, fit, budgeted, GrProtected::kNo, UseAllocator::kYes);
|
||||
@ -352,14 +353,14 @@ sk_sp<GrTextureProxy> GrProxyProvider::createMippedProxyFromBitmap(const SkBitma
|
||||
auto dims = bitmap.dimensions();
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
|
||||
[dims, format, bitmap, mipmaps, budgeted](GrResourceProvider* resourceProvider) {
|
||||
[bitmap, mipmaps](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) {
|
||||
const int mipLevelCount = mipmaps->countLevels() + 1;
|
||||
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
|
||||
auto colorType = SkColorTypeToGrColorType(bitmap.colorType());
|
||||
|
||||
texels[0].fPixels = bitmap.getPixels();
|
||||
texels[0].fRowBytes = bitmap.rowBytes();
|
||||
|
||||
auto colorType = SkColorTypeToGrColorType(bitmap.colorType());
|
||||
for (int i = 1; i < mipLevelCount; ++i) {
|
||||
SkMipMap::Level generatedMipLevel;
|
||||
mipmaps->getLevel(i - 1, &generatedMipLevel);
|
||||
@ -369,8 +370,8 @@ sk_sp<GrTextureProxy> GrProxyProvider::createMippedProxyFromBitmap(const SkBitma
|
||||
SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType());
|
||||
}
|
||||
return LazyCallbackResult(resourceProvider->createTexture(
|
||||
dims, format, colorType, GrRenderable::kNo, 1, budgeted, GrProtected::kNo,
|
||||
texels.get(), mipLevelCount));
|
||||
desc.fDimensions, desc.fFormat, colorType, GrRenderable::kNo, 1,
|
||||
desc.fBudgeted, GrProtected::kNo, texels.get(), mipLevelCount));
|
||||
},
|
||||
format, dims, GrRenderable::kNo, 1, GrMipMapped::kYes, GrMipMapsStatus::kValid,
|
||||
GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, budgeted, GrProtected::kNo,
|
||||
@ -457,10 +458,10 @@ sk_sp<GrTextureProxy> GrProxyProvider::createCompressedTextureProxy(
|
||||
: GrMipMapsStatus::kNotAllocated;
|
||||
|
||||
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
|
||||
[dimensions, format, budgeted, mipMapped, isProtected,
|
||||
data](GrResourceProvider* resourceProvider) {
|
||||
[data](GrResourceProvider* resourceProvider, const LazySurfaceDesc& desc) {
|
||||
return LazyCallbackResult(resourceProvider->createCompressedTexture(
|
||||
dimensions, format, budgeted, mipMapped, isProtected, data.get()));
|
||||
desc.fDimensions, desc.fFormat, desc.fBudgeted, desc.fMipMapped,
|
||||
desc.fProtected, data.get()));
|
||||
},
|
||||
format, dimensions, GrRenderable::kNo, 1, mipMapped, mipMapsStatus,
|
||||
GrInternalSurfaceFlags::kReadOnly, SkBackingFit::kExact, SkBudgeted::kYes,
|
||||
|
@ -148,6 +148,7 @@ public:
|
||||
const GrVkDrawableInfo&);
|
||||
|
||||
using LazyInstantiationKeyMode = GrSurfaceProxy::LazyInstantiationKeyMode;
|
||||
using LazySurfaceDesc = GrSurfaceProxy::LazySurfaceDesc;
|
||||
using LazyCallbackResult = GrSurfaceProxy::LazyCallbackResult;
|
||||
using LazyInstantiateCallback = GrSurfaceProxy::LazyInstantiateCallback;
|
||||
|
||||
|
@ -127,6 +127,22 @@ bool GrRenderTargetProxy::refsWrappedObjects() const {
|
||||
return surface->resourcePriv().refsWrappedObjects();
|
||||
}
|
||||
|
||||
GrSurfaceProxy::LazySurfaceDesc GrRenderTargetProxy::callbackDesc() const {
|
||||
// We only expect exactly sized lazy RT proxies.
|
||||
SkASSERT(!this->isFullyLazy());
|
||||
SkASSERT(this->isFunctionallyExact());
|
||||
return {
|
||||
this->dimensions(),
|
||||
SkBackingFit::kExact,
|
||||
GrRenderable::kYes,
|
||||
GrMipMapped::kNo,
|
||||
this->numSamples(),
|
||||
this->backendFormat(),
|
||||
this->isProtected(),
|
||||
this->isBudgeted(),
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
|
||||
// We do not check that surface->asTexture returns null since, when replaying DDLs we
|
||||
|
@ -143,6 +143,8 @@ private:
|
||||
size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
|
||||
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
||||
|
||||
LazySurfaceDesc callbackDesc() const override;
|
||||
|
||||
// WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
|
||||
// when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
|
||||
// each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
|
||||
|
@ -391,7 +391,7 @@ bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvide
|
||||
bool syncKey = true;
|
||||
bool releaseCallback = false;
|
||||
if (!surface) {
|
||||
auto result = fProxy->fLazyInstantiateCallback(resourceProvider);
|
||||
auto result = fProxy->fLazyInstantiateCallback(resourceProvider, fProxy->callbackDesc());
|
||||
surface = std::move(result.fSurface);
|
||||
syncKey = result.fKeyMode == GrSurfaceProxy::LazyInstantiationKeyMode::kSynced;
|
||||
releaseCallback = surface && result.fReleaseCallback;
|
||||
|
@ -62,6 +62,21 @@ public:
|
||||
kSynced
|
||||
};
|
||||
|
||||
/**
|
||||
* Specifies the expected properties of the GrSurface returned by a lazy instantiation
|
||||
* callback. The dimensions will be negative in the case of a fully lazy proxy.
|
||||
*/
|
||||
struct LazySurfaceDesc {
|
||||
SkISize fDimensions;
|
||||
SkBackingFit fFit;
|
||||
GrRenderable fRenderable;
|
||||
GrMipMapped fMipMapped;
|
||||
int fSampleCnt;
|
||||
const GrBackendFormat& fFormat;
|
||||
GrProtected fProtected;
|
||||
SkBudgeted fBudgeted;
|
||||
};
|
||||
|
||||
struct LazyCallbackResult {
|
||||
LazyCallbackResult() = default;
|
||||
LazyCallbackResult(const LazyCallbackResult&) = default;
|
||||
@ -85,7 +100,8 @@ public:
|
||||
bool fReleaseCallback = true;
|
||||
};
|
||||
|
||||
using LazyInstantiateCallback = std::function<LazyCallbackResult(GrResourceProvider*)>;
|
||||
using LazyInstantiateCallback =
|
||||
std::function<LazyCallbackResult(GrResourceProvider*, const LazySurfaceDesc&)>;
|
||||
|
||||
enum class UseAllocator {
|
||||
/**
|
||||
@ -410,6 +426,8 @@ private:
|
||||
|
||||
virtual size_t onUninstantiatedGpuMemorySize(const GrCaps&) const = 0;
|
||||
|
||||
virtual LazySurfaceDesc callbackDesc() const = 0;
|
||||
|
||||
bool fIgnoredByResourceAllocator = false;
|
||||
GrProtected fIsProtected;
|
||||
|
||||
|
@ -171,6 +171,28 @@ void GrTextureProxy::clearUniqueKey() {
|
||||
fProxyProvider = nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceProxy::LazySurfaceDesc GrTextureProxy::callbackDesc() const {
|
||||
SkISize dims;
|
||||
SkBackingFit fit;
|
||||
if (this->isFullyLazy()) {
|
||||
fit = SkBackingFit::kApprox;
|
||||
dims = {-1, -1};
|
||||
} else {
|
||||
fit = this->isFunctionallyExact() ? SkBackingFit::kExact : SkBackingFit::kApprox;
|
||||
dims = this->dimensions();
|
||||
}
|
||||
return {
|
||||
dims,
|
||||
fit,
|
||||
GrRenderable::kNo,
|
||||
fMipMapped,
|
||||
1,
|
||||
this->backendFormat(),
|
||||
this->isProtected(),
|
||||
this->isBudgeted(),
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void GrTextureProxy::onValidateSurface(const GrSurface* surface) {
|
||||
SkASSERT(!surface->asRenderTarget());
|
||||
|
@ -176,6 +176,8 @@ private:
|
||||
GrUniqueKey fUniqueKey;
|
||||
GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
|
||||
|
||||
LazySurfaceDesc callbackDesc() const override;
|
||||
|
||||
// Only used for proxies whose contents are being prepared on a worker thread. This object
|
||||
// stores the texture data, allowing the proxy to remain uninstantiated until flush. At that
|
||||
// point, the proxy is instantiated, and this data is used to perform an ASAP upload.
|
||||
|
@ -143,6 +143,28 @@ sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface(
|
||||
return surface;
|
||||
}
|
||||
|
||||
GrSurfaceProxy::LazySurfaceDesc GrTextureRenderTargetProxy::callbackDesc() const {
|
||||
SkISize dims;
|
||||
SkBackingFit fit;
|
||||
if (this->isFullyLazy()) {
|
||||
fit = SkBackingFit::kApprox;
|
||||
dims = {-1, -1};
|
||||
} else {
|
||||
fit = this->isFunctionallyExact() ? SkBackingFit::kExact : SkBackingFit::kApprox;
|
||||
dims = this->dimensions();
|
||||
}
|
||||
return {
|
||||
dims,
|
||||
fit,
|
||||
GrRenderable::kYes,
|
||||
this->mipMapped(),
|
||||
this->numSamples(),
|
||||
this->backendFormat(),
|
||||
this->isProtected(),
|
||||
this->isBudgeted(),
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void GrTextureRenderTargetProxy::onValidateSurface(const GrSurface* surface) {
|
||||
// Anything checked here should also be checking the GrTextureProxy version
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
|
||||
|
||||
size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
|
||||
|
||||
LazySurfaceDesc callbackDesc() const override;
|
||||
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
||||
};
|
||||
|
||||
|
@ -68,13 +68,15 @@ public:
|
||||
: GrCCPathProcessor::CoverageMode::kLiteral;
|
||||
}
|
||||
|
||||
|
||||
static sk_sp<GrTextureProxy> MakeLazyAtlasProxy(const LazyInstantiateAtlasCallback& callback,
|
||||
CoverageType coverageType, const GrCaps& caps,
|
||||
static sk_sp<GrTextureProxy> MakeLazyAtlasProxy(LazyInstantiateAtlasCallback&& callback,
|
||||
CoverageType coverageType,
|
||||
const GrCaps& caps,
|
||||
GrSurfaceProxy::UseAllocator useAllocator) {
|
||||
return GrDynamicAtlas::MakeLazyAtlasProxy(callback, CoverageTypeToColorType(coverageType),
|
||||
return GrDynamicAtlas::MakeLazyAtlasProxy(std::move(callback),
|
||||
CoverageTypeToColorType(coverageType),
|
||||
CoverageTypeHasInternalMultisample(coverageType),
|
||||
caps, useAllocator);
|
||||
caps,
|
||||
useAllocator);
|
||||
}
|
||||
|
||||
GrCCAtlas(CoverageType, const Specs&, const GrCaps&);
|
||||
|
@ -19,8 +19,7 @@ void GrCCClipPath::init(
|
||||
SkASSERT(!this->isInitialized());
|
||||
|
||||
fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy(
|
||||
[this](GrResourceProvider* resourceProvider, const GrBackendFormat& format,
|
||||
int sampleCount) {
|
||||
[this](GrResourceProvider* resourceProvider, const GrCCAtlas::LazyAtlasDesc& desc) {
|
||||
SkASSERT(fHasAtlas);
|
||||
SkASSERT(!fHasAtlasTransform);
|
||||
|
||||
@ -34,8 +33,6 @@ void GrCCClipPath::init(
|
||||
|
||||
sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
|
||||
SkASSERT(texture);
|
||||
SkASSERT(texture->backendFormat() == format);
|
||||
SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount);
|
||||
|
||||
fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
|
||||
fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
|
||||
|
@ -37,8 +37,10 @@ public:
|
||||
}
|
||||
|
||||
bool isInitialized() const { return fAtlasLazyProxy != nullptr; }
|
||||
void init(const SkPath& deviceSpacePath, const SkIRect& accessRect,
|
||||
GrCCAtlas::CoverageType atlasCoverageType, const GrCaps&);
|
||||
void init(const SkPath& deviceSpacePath,
|
||||
const SkIRect& desc,
|
||||
GrCCAtlas::CoverageType atlasCoverageType,
|
||||
const GrCaps&);
|
||||
|
||||
void addAccess(const SkIRect& accessRect) {
|
||||
SkASSERT(this->isInitialized());
|
||||
|
@ -402,7 +402,8 @@ sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
|
||||
}
|
||||
}
|
||||
|
||||
GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider) {
|
||||
GrSurfaceProxy::LazyCallbackResult operator()(GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc&) {
|
||||
// We use the unique key in a way that is unrelated to the SkImage-based key that the
|
||||
// proxy may receive, hence kUnsynced.
|
||||
static constexpr auto kKeySyncMode =
|
||||
|
@ -50,23 +50,22 @@ sk_sp<SkSurface> SkSurface::MakeFromCAMetalLayer(GrContext* context,
|
||||
texInfo.fTextureType = GrTextureType::k2D;
|
||||
|
||||
sk_sp<GrRenderTargetProxy> proxy = proxyProvider->createLazyRenderTargetProxy(
|
||||
[layer, drawable, sampleCnt](GrResourceProvider* resourceProvider) {
|
||||
[layer, drawable](GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc) {
|
||||
CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
|
||||
id<CAMetalDrawable> currentDrawable = [metalLayer nextDrawable];
|
||||
|
||||
SkISize dims = {(int)metalLayer.drawableSize.width,
|
||||
(int)metalLayer.drawableSize.height};
|
||||
|
||||
GrMtlGpu* mtlGpu = (GrMtlGpu*) resourceProvider->priv().gpu();
|
||||
sk_sp<GrRenderTarget> surface;
|
||||
if (metalLayer.framebufferOnly) {
|
||||
surface = GrMtlRenderTarget::MakeWrappedRenderTarget(mtlGpu, dims, sampleCnt,
|
||||
currentDrawable.texture);
|
||||
surface = GrMtlRenderTarget::MakeWrappedRenderTarget(
|
||||
mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
|
||||
} else {
|
||||
surface = GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(
|
||||
mtlGpu, dims, sampleCnt, currentDrawable.texture, GrWrapCacheable::kNo);
|
||||
mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture,
|
||||
GrWrapCacheable::kNo);
|
||||
}
|
||||
if (surface && sampleCnt > 1) {
|
||||
if (surface && desc.fSampleCnt > 1) {
|
||||
surface->setRequiresManualMSAAResolve();
|
||||
}
|
||||
|
||||
@ -122,22 +121,22 @@ sk_sp<SkSurface> SkSurface::MakeFromMTKView(GrContext* context,
|
||||
texInfo.fTextureType = GrTextureType::k2D;
|
||||
|
||||
sk_sp<GrRenderTargetProxy> proxy = proxyProvider->createLazyRenderTargetProxy(
|
||||
[view, sampleCnt](GrResourceProvider* resourceProvider) {
|
||||
[view](GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc) {
|
||||
MTKView* mtkView = (__bridge MTKView*)view;
|
||||
id<CAMetalDrawable> currentDrawable = [mtkView currentDrawable];
|
||||
|
||||
SkISize dims = {(int)mtkView.drawableSize.width, (int)mtkView.drawableSize.height};
|
||||
|
||||
GrMtlGpu* mtlGpu = (GrMtlGpu*) resourceProvider->priv().gpu();
|
||||
sk_sp<GrRenderTarget> surface;
|
||||
if (mtkView.framebufferOnly) {
|
||||
surface = GrMtlRenderTarget::MakeWrappedRenderTarget(mtlGpu, dims, sampleCnt,
|
||||
currentDrawable.texture);
|
||||
surface = GrMtlRenderTarget::MakeWrappedRenderTarget(
|
||||
mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
|
||||
} else {
|
||||
surface = GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(
|
||||
mtlGpu, dims, sampleCnt, currentDrawable.texture, GrWrapCacheable::kNo);
|
||||
mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture,
|
||||
GrWrapCacheable::kNo);
|
||||
}
|
||||
if (surface && sampleCnt > 1) {
|
||||
if (surface && desc.fSampleCnt > 1) {
|
||||
surface->setRequiresManualMSAAResolve();
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,8 @@ DEF_GPUTEST(TextureIdleProcTest, reporter, options) {
|
||||
SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr);
|
||||
auto rtc = rt->getCanvas()->internal_private_accessTopLayerRenderTargetContext();
|
||||
auto singleUseLazyCB = [&texture](GrResourceProvider* rp) {
|
||||
auto singleUseLazyCB = [&texture](GrResourceProvider*,
|
||||
const GrSurfaceProxy::LazySurfaceDesc&) {
|
||||
auto mode = GrSurfaceProxy::LazyInstantiationKeyMode::kSynced;
|
||||
if (texture->getUniqueKey().isValid()) {
|
||||
mode = GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced;
|
||||
|
@ -83,8 +83,9 @@ public:
|
||||
ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565,
|
||||
GrRenderable::kNo);
|
||||
fProxy = GrProxyProvider::MakeFullyLazyProxy(
|
||||
[this, format,
|
||||
nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
[this, nullTexture](GrResourceProvider* rp,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc)
|
||||
-> GrSurfaceProxy::LazyCallbackResult {
|
||||
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
|
||||
fTest->fHasOpTexture = true;
|
||||
if (nullTexture) {
|
||||
@ -92,8 +93,8 @@ public:
|
||||
} else {
|
||||
static constexpr SkISize kDimensions = {1234, 567};
|
||||
sk_sp<GrTexture> texture = rp->createTexture(
|
||||
kDimensions, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
||||
SkBudgeted::kYes, GrProtected::kNo);
|
||||
kDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt,
|
||||
desc.fMipMapped, desc.fBudgeted, desc.fProtected);
|
||||
REPORTER_ASSERT(fTest->fReporter, texture);
|
||||
return texture;
|
||||
}
|
||||
@ -137,7 +138,8 @@ public:
|
||||
ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
|
||||
GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType);
|
||||
fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
|
||||
[this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
[this](GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc&)
|
||||
-> GrSurfaceProxy::LazyCallbackResult {
|
||||
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
|
||||
fTest->fHasClipTexture = true;
|
||||
fAtlas->instantiate(rp);
|
||||
@ -264,7 +266,8 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
|
||||
}
|
||||
TestCallback& operator=(const TestCallback& that) = delete;
|
||||
|
||||
LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const {
|
||||
LazyInstantiationResult operator()(GrResourceProvider*,
|
||||
const GrSurfaceProxy::LazySurfaceDesc&) const {
|
||||
*fValue = 1;
|
||||
return {fTexture, fReleaseCallback};
|
||||
}
|
||||
@ -328,32 +331,31 @@ private:
|
||||
int* testExecuteValue, bool shouldFailInstantiation)
|
||||
: INHERITED(ClassID())
|
||||
, fTestExecuteValue(testExecuteValue) {
|
||||
SkISize desc;
|
||||
desc.fWidth = kSize;
|
||||
desc.fHeight = kSize;
|
||||
SkISize dims = {kSize, kSize};
|
||||
GrBackendFormat format =
|
||||
ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
||||
GrRenderable::kNo);
|
||||
|
||||
fLazyProxy = proxyProvider->createLazyProxy(
|
||||
[testExecuteValue, shouldFailInstantiation, desc,
|
||||
format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
|
||||
[testExecuteValue, shouldFailInstantiation](
|
||||
GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc& desc)
|
||||
-> GrSurfaceProxy::LazyCallbackResult {
|
||||
if (shouldFailInstantiation) {
|
||||
*testExecuteValue = 1;
|
||||
return {};
|
||||
}
|
||||
return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
||||
SkBudgeted::kNo, GrProtected::kNo),
|
||||
return {rp->createTexture(desc.fDimensions, desc.fFormat, desc.fRenderable,
|
||||
desc.fSampleCnt, desc.fMipMapped, desc.fBudgeted,
|
||||
desc.fProtected),
|
||||
true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
|
||||
},
|
||||
format, desc, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
||||
format, dims, GrRenderable::kNo, 1, GrMipMapped::kNo,
|
||||
GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
|
||||
SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
|
||||
|
||||
SkASSERT(fLazyProxy.get());
|
||||
|
||||
this->setBounds(SkRect::MakeIWH(kSize, kSize),
|
||||
HasAABloat::kNo, IsHairline::kNo);
|
||||
this->setBounds(SkRect::Make(dims), HasAABloat::kNo, IsHairline::kNo);
|
||||
}
|
||||
|
||||
const char* name() const override { return "LazyFailedInstantiationTestOp"; }
|
||||
|
@ -336,17 +336,19 @@ public:
|
||||
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
||||
GrRenderable::kYes);
|
||||
auto proxy = GrProxyProvider::MakeFullyLazyProxy(
|
||||
[format](GrResourceProvider* resourceProvider)
|
||||
[](GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc)
|
||||
-> GrSurfaceProxy::LazyCallbackResult {
|
||||
SkASSERT(desc.fDimensions.width() < 0 && desc.fDimensions.height() < 0);
|
||||
SkISize dims;
|
||||
// TODO: until partial flushes in MDB lands we're stuck having
|
||||
// all 9 atlas draws occur
|
||||
dims.fWidth = 9 /*this->numOps()*/ * kAtlasTileSize;
|
||||
dims.fHeight = kAtlasTileSize;
|
||||
|
||||
return resourceProvider->createTexture(dims, format, GrRenderable::kYes, 1,
|
||||
GrMipMapped::kNo, SkBudgeted::kYes,
|
||||
GrProtected::kNo);
|
||||
return resourceProvider->createTexture(dims, desc.fFormat, desc.fRenderable,
|
||||
desc.fSampleCnt, desc.fMipMapped,
|
||||
desc.fBudgeted, desc.fProtected);
|
||||
},
|
||||
format,
|
||||
GrRenderable::kYes,
|
||||
|
@ -256,21 +256,22 @@ sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* ca
|
||||
const ProxyParams& p) {
|
||||
const auto format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
|
||||
|
||||
SkBackingFit fit = p.fFit;
|
||||
SkISize dims = {p.fSize, p.fSize};
|
||||
auto callback = [fit, dims, format, p](GrResourceProvider* resourceProvider) {
|
||||
auto callback = [](GrResourceProvider* resourceProvider,
|
||||
const GrSurfaceProxy::LazySurfaceDesc& desc) {
|
||||
sk_sp<GrTexture> texture;
|
||||
if (fit == SkBackingFit::kApprox) {
|
||||
texture = resourceProvider->createApproxTexture(dims, format, p.fRenderable,
|
||||
p.fSampleCnt, GrProtected::kNo);
|
||||
if (desc.fFit == SkBackingFit::kApprox) {
|
||||
texture = resourceProvider->createApproxTexture(desc.fDimensions, desc.fFormat,
|
||||
desc.fRenderable, desc.fSampleCnt,
|
||||
desc.fProtected);
|
||||
} else {
|
||||
texture = resourceProvider->createTexture(dims, format, p.fRenderable, p.fSampleCnt,
|
||||
GrMipMapped::kNo, SkBudgeted::kNo,
|
||||
GrProtected::kNo);
|
||||
texture = resourceProvider->createTexture(
|
||||
desc.fDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt,
|
||||
desc.fMipMapped, desc.fBudgeted, desc.fProtected);
|
||||
}
|
||||
return GrSurfaceProxy::LazyCallbackResult(std::move(texture));
|
||||
};
|
||||
GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone;
|
||||
SkISize dims = {p.fSize, p.fSize};
|
||||
return proxyProvider->createLazyProxy(callback, format, dims, p.fRenderable, p.fSampleCnt,
|
||||
GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, flags,
|
||||
p.fFit, p.fBudgeted, GrProtected::kNo,
|
||||
|
Loading…
Reference in New Issue
Block a user