/* Copyright 2010 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef GrGpu_DEFINED #define GrGpu_DEFINED #include "GrRect.h" #include "GrRefCnt.h" #include "GrDrawTarget.h" #include "GrTexture.h" class GrVertexBufferAllocPool; class GrIndexBufferAllocPool; class GrPathRenderer; 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); /** * Used to control the level of antialiasing available for a rendertarget. * Anti-alias quality levels depend on the underlying API/GPU capabilities. */ enum AALevels { kNone_AALevel, //resetContext(); fContextIsDirty = false; } } GrVertexBufferAllocPool* fVertexPool; GrIndexBufferAllocPool* fIndexPool; mutable GrIndexBuffer* fQuadIndexBuffer; // mutable so it can be // created on-demand mutable GrVertexBuffer* fUnitSquareVertexBuffer; // mutable so it can be // created on-demand GrPathRenderer* fPathRenderer; bool fContextIsDirty; // when in an internal draw these indicate whether the pools are in use // by one of the outer draws. If false then it is safe to reset the // pool. bool fVertexPoolInUse; bool fIndexPoolInUse; // used to save and restore state when the GrGpu needs // to make its geometry pools available internally class AutoInternalDrawGeomRestore { public: AutoInternalDrawGeomRestore(GrGpu* gpu) : fAgsr(gpu) { fGpu = gpu; fVertexPoolWasInUse = gpu->fVertexPoolInUse; fIndexPoolWasInUse = gpu->fIndexPoolInUse; gpu->fVertexPoolInUse = fVertexPoolWasInUse || (kBuffer_GeometrySrcType != gpu->fGeometrySrc.fVertexSrc); gpu->fIndexPoolInUse = fIndexPoolWasInUse || (kBuffer_GeometrySrcType != gpu->fGeometrySrc.fIndexSrc);; fSavedPoolVertexBuffer = gpu->fCurrPoolVertexBuffer; fSavedPoolStartVertex = gpu->fCurrPoolStartVertex; fSavedPoolIndexBuffer = gpu->fCurrPoolIndexBuffer; fSavedPoolStartIndex = gpu->fCurrPoolStartIndex; fSavedReservedGeometry = gpu->fReservedGeometry; gpu->fReservedGeometry.fLocked = false; } ~AutoInternalDrawGeomRestore() { fGpu->fCurrPoolVertexBuffer = fSavedPoolVertexBuffer; fGpu->fCurrPoolStartVertex = fSavedPoolStartVertex; fGpu->fCurrPoolIndexBuffer = fSavedPoolIndexBuffer; fGpu->fCurrPoolStartIndex = fSavedPoolStartIndex; fGpu->fVertexPoolInUse = fVertexPoolWasInUse; fGpu->fIndexPoolInUse = fIndexPoolWasInUse; fGpu->fReservedGeometry = fSavedReservedGeometry; } private: AutoGeometrySrcRestore fAgsr; GrGpu* fGpu; const GrVertexBuffer* fSavedPoolVertexBuffer; int fSavedPoolStartVertex; const GrIndexBuffer* fSavedPoolIndexBuffer; int fSavedPoolStartIndex; bool fVertexPoolWasInUse; bool fIndexPoolWasInUse; ReservedGeometry fSavedReservedGeometry; }; typedef GrDrawTarget INHERITED; }; #endif