Move texture descriptor into GrTexture
http://codereview.appspot.com/6258068/
git-svn-id: http://skia.googlecode.com/svn/trunk@4133 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index a57ac00..e5c67d6 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -23,34 +23,45 @@
*
* @return the width in texels
*/
- int width() const { return fWidth; }
+ int width() const { return fDesc.fWidth; }
/**
* Retrieves the height of the texture.
*
* @return the height in texels
*/
- int height() const { return fHeight; }
+ int height() const { return fDesc.fHeight; }
/**
* Convert from texels to normalized texture coords for POT textures
* only.
*/
- GrFixed normalizeFixedX(GrFixed x) const { GrAssert(GrIsPow2(fWidth));
- return x >> fShiftFixedX; }
- GrFixed normalizeFixedY(GrFixed y) const { GrAssert(GrIsPow2(fHeight));
- return y >> fShiftFixedY; }
+ GrFixed normalizeFixedX(GrFixed x) const {
+ GrAssert(GrIsPow2(fDesc.fWidth));
+ return x >> fShiftFixedX;
+ }
+ GrFixed normalizeFixedY(GrFixed y) const {
+ GrAssert(GrIsPow2(fDesc.fHeight));
+ return y >> fShiftFixedY;
+ }
/**
* Retrieves the pixel config specified when the texture was created.
*/
- GrPixelConfig config() const { return fConfig; }
+ GrPixelConfig config() const { return fDesc.fConfig; }
+
+ /**
+ * Return the descriptor describing the texture
+ */
+ const GrTextureDesc& desc() const { return fDesc; }
/**
* Approximate number of bytes used by the texture
*/
virtual size_t sizeInBytes() const {
- return (size_t) fWidth * fHeight * GrBytesPerPixel(fConfig);
+ return (size_t) fDesc.fWidth *
+ fDesc.fHeight *
+ GrBytesPerPixel(fDesc.fConfig);
}
/**
@@ -112,6 +123,8 @@
#if GR_DEBUG
void validate() const {
this->INHERITED::validate();
+
+ this->validateDesc();
}
#else
void validate() const {}
@@ -122,18 +135,14 @@
// base class cons sets to NULL
// subclass cons can create and set
- GrTexture(GrGpu* gpu,
- int width,
- int height,
- GrPixelConfig config)
+ GrTexture(GrGpu* gpu, const GrTextureDesc& desc)
: INHERITED(gpu)
, fRenderTarget(NULL)
- , fWidth(width)
- , fHeight(height)
- , fConfig(config) {
+ , fDesc(desc) {
+
// only make sense if alloc size is pow2
- fShiftFixedX = 31 - Gr_clz(fWidth);
- fShiftFixedY = 31 - Gr_clz(fHeight);
+ fShiftFixedX = 31 - Gr_clz(fDesc.fWidth);
+ fShiftFixedY = 31 - Gr_clz(fDesc.fHeight);
}
// GrResource overrides
@@ -143,16 +152,15 @@
virtual void onAbandon();
+ void validateDesc() const;
+
private:
- int fWidth;
- int fHeight;
+ GrTextureDesc fDesc;
// these two shift a fixed-point value into normalized coordinates
// for this texture if the texture is power of two sized.
- int fShiftFixedX;
- int fShiftFixedY;
-
- GrPixelConfig fConfig;
+ int fShiftFixedX;
+ int fShiftFixedY;
typedef GrResource INHERITED;
};
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 0486cbf..ef80142 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -593,13 +593,15 @@
* count Gr will create an MSAA buffer that resolves into the texture. Gr auto-
* resolves when it reads from the texture. The client can explictly resolve
* using the GrRenderTarget interface.
+ *
+ * Note: These flags currently form a subset of GrTexture's flags.
*/
enum GrPlatformTextureFlags {
/**
* No flags enabled
*/
- kNone_GrPlatformTextureFlag = 0x0,
+ kNone_GrPlatformTextureFlag = kNone_GrTextureFlags,
/**
* Indicates that the texture is also a render target, and thus should have
* a GrRenderTarget object.
@@ -607,7 +609,7 @@
* D3D (future): client must have created the texture with flags that allow
* it to be used as a render target.
*/
- kRenderTarget_GrPlatformTextureFlag = 0x1,
+ kRenderTarget_GrPlatformTextureFlag = kRenderTarget_GrTextureFlagBit,
};
GR_MAKE_BITFIELD_OPS(GrPlatformTextureFlags)
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index c145c71..00ae8d0 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -44,9 +44,15 @@
void GrTexture::releaseRenderTarget() {
if (NULL != fRenderTarget) {
GrAssert(fRenderTarget->asTexture() == this);
+ GrAssert(fDesc.fFlags & kRenderTarget_GrTextureFlagBit);
+
fRenderTarget->onTextureReleaseRenderTarget();
fRenderTarget->unref();
fRenderTarget = NULL;
+
+ fDesc.fFlags = fDesc.fFlags &
+ ~(kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit);
+ fDesc.fSampleCnt = 0;
}
}
@@ -56,3 +62,21 @@
}
}
+void GrTexture::validateDesc() const {
+ if (NULL != this->asRenderTarget()) {
+ // This texture has a render target
+ GrAssert(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
+
+ if (NULL != this->asRenderTarget()->getStencilBuffer()) {
+ GrAssert(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ } else {
+ GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ }
+
+ GrAssert(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
+ } else {
+ GrAssert(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
+ GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
+ GrAssert(0 == fDesc.fSampleCnt);
+ }
+}
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 3d30610..476d3e7 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -50,20 +50,14 @@
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
const Desc& textureDesc)
- : INHERITED(gpu,
- textureDesc.fWidth,
- textureDesc.fHeight,
- textureDesc.fConfig) {
+ : INHERITED(gpu, textureDesc) {
this->init(gpu, textureDesc, NULL);
}
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
const Desc& textureDesc,
const GrGLRenderTarget::Desc& rtDesc)
- : INHERITED(gpu,
- textureDesc.fWidth,
- textureDesc.fHeight,
- textureDesc.fConfig) {
+ : INHERITED(gpu, textureDesc) {
this->init(gpu, textureDesc, &rtDesc);
}
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 77e1c32..dd6419e 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -58,10 +58,7 @@
void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
};
- struct Desc {
- int fWidth;
- int fHeight;
- GrPixelConfig fConfig;
+ struct Desc : public GrTextureDesc {
GrGLuint fTextureID;
bool fOwnsID;
Orientation fOrientation;
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 004702f..90fb2a6 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -557,9 +557,12 @@
return NULL;
}
+ // next line relies on PlatformTextureDesc's flags matching GrTexture's
+ glTexDesc.fFlags = (GrTextureFlags) desc.fFlags;
glTexDesc.fWidth = desc.fWidth;
glTexDesc.fHeight = desc.fHeight;
glTexDesc.fConfig = desc.fConfig;
+ glTexDesc.fSampleCnt = desc.fSampleCnt;
glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
glTexDesc.fOwnsID = false;
glTexDesc.fOrientation = GrGLTexture::kBottomUp_Orientation;
@@ -638,11 +641,13 @@
this->setSpareTextureUnit();
GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID()));
GrGLTexture::Desc desc;
- desc.fConfig = glTex->config();
+ desc.fFlags = glTex->desc().fFlags;
desc.fWidth = glTex->width();
desc.fHeight = glTex->height();
- desc.fOrientation = glTex->orientation();
+ desc.fConfig = glTex->config();
+ desc.fSampleCnt = glTex->desc().fSampleCnt;
desc.fTextureID = glTex->textureID();
+ desc.fOrientation = glTex->orientation();
this->uploadTexData(desc, false,
left, top, width, height,
@@ -1002,9 +1007,12 @@
// Attempt to catch un- or wrongly initialized sample counts;
GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
+ glTexDesc.fFlags = desc.fFlags;
glTexDesc.fWidth = desc.fWidth;
glTexDesc.fHeight = desc.fHeight;
glTexDesc.fConfig = desc.fConfig;
+ glTexDesc.fSampleCnt = desc.fSampleCnt;
+
glTexDesc.fOwnsID = true;
glRTDesc.fMSColorRenderbufferID = 0;