Reduce glGets for stencil bits.
Clean up GL vs Gr rect conventions for viewport and scissor.
Review URL: http://codereview.appspot.com/4185056/
git-svn-id: http://skia.googlecode.com/svn/trunk@813 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index 973198b..93c012c 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -145,9 +145,16 @@
/**
* Wraps an externally-created rendertarget in a GrRenderTarget.
- * e.g. in GL platforamRenderTarget is an FBO id.
+ * @param platformRenderTarget 3D API-specific render target identifier
+ * e.g. in GL platforamRenderTarget is an FBO
+ * id.
+ * @param stencilBits the number of stencil bits that the render
+ * target has.
+ * @param width width of the render target.
+ * @param height height of the render target.
*/
GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
+ int stencilBits,
int width, int height);
/**
diff --git a/gpu/include/GrGLConfig.h b/gpu/include/GrGLConfig.h
index e20e3a5..dcad9a1 100644
--- a/gpu/include/GrGLConfig.h
+++ b/gpu/include/GrGLConfig.h
@@ -384,4 +384,40 @@
#define GR_GLEXT(exts, X) exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
#define GR_GLEXT_NO_ERR(exts, X) GrGLClearErr(); exts. X; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Helpers for glGetString()
+ */
+bool has_gl_extension(const char* ext);
+void gl_version(int* major, int* minor);
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
+ * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
+ */
+#if GR_SUPPORT_GLDESKTOP
+ static inline void GrGL_RestoreResetRowLength() {
+ GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0));
+ }
+#else
+ #define GrGL_RestoreResetRowLength()
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Some drivers want the var-int arg to be zero-initialized on input.
+ */
+#define GR_GL_INIT_ZERO 0
+#define GR_GL_GetIntegerv(e, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL(GetIntegerv(e, p)); \
+ } while (0)
+
+////////////////////////////////////////////////////////////////////////////////
+
#endif
\ No newline at end of file
diff --git a/gpu/include/GrGLTexture.h b/gpu/include/GrGLTexture.h
index 6f1b961..fc12ee0 100644
--- a/gpu/include/GrGLTexture.h
+++ b/gpu/include/GrGLTexture.h
@@ -18,36 +18,14 @@
#ifndef GrGLTexture_DEFINED
#define GrGLTexture_DEFINED
-#include "GrGLConfig.h"
-#include "GrGpu.h"
#include "GrTexture.h"
-#include "GrRect.h"
+#include "GrScalar.h"
+#include "GrGLIRect.h"
class GrGpuGL;
class GrGLTexture;
class GrGLRenderTarget : public GrRenderTarget {
-protected:
-
- struct GLRenderTargetIDs {
- GLuint fRTFBOID;
- GLuint fTexFBOID;
- GLuint fStencilRenderbufferID;
- GLuint fMSColorRenderbufferID;
- bool fOwnIDs;
- };
-
- GrGLRenderTarget(const GLRenderTargetIDs& ids,
- const GrIRect& fViewport,
- GrGLTexture* texture,
- GrGpuGL* gl);
-
- void setViewport(const GrIRect& rect) { GrAssert(rect.height() <= 0);
- fViewport = rect;}
-
- virtual uint32_t width() const { return fViewport.width(); }
- virtual uint32_t height() const { return -fViewport.height(); }
-
public:
virtual ~GrGLRenderTarget();
@@ -58,15 +36,39 @@
GLuint renderFBOID() const { return fRTFBOID; }
GLuint textureFBOID() const { return fTexFBOID; }
- const GrIRect& viewport() const { return fViewport; }
+ GLuint getStencilBits() const { return fStencilBits; }
+
+ const GrGLIRect& viewport() const { return fViewport; }
void abandon();
+protected:
+
+ struct GLRenderTargetIDs {
+ GLuint fRTFBOID;
+ GLuint fTexFBOID;
+ GLuint fStencilRenderbufferID;
+ GLuint fMSColorRenderbufferID;
+ bool fOwnIDs;
+ };
+
+ GrGLRenderTarget(const GLRenderTargetIDs& ids,
+ GLuint stencilBits,
+ const GrGLIRect& fViewport,
+ GrGLTexture* texture,
+ GrGpuGL* gl);
+
+ void setViewport(const GrGLIRect& rect) { fViewport = rect; }
+
+ virtual int width() const { return fViewport.fWidth; }
+ virtual int height() const { return fViewport.fHeight; }
+
private:
GrGpuGL* fGL;
GLuint fRTFBOID;
GLuint fTexFBOID;
GLuint fStencilRenderbufferID;
GLuint fMSColorRenderbufferID;
+ GLuint fStencilBits;
// Should this object delete IDs when it is destroyed or does someone
// else own them.
@@ -79,7 +81,7 @@
// when we switch to this rendertarget we want to set the viewport to
// only render to to content area (as opposed to the whole allocation) and
// we want the rendering to be at top left (GL has origin in bottom left)
- GrIRect fViewport;
+ GrGLIRect fViewport;
friend class GrGpuGL;
friend class GrGLTexture;
@@ -111,6 +113,7 @@
GLenum fUploadFormat;
GLenum fUploadByteCount;
GLenum fUploadType;
+ GLuint fStencilBits;
Orientation fOrientation;
};
typedef GrGLRenderTarget::GLRenderTargetIDs GLRenderTargetIDs;
diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h
index a132e9f..cfa1509 100644
--- a/gpu/include/GrGpu.h
+++ b/gpu/include/GrGpu.h
@@ -170,11 +170,13 @@
* @param platformRenderTarget handle to the the render target in the
* underlying 3D API. Interpretation depends on
* GrGpu subclass in use.
+ * @param stencilBits number of stencil bits the target has
* @param width width of the render target
* @param height height of the render target
*/
virtual GrRenderTarget* createPlatformRenderTarget(
intptr_t platformRenderTarget,
+ int stencilBits,
int width, int height) = 0;
/**
@@ -351,12 +353,6 @@
// prepares clip flushes gpu state before a draw
bool setupClipAndFlushState(PrimitiveType type);
- struct BoundsState {
- bool fScissorEnabled;
- GrIRect fScissorRect;
- GrIRect fViewportRect;
- };
-
// defaults to false, subclass can set true to support palleted textures
bool f8bitPaletteSupport;
diff --git a/gpu/include/GrTexture.h b/gpu/include/GrTexture.h
index 5b3ed09..098ac59 100644
--- a/gpu/include/GrTexture.h
+++ b/gpu/include/GrTexture.h
@@ -34,11 +34,11 @@
/**
* @return the width of the rendertarget
*/
- virtual uint32_t width() const = 0;
+ virtual int width() const = 0;
/**
* @return the height of the rendertarget
*/
- virtual uint32_t height() const = 0;
+ virtual int height() const = 0;
/**
* @return the texture associated with the rendertarget, may be NULL.
diff --git a/gpu/include/GrUserConfig.h b/gpu/include/GrUserConfig.h
index 819f093..201d836 100644
--- a/gpu/include/GrUserConfig.h
+++ b/gpu/include/GrUserConfig.h
@@ -28,8 +28,6 @@
#define GR_DEBUG 1
#endif
-//#define GR_FORCE_GLCHECKERR 1
-
/*
* The default 32bit pixel config for texture upload is GL_RGBA on all
* platforms except on Windows where it is GL_BGRA. If your bitmaps map to a