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
This commit is contained in:
robertphillips@google.com 2012-06-04 12:48:45 +00:00
Родитель 1830c7aa3c
Коммит 3271628342
6 изменённых файлов: 72 добавлений и 39 удалений

Просмотреть файл

@ -23,34 +23,45 @@ public:
*
* @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 @@ public:
#if GR_DEBUG
void validate() const {
this->INHERITED::validate();
this->validateDesc();
}
#else
void validate() const {}
@ -122,18 +135,14 @@ protected:
// 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 @@ protected:
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;
};

Просмотреть файл

@ -593,13 +593,15 @@ typedef intptr_t GrPlatform3DObject;
* 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 @@ enum GrPlatformTextureFlags {
* 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)

Просмотреть файл

@ -44,9 +44,15 @@ void GrTexture::writePixels(int left, int top, int width, int height,
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::onAbandon() {
}
}
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);
}
}

Просмотреть файл

@ -50,20 +50,14 @@ void GrGLTexture::init(GrGpuGL* gpu,
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);
}

Просмотреть файл

@ -58,10 +58,7 @@ public:
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;

Просмотреть файл

@ -557,9 +557,12 @@ GrTexture* GrGpuGL::onCreatePlatformTexture(const GrPlatformTextureDesc& desc) {
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 @@ void GrGpuGL::onWriteTexturePixels(GrTexture* texture,
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 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
// 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;