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
This commit is contained in:
bsalomon@google.com 2011-05-02 21:14:59 +00:00
Родитель d9fec6114f
Коммит 05ef510389
8 изменённых файлов: 95 добавлений и 91 удалений

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

@ -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 @@ public:
/**
* 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 @@ public:
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 @@ public:
*
* @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 @@ public:
* 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 @@ public:
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 @@ public:
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

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

@ -28,61 +28,43 @@ class GrIndexBufferAllocPool;
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 @@ public:
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 @@ protected:
int fMinRenderTargetHeight;
int fMaxTextureDimension;
Stats fStats;
GrGpuStats fStats;
const GrVertexBuffer* fCurrPoolVertexBuffer;
int fCurrPoolStartVertex;

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

@ -165,6 +165,24 @@ static inline int16_t GrToS16(intptr_t x) {
#endif
///////////////////////////////////////////////////////////////////////////////
/**
* 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;
///////////////////////////////////////////////////////////////////////////////
/**

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

@ -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 int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
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::Create(GrGpu::Engine engine,
}
GrContext* GrContext::CreateGLShaderContext() {
return GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
return GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
}
GrContext::~GrContext() {
@ -351,6 +351,25 @@ GrResource* GrContext::createPlatformSurface(const GrPlatformSurfaceDesc& desc)
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 @@ bool GrContext::supportsIndex8PixelConfig(const GrSamplerState& sampler,
////////////////////////////////////////////////////////////////////////////////
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 @@ void GrContext::resetStats() {
fGpu->resetStats();
}
const GrGpu::Stats& GrContext::getStats() const {
const GrGpuStats& GrContext::getStats() const {
return fGpu->getStats();
}

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

@ -725,7 +725,7 @@ void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) {
////////////////////////////////////////////////////////////////////////////////
const GrGpu::Stats& GrGpu::getStats() const {
const GrGpuStats& GrGpu::getStats() const {
return fStats;
}

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

@ -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* GrGpu::Create(Engine engine, Platform3DContext context3D) {
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 @@ GrGpu* GrGpu::Create(Engine engine, Platform3DContext context3D) {
#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);

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

@ -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) {

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

@ -378,9 +378,9 @@ bool SampleWindow::make3DReady() {
if (NULL == fGrContext) {
#if defined(SK_USE_SHADERS)
fGrContext = GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, NULL);
fGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
#else
fGrContext = GrContext::Create(GrGpu::kOpenGL_Fixed_Engine, NULL);
fGrContext = GrContext::Create(kOpenGL_Fixed_GrEngine, NULL);
#endif
SkDebugf("---- constructor\n");
}