Make RT & TEX base classes aware of NPOT/min-RT bloated size
Review URL: http://codereview.appspot.com/4849045/
git-svn-id: http://skia.googlecode.com/svn/trunk@2057 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrRenderTarget.h b/gpu/include/GrRenderTarget.h
index 06d62a4..13b1a3a 100644
--- a/gpu/include/GrRenderTarget.h
+++ b/gpu/include/GrRenderTarget.h
@@ -44,6 +44,20 @@
int height() const { return fHeight; }
/**
+ * Retrieves the allocated width. It may differ from width for
+ * NPOT or min-RT size reasons.
+ * @return allocated width in pixels
+ */
+ int allocatedWidth() const { return fAllocatedWidth; }
+
+ /**
+ * Retrieves the allocated height. It may differ from height for
+ * NPOT or min-RT size reasons.
+ * @return allocated height in pixels
+ */
+ int allocatedHeight() const { return fAllocatedHeight; }
+
+ /**
* @return the pixel config. Can be kUnknown_GrPixelConfig
* if client asked us to render to a target that has a pixel
* config that isn't equivalent with one of our configs.
@@ -151,6 +165,8 @@
GrTexture* texture,
int width,
int height,
+ int allocatedWidth,
+ int allocatedHeight,
GrPixelConfig config,
int sampleCnt)
: INHERITED(gpu)
@@ -158,6 +174,8 @@
, fTexture(texture)
, fWidth(width)
, fHeight(height)
+ , fAllocatedWidth(allocatedWidth)
+ , fAllocatedHeight(allocatedHeight)
, fConfig(config)
, fSampleCnt(sampleCnt)
{
@@ -181,6 +199,8 @@
GrTexture* fTexture; // not ref'ed
int fWidth;
int fHeight;
+ int fAllocatedWidth;
+ int fAllocatedHeight;
GrPixelConfig fConfig;
int fSampleCnt;
GrIRect fResolveRect;
diff --git a/gpu/include/GrTexture.h b/gpu/include/GrTexture.h
index 9bdd340..77f88fa 100644
--- a/gpu/include/GrTexture.h
+++ b/gpu/include/GrTexture.h
@@ -33,6 +33,20 @@
int height() const { return fHeight; }
/**
+ * Retrieves the allocated width. It may differ from width for
+ * NPOT or min-RT size reasons.
+ * @return allocated width in texels
+ */
+ int allocatedWidth() const { return fAllocatedWidth; }
+
+ /**
+ * Retrieves the allocated height. It may differ from height for
+ * NPOT or min-RT size reasons.
+ * @return allocated height in texels
+ */
+ int allocatedHeight() const { return fAllocatedHeight; }
+
+ /**
* Convert from texels to normalized texture coords for POT textures
* only.
*/
@@ -50,7 +64,7 @@
* Approximate number of bytes used by the texture
*/
virtual size_t sizeInBytes() const {
- return fWidth * fHeight * GrBytesPerPixel(fConfig);
+ return fAllocatedWidth * fAllocatedHeight * GrBytesPerPixel(fConfig);
}
/**
@@ -125,11 +139,15 @@
GrTexture(GrGpu* gpu,
int width,
int height,
+ int allocatedWidth,
+ int allocatedHeight,
GrPixelConfig config)
: INHERITED(gpu)
, fRenderTarget(NULL)
, fWidth(width)
, fHeight(height)
+ , fAllocatedWidth(allocatedWidth)
+ , fAllocatedHeight(allocatedHeight)
, fConfig(config) {
// only make sense if alloc size is pow2
fShiftFixedX = 31 - Gr_clz(fWidth);
@@ -146,6 +164,9 @@
private:
int fWidth;
int fHeight;
+ int fAllocatedWidth;
+ int fAllocatedHeight;
+
// these two shift a fixed-point value into normalized coordinates
// for this texture if the texture is power of two sized.
int fShiftFixedX;