const GrRenderTarget* asRenderTarget() const override { return this; }
// GrRenderTarget
- bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; }
+ bool isStencilBufferMultisampled() const { return fSampleCnt > 0; }
GrFSAAType fsaaType() const {
- if (!fDesc.fSampleCnt) {
+ if (!fSampleCnt) {
SkASSERT(!(fFlags & Flags::kMixedSampled));
return GrFSAAType::kNone;
}
/**
* Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
*/
- int numStencilSamples() const { return fDesc.fSampleCnt; }
+ int numStencilSamples() const { return fSampleCnt; }
/**
* Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled).
*/
int numColorSamples() const {
- return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fDesc.fSampleCnt;
+ return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fSampleCnt;
}
/**
friend class GrRenderTargetPriv;
friend class GrRenderTargetProxy; // for Flags
+ int fSampleCnt;
GrStencilAttachment* fStencilAttachment;
uint8_t fMultisampleSpecsID;
Flags fFlags;
/**
* Retrieves the width of the surface.
*/
- int width() const { return fDesc.fWidth; }
+ int width() const { return fWidth; }
/**
* Retrieves the height of the surface.
*/
- int height() const { return fDesc.fHeight; }
+ int height() const { return fHeight; }
/**
* Helper that gets the width and height of the surface as a bounding rectangle.
SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
GrSurfaceOrigin origin() const {
- SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin ||
- kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin);
- return fDesc.fOrigin;
+ SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
+ return fOrigin;
}
/**
* if client asked us to render to a target that has a pixel
* config that isn't equivalent with one of our configs.
*/
- GrPixelConfig config() const { return fDesc.fConfig; }
+ GrPixelConfig config() const { return fConfig; }
/**
* @return the texture associated with the surface, may be null.
friend class GrSurfacePriv;
GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
- : INHERITED(gpu)
- , fDesc(desc) {
- }
+ : INHERITED(gpu)
+ , fConfig(desc.fConfig)
+ , fWidth(desc.fWidth)
+ , fHeight(desc.fHeight)
+ , fOrigin(desc.fOrigin) {}
~GrSurface() override {}
- GrSurfaceDesc fDesc;
void onRelease() override;
void onAbandon() override;
private:
+ GrPixelConfig fConfig;
+ int fWidth;
+ int fHeight;
+ GrSurfaceOrigin fOrigin;
+
typedef GrGpuResource INHERITED;
};
#ifdef SK_DEBUG
void validate() const {
this->INHERITED::validate();
- this->validateDesc();
}
#endif
GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType,
GrSamplerParams::FilterMode highestFilterMode, bool wasMipMapDataProvided);
- void validateDesc() const;
-
private:
void computeScratchKey(GrScratchKey*) const override;
size_t onGpuMemorySize() const override;
GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, Flags flags,
GrStencilAttachment* stencil)
- : INHERITED(gpu, desc)
- , fStencilAttachment(stencil)
- , fMultisampleSpecsID(0)
- , fFlags(flags) {
- SkASSERT(!(fFlags & Flags::kMixedSampled) || fDesc.fSampleCnt > 0);
+ : INHERITED(gpu, desc)
+ , fSampleCnt(desc.fSampleCnt)
+ , fStencilAttachment(stencil)
+ , fMultisampleSpecsID(0)
+ , fFlags(flags) {
+ SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+ SkASSERT(!(fFlags & Flags::kMixedSampled) || fSampleCnt > 0);
SkASSERT(!(fFlags & Flags::kWindowRectsSupport) || gpu->caps()->maxWindowRectangles() > 0);
fResolveRect.setLargestInverted();
}
return proxy->priv().isExact() || (SkIsPow2(proxy->width()) && SkIsPow2(proxy->height()));
}
+bool validate_desc(const GrSurfaceDesc& desc, const GrCaps& caps, int levelCount = 0) {
+ if (desc.fWidth <= 0 || desc.fHeight <= 0) {
+ return false;
+ }
+ if (!caps.isConfigTexturable(desc.fConfig)) {
+ return false;
+ }
+ if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
+ if (!caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ return false;
+ }
+ } else {
+ if (desc.fSampleCnt) {
+ return false;
+ }
+ }
+ if (levelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
+ return false;
+ }
+ return true;
+}
+
// MDB TODO: this should probably be a factory on GrSurfaceProxy
sk_sp<GrTextureProxy> GrResourceProvider::createMipMappedTexture(
const GrSurfaceDesc& desc,
return nullptr;
}
- if (mipLevelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
- return nullptr;
- }
- if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
- !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ if (!validate_desc(desc, *fCaps, mipLevelCount)) {
return nullptr;
}
return nullptr;
}
+ if (!validate_desc(desc, *fCaps)) {
+ return nullptr;
+ }
+
GrContext* context = fGpu->getContext();
if (!GrPixelConfigIsCompressed(desc.fConfig)) {
return nullptr;
}
- if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
- !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ if (!validate_desc(desc, *fCaps)) {
return nullptr;
}
return nullptr;
}
+ if (!validate_desc(desc, *fCaps)) {
+ return nullptr;
+ }
+
return this->refScratchTexture(desc, flags);
}
-GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
- uint32_t flags) {
+GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc, uint32_t flags) {
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
- SkASSERT(inDesc.fWidth > 0 && inDesc.fHeight > 0);
+ SkASSERT(validate_desc(inDesc, *fCaps));
SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
this->texturePriv().hasMipMaps(), false);
}
-void GrTexture::validateDesc() const {
- if (this->asRenderTarget()) {
- // This texture has a render target
- SkASSERT(0 != (fDesc.fFlags & kRenderTarget_GrSurfaceFlag));
- SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numColorSamples());
- } else {
- SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrSurfaceFlag));
- SkASSERT(0 == fDesc.fSampleCnt);
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
namespace {
, fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) {
if (wasMipMapDataProvided) {
fMipMapsStatus = kValid_MipMapsStatus;
- fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeight);
+ fMaxMipMapLevel = SkMipMap::ComputeLevelCount(this->width(), this->height());
} else {
fMipMapsStatus = kNotAllocated_MipMapsStatus;
fMaxMipMapLevel = 0;
}
void GrTexture::computeScratchKey(GrScratchKey* key) const {
- if (!GrPixelConfigIsCompressed(fDesc.fConfig)) {
- GrTexturePriv::ComputeScratchKey(fDesc, key);
+ if (!GrPixelConfigIsCompressed(this->config())) {
+ const GrRenderTarget* rt = this->asRenderTarget();
+ int sampleCount = 0;
+ if (rt) {
+ sampleCount = rt->numStencilSamples();
+ }
+ GrTexturePriv::ComputeScratchKey(this->config(), this->width(), this->height(),
+ this->origin(), SkToBool(rt), sampleCount,
+ this->texturePriv().hasMipMaps(), key);
}
}
-void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
+void GrTexturePriv::ComputeScratchKey(GrPixelConfig config, int width, int height,
+ GrSurfaceOrigin origin, bool isRenderTarget, int sampleCnt,
+ bool isMipMapped, GrScratchKey* key) {
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
+ uint32_t flags = isRenderTarget;
- GrSurfaceOrigin origin = resolve_origin(desc);
- uint32_t flags = desc.fFlags;
+ SkASSERT(0 == sampleCnt || isRenderTarget);
// make sure desc.fConfig fits in 5 bits
SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5);
- SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5));
- SkASSERT(desc.fSampleCnt < (1 << 8));
+ SkASSERT(static_cast<int>(config) < (1 << 5));
+ SkASSERT(sampleCnt < (1 << 8));
SkASSERT(flags < (1 << 10));
SkASSERT(static_cast<int>(origin) < (1 << 8));
GrScratchKey::Builder builder(key, kType, 3);
- builder[0] = desc.fWidth;
- builder[1] = desc.fHeight;
- builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6) | (flags << 14)
- | (origin << 24);
+ builder[0] = width;
+ builder[1] = height;
+ builder[2] = config | (isMipMapped << 5) | (sampleCnt << 6) | (flags << 14) | (origin << 24);
+}
+
+void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
+ GrSurfaceOrigin origin = resolve_origin(desc);
+ return ComputeScratchKey(desc.fConfig, desc.fWidth, desc.fHeight, origin,
+ SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag), desc.fSampleCnt,
+ desc.fIsMipMapped, key);
}
implemented privately in GrTexture with a inline public method here). */
class GrTexturePriv {
public:
- void setFlag(GrSurfaceFlags flags) {
- fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags;
- }
-
- void resetFlag(GrSurfaceFlags flags) {
- fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags;
- }
-
- bool isSetFlag(GrSurfaceFlags flags) const {
- return 0 != (fTexture->fDesc.fFlags & flags);
- }
-
void dirtyMipMaps(bool mipMapsDirty) {
fTexture->dirtyMipMaps(mipMapsDirty);
}
static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*);
private:
+ static void ComputeScratchKey(GrPixelConfig config, int width, int height,
+ GrSurfaceOrigin origin, bool isRenderTarget, int sampleCnt,
+ bool isMipMapped, GrScratchKey* key);
+
GrTexturePriv(GrTexture* texture) : fTexture(texture) { }
GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { }
GrTexturePriv& operator=(const GrTexturePriv&); // unimpl
return return_null_texture();
}
- bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+ bool isRenderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
GrGLTexture::IDDesc idDesc;
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
GrGLTexture::TexParams initialTexParams;
- if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexParams, texels)) {
+ if (!this->createTextureImpl(desc, &idDesc.fInfo, isRenderTarget, &initialTexParams, texels)) {
return return_null_texture();
}
}
GrGLTexture* tex;
- if (renderTarget) {
+ if (isRenderTarget) {
// unbind the texture from the texture unit before binding it to the frame buffer
GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0));
GrGLRenderTarget::IDDesc rtIDDesc;
if (fTexFBOID == kUnresolvableFBOID || fTexFBOID != fRTFBOID) {
// If the render target's FBO is external (fTexFBOID == kUnresolvableFBOID), or if we own
// the render target's FBO (fTexFBOID == fRTFBOID) then we use the provided sample count.
- return SkTMax(1, fDesc.fSampleCnt);
+ return SkTMax(1, this->numStencilSamples());
}
// When fTexFBOID == fRTFBOID, we either are not using MSAA, or MSAA is auto resolving, so use
return false;
}
- bool renderTarget = SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag);
+ bool renderTarget = SkToBool(this->asRenderTarget());
VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
if (renderTarget) {
GrVkImage::ImageDesc imageDesc;
imageDesc.fImageType = VK_IMAGE_TYPE_2D;
imageDesc.fFormat = fInfo.fFormat;
- imageDesc.fWidth = fDesc.fWidth;
- imageDesc.fHeight = fDesc.fHeight;
+ imageDesc.fWidth = this->width();
+ imageDesc.fHeight = this->height();
imageDesc.fLevels = mipLevels;
imageDesc.fSamples = 1;
imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) {
VkFormat pixelFormat;
- GrPixelConfigToVkFormat(fDesc.fConfig, &pixelFormat);
- if (fDesc.fSampleCnt) {
+ GrPixelConfigToVkFormat(this->config(), &pixelFormat);
+ if (this->numStencilSamples()) {
const GrVkImageView* resolveAttachmentView =
GrVkImageView::Create(gpu,
newInfo.fImage,