Remove GrContext.h dependence on GrGpu.h
Review URL: http://codereview.appspot.com/4433096/
git-svn-id: http://skia.googlecode.com/svn/trunk@1227 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index faf535f..951c0e6 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -18,12 +18,13 @@
#define GrContext_DEFINED
#include "GrClip.h"
-#include "GrGpu.h"
#include "GrTextureCache.h"
#include "GrPaint.h"
#include "GrPathRenderer.h"
class GrFontCache;
+class GrGpu;
+struct GrGpuStats;
class GrPathIter;
class GrVertexBufferAllocPool;
class GrIndexBufferAllocPool;
@@ -34,8 +35,8 @@
/**
* Creates a GrContext from within a 3D context.
*/
- static GrContext* Create(GrGpu::Engine engine,
- GrGpu::Platform3DContext context3D);
+ static GrContext* Create(GrEngine engine,
+ GrPlatform3DContext context3D);
/**
* Helper to create a opengl-shader based context
@@ -208,14 +209,7 @@
GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
- int width, int height) {
- #if GR_DEBUG
- GrPrintf("Using deprecated createPlatformRenderTarget API.");
- #endif
- return fGpu->createPlatformRenderTarget(platformRenderTarget,
- stencilBits, isMultisampled,
- width, height);
- }
+ int width, int height);
/**
* DEPRECATED, WILL BE REMOVED SOON. USE createPlatformSurface.
@@ -228,12 +222,7 @@
*
* @return the newly created GrRenderTarget
*/
- GrRenderTarget* createRenderTargetFrom3DApiState() {
- #if GR_DEBUG
- GrPrintf("Using deprecated createRenderTargetFrom3DApiState API.");
- #endif
- return fGpu->createRenderTargetFrom3DApiState();
- }
+ GrRenderTarget* createRenderTargetFrom3DApiState();
///////////////////////////////////////////////////////////////////////////
// Matrix state
@@ -264,7 +253,7 @@
* Gets the current clip.
* @return the current clip.
*/
- const GrClip& getClip() const { return fGpu->getClip(); }
+ const GrClip& getClip() const;
/**
* Sets the clip.
@@ -507,16 +496,6 @@
void writePixels(int left, int top, int width, int height,
GrPixelConfig, const void* buffer, size_t stride);
-
- ///////////////////////////////////////////////////////////////////////////
- // Statistics
-
- void resetStats();
-
- const GrGpu::Stats& getStats() const;
-
- void printStats() const;
-
///////////////////////////////////////////////////////////////////////////
// Helpers
@@ -548,6 +527,9 @@
GrDrawTarget* getTextTarget(const GrPaint& paint);
void flushText();
const GrIndexBuffer* getQuadIndexBuffer() const;
+ void resetStats();
+ const GrGpuStats& getStats() const;
+ void printStats() const;
private:
// used to keep track of when we need to flush the draw buffer
diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h
index 16bb6b6..5602d1a 100644
--- a/gpu/include/GrGpu.h
+++ b/gpu/include/GrGpu.h
@@ -28,61 +28,43 @@
class GrResource;
class GrVertexBufferAllocPool;
+/**
+ * Gpu usage statistics.
+ */
+struct GrGpuStats {
+ uint32_t fVertexCnt; //<! Number of vertices drawn
+ uint32_t fIndexCnt; //<! Number of indices drawn
+ uint32_t fDrawCnt; //<! Number of draws
+
+ uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
+
+ /*
+ * Number of times the texture is set in 3D API
+ */
+ uint32_t fTextureChngCnt;
+ /*
+ * Number of times the render target is set in 3D API
+ */
+ uint32_t fRenderTargetChngCnt;
+ /*
+ * Number of textures created (includes textures that are rendertargets).
+ */
+ uint32_t fTextureCreateCnt;
+ /*
+ * Number of rendertargets created.
+ */
+ uint32_t fRenderTargetCreateCnt;
+};
+
class GrGpu : public GrDrawTarget {
public:
/**
- * Possible 3D APIs that may be used by Ganesh.
- */
- enum Engine {
- kOpenGL_Shaders_Engine,
- kOpenGL_Fixed_Engine,
- kDirect3D9_Engine
- };
-
- /**
- * Platform specific 3D context.
- * For
- * kOpenGL_Shaders_Engine use NULL
- * kOpenGL_Fixed_Engine use NULL
- * kDirect3D9_Engine use an IDirect3DDevice9*
- */
- typedef void* Platform3DContext;
-
- /**
* Create an instance of GrGpu that matches the specified Engine backend.
* If the requested engine is not supported (at compile-time or run-time)
* this returns NULL.
*/
- static GrGpu* Create(Engine, Platform3DContext context3D);
-
- /**
- * Gpu usage statistics.
- */
- struct Stats {
- uint32_t fVertexCnt; //<! Number of vertices drawn
- uint32_t fIndexCnt; //<! Number of indices drawn
- uint32_t fDrawCnt; //<! Number of draws
-
- uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
-
- /*
- * Number of times the texture is set in 3D API
- */
- uint32_t fTextureChngCnt;
- /*
- * Number of times the render target is set in 3D API
- */
- uint32_t fRenderTargetChngCnt;
- /*
- * Number of textures created (includes textures that are rendertargets).
- */
- uint32_t fTextureCreateCnt;
- /*
- * Number of rendertargets created.
- */
- uint32_t fRenderTargetCreateCnt;
- };
+ static GrGpu* Create(GrEngine, GrPlatform3DContext context3D);
////////////////////////////////////////////////////////////////////////////
@@ -320,7 +302,7 @@
int left, int top, int width, int height,
GrPixelConfig config, void* buffer);
- const Stats& getStats() const;
+ const GrGpuStats& getStats() const;
void resetStats();
void printStats() const;
@@ -407,7 +389,7 @@
int fMinRenderTargetHeight;
int fMaxTextureDimension;
- Stats fStats;
+ GrGpuStats fStats;
const GrVertexBuffer* fCurrPoolVertexBuffer;
int fCurrPoolStartVertex;
diff --git a/gpu/include/GrTypes.h b/gpu/include/GrTypes.h
index d4cfc10..08b10f0 100644
--- a/gpu/include/GrTypes.h
+++ b/gpu/include/GrTypes.h
@@ -168,6 +168,24 @@
///////////////////////////////////////////////////////////////////////////////
/**
+ * Possible 3D APIs that may be used by Ganesh.
+ */
+enum GrEngine {
+ kOpenGL_Shaders_GrEngine,
+ kOpenGL_Fixed_GrEngine,
+ kDirect3D9_GrEngine
+};
+
+/**
+ * Engine-specific 3D context handle
+ * Unused for GL.
+ * IDirect3DDevice9* for D3D9
+ */
+typedef intptr_t GrPlatform3DContext;
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
* Type used to describe format of vertices in arrays
* Values are defined in GrDrawTarget
*/
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index 2263172..399eaf8 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -15,7 +15,7 @@
*/
#include "GrContext.h"
-#include "GrTypes.h"
+#include "GrGpu.h"
#include "GrTextureCache.h"
#include "GrTextStrike.h"
#include "GrMemory.h"
@@ -43,8 +43,8 @@
static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 0;
static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 0;
-GrContext* GrContext::Create(GrGpu::Engine engine,
- GrGpu::Platform3DContext context3D) {
+GrContext* GrContext::Create(GrEngine engine,
+ GrPlatform3DContext context3D) {
GrContext* ctx = NULL;
GrGpu* fGpu = GrGpu::Create(engine, context3D);
if (NULL != fGpu) {
@@ -55,7 +55,7 @@
}
GrContext* GrContext::CreateGLShaderContext() {
- return GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
+ return GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
}
GrContext::~GrContext() {
@@ -351,6 +351,25 @@
return fGpu->createPlatformSurface(desc);
}
+GrRenderTarget* GrContext::createPlatformRenderTarget(intptr_t platformRenderTarget,
+ int stencilBits,
+ bool isMultisampled,
+ int width, int height) {
+#if GR_DEBUG
+ GrPrintf("Using deprecated createPlatformRenderTarget API.");
+#endif
+ return fGpu->createPlatformRenderTarget(platformRenderTarget,
+ stencilBits, isMultisampled,
+ width, height);
+}
+
+GrRenderTarget* GrContext::createRenderTargetFrom3DApiState() {
+#if GR_DEBUG
+ GrPrintf("Using deprecated createRenderTargetFrom3DApiState API.");
+#endif
+ return fGpu->createRenderTargetFrom3DApiState();
+}
+
///////////////////////////////////////////////////////////////////////////////
bool GrContext::supportsIndex8PixelConfig(const GrSamplerState& sampler,
@@ -378,6 +397,8 @@
////////////////////////////////////////////////////////////////////////////////
+const GrClip& GrContext::getClip() const { return fGpu->getClip(); }
+
void GrContext::setClip(const GrClip& clip) {
fGpu->setClip(clip);
fGpu->enableState(GrDrawTarget::kClip_StateBit);
@@ -1355,7 +1376,7 @@
fGpu->resetStats();
}
-const GrGpu::Stats& GrContext::getStats() const {
+const GrGpuStats& GrContext::getStats() const {
return fGpu->getStats();
}
diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp
index cb78204..5fff20f 100644
--- a/gpu/src/GrGpu.cpp
+++ b/gpu/src/GrGpu.cpp
@@ -725,7 +725,7 @@
////////////////////////////////////////////////////////////////////////////////
-const GrGpu::Stats& GrGpu::getStats() const {
+const GrGpuStats& GrGpu::getStats() const {
return fStats;
}
diff --git a/gpu/src/GrGpuFactory.cpp b/gpu/src/GrGpuFactory.cpp
index 1715333..c6f541c 100644
--- a/gpu/src/GrGpuFactory.cpp
+++ b/gpu/src/GrGpuFactory.cpp
@@ -28,10 +28,10 @@
#include "GrGpuGLShaders.h"
#include "GrGpuGLShaders2.h"
-GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
+GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
- if (kOpenGL_Shaders_Engine == engine ||
- kOpenGL_Fixed_Engine == engine) {
+ if (kOpenGL_Shaders_GrEngine == engine ||
+ kOpenGL_Fixed_GrEngine == engine) {
// If no GL bindings have been installed, fall-back to calling the
// GL functions that have been linked with the executable.
if (!GrGLGetGLInterface()) {
@@ -46,7 +46,7 @@
GrGpu* gpu = NULL;
switch (engine) {
- case kOpenGL_Shaders_Engine:
+ case kOpenGL_Shaders_GrEngine:
GrAssert(NULL == context3D);
{
#if GR_USE_NEW_GLSHADERS
@@ -56,11 +56,11 @@
#endif
}
break;
- case kOpenGL_Fixed_Engine:
+ case kOpenGL_Fixed_GrEngine:
GrAssert(NULL == context3D);
gpu = new GrGpuGLFixed;
break;
- case kDirect3D9_Engine:
+ case kDirect3D9_GrEngine:
GrAssert(NULL != context3D);
#if GR_WIN32_BUILD
// gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
diff --git a/gpu/src/GrTexture.cpp b/gpu/src/GrTexture.cpp
index e9ec4e6..8ee531c 100644
--- a/gpu/src/GrTexture.cpp
+++ b/gpu/src/GrTexture.cpp
@@ -16,6 +16,7 @@
#include "GrTexture.h"
#include "GrContext.h"
+#include "GrGpu.h"
bool GrRenderTarget::readPixels(int left, int top, int width, int height,
GrPixelConfig config, void* buffer) {