diff options
Diffstat (limited to 'gpu/src')
-rw-r--r-- | gpu/src/GrContext.cpp | 13 | ||||
-rw-r--r-- | gpu/src/GrGpu.cpp | 60 | ||||
-rw-r--r-- | gpu/src/GrGpuGL.cpp | 34 | ||||
-rw-r--r-- | gpu/src/GrGpuGL.h | 51 | ||||
-rw-r--r-- | gpu/src/GrGpuGLFixed.cpp | 8 | ||||
-rw-r--r-- | gpu/src/GrGpuGLFixed.h | 4 | ||||
-rw-r--r-- | gpu/src/GrGpuGLShaders2.cpp | 6 | ||||
-rw-r--r-- | gpu/src/GrGpuGLShaders2.h | 4 |
8 files changed, 111 insertions, 69 deletions
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp index a047895ced..c6fa618920 100644 --- a/gpu/src/GrContext.cpp +++ b/gpu/src/GrContext.cpp @@ -560,9 +560,14 @@ void GrContext::drawPath(const GrPaint& paint, //////////////////////////////////////////////////////////////////////////////// -void GrContext::flush(bool flushRenderTarget) { - flushDrawBuffer(); - if (flushRenderTarget) { +void GrContext::flush(int flagsBitfield) { + if (kDiscard_FlushBit & flagsBitfield) { + fDrawBuffer->reset(); + } else { + flushDrawBuffer(); + } + + if (kForceCurrentRenderTarget_FlushBit & flagsBitfield) { fGpu->forceRenderTargetFlush(); } } @@ -683,7 +688,7 @@ GrDrawTarget* GrContext::prepareToDraw(const GrPaint& paint, //////////////////////////////////////////////////////////////////////////////// void GrContext::resetContext() { - fGpu->resetContext(); + fGpu->markContextDirty(); } void GrContext::setRenderTarget(GrRenderTarget* target) { diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp index 045dcd00b6..d41005b531 100644 --- a/gpu/src/GrGpu.cpp +++ b/gpu/src/GrGpu.cpp @@ -71,6 +71,7 @@ GrGpu::GrGpu() : f8bitPaletteSupport(false), fQuadIndexBuffer(NULL), fUnitSquareVertexBuffer(NULL), fPathRenderer(NULL), + fContextIsDirty(true), fVertexPoolInUse(false), fIndexPoolInUse(false) { #if GR_DEBUG @@ -98,6 +99,54 @@ void GrGpu::unimpl(const char msg[]) { //////////////////////////////////////////////////////////////////////////////// +GrTexture* GrGpu::createTexture(const TextureDesc& desc, + const void* srcData, size_t rowBytes) { + this->handleDirtyContext(); + return this->createTextureHelper(desc, srcData, rowBytes); +} + +GrRenderTarget* GrGpu::createPlatformRenderTarget(intptr_t platformRenderTarget, + int stencilBits, + int width, int height) { + this->handleDirtyContext(); + return this->createPlatformRenderTargetHelper(platformRenderTarget, + stencilBits, + width, height); +} + +GrRenderTarget* GrGpu::createRenderTargetFrom3DApiState() { + this->handleDirtyContext(); + return this->createRenderTargetFrom3DApiStateHelper(); +} + +GrVertexBuffer* GrGpu::createVertexBuffer(uint32_t size, bool dynamic) { + this->handleDirtyContext(); + return this->createVertexBufferHelper(size, dynamic); +} + +GrIndexBuffer* GrGpu::createIndexBuffer(uint32_t size, bool dynamic) { + this->handleDirtyContext(); + return this->createIndexBufferHelper(size, dynamic); +} + +void GrGpu::eraseColor(GrColor color) { + this->handleDirtyContext(); + this->eraseColorHelper(color); +} + +void GrGpu::forceRenderTargetFlush() { + this->handleDirtyContext(); + this->forceRenderTargetFlushHelper(); +} + +bool GrGpu::readPixels(int left, int top, int width, int height, + GrTexture::PixelConfig config, void* buffer) { + this->handleDirtyContext(); + return this->readPixelsHelper(left, top, width, height, config, buffer); +} + +//////////////////////////////////////////////////////////////////////////////// + static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); @@ -184,7 +233,8 @@ const GrStencilSettings GrGpu::gClipStencilSettings = { 0, 0 }; -// converts special stencil func to +// mapping of clip-respecting stencil funcs to normal stencil funcs +// mapping depends on whether stencil-clipping is in effect. static const GrStencilFunc gGrClipToNormalStencilFunc[2][kClipStencilFuncCount] = { {// Stencil-Clipping is DISABLED, effectively always inside the clip // In the Clip Funcs @@ -445,7 +495,9 @@ void GrGpu::drawIndexed(GrPrimitiveType type, GrAssert(kReserved_GeometrySrcType != fGeometrySrc.fIndexSrc || fReservedGeometry.fLocked); - if (!setupClipAndFlushState(type)) { + this->handleDirtyContext(); + + if (!this->setupClipAndFlushState(type)) { return; } @@ -469,7 +521,9 @@ void GrGpu::drawNonIndexed(GrPrimitiveType type, GrAssert(kReserved_GeometrySrcType != fGeometrySrc.fVertexSrc || fReservedGeometry.fLocked); - if (!setupClipAndFlushState(type)) { + this->handleDirtyContext(); + + if (!this->setupClipAndFlushState(type)) { return; } #if GR_COLLECT_STATS diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp index 3ee524b74b..b0d5e73bc9 100644 --- a/gpu/src/GrGpuGL.cpp +++ b/gpu/src/GrGpuGL.cpp @@ -152,8 +152,6 @@ GrGpuGL::GrGpuGL() { GrGLInitExtensions(&fExts); - resetContextHelper(); - resetDirtyFlags(); GLint maxTextureUnits; @@ -427,8 +425,8 @@ GrGpuGL::GrGpuGL() { GrGpuGL::~GrGpuGL() { } -void GrGpuGL::resetContextHelper() { -// We detect cases when blending is effectively off +void GrGpuGL::resetContext() { + // We detect cases when blending is effectively off fHWBlendDisabled = false; GR_GL(Enable(GL_BLEND)); @@ -491,12 +489,7 @@ void GrGpuGL::resetContextHelper() { fHWDrawState.fRenderTarget = NULL; } -void GrGpuGL::resetContext() { - INHERITED::resetContext(); - resetContextHelper(); -} - -GrRenderTarget* GrGpuGL::createPlatformRenderTarget( +GrRenderTarget* GrGpuGL::createPlatformRenderTargetHelper( intptr_t platformRenderTarget, int stencilBits, int width, @@ -520,7 +513,7 @@ GrRenderTarget* GrGpuGL::createPlatformRenderTarget( return new GrGLRenderTarget(rtIDs, stencilBits, viewport, NULL, this); } -GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiState() { +GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiStateHelper() { GrGLRenderTarget::GLRenderTargetIDs rtIDs; @@ -575,8 +568,9 @@ static size_t as_size_t(int x) { } #endif -GrTexture* GrGpuGL::createTexture(const TextureDesc& desc, - const void* srcData, size_t rowBytes) { +GrTexture* GrGpuGL::createTextureHelper(const TextureDesc& desc, + const void* srcData, + size_t rowBytes) { #if GR_COLLECT_STATS ++fStats.fTextureCreateCnt; @@ -988,7 +982,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc, return tex; } -GrVertexBuffer* GrGpuGL::createVertexBuffer(uint32_t size, bool dynamic) { +GrVertexBuffer* GrGpuGL::createVertexBufferHelper(uint32_t size, bool dynamic) { GLuint id; GR_GL(GenBuffers(1, &id)); if (id) { @@ -1012,7 +1006,7 @@ GrVertexBuffer* GrGpuGL::createVertexBuffer(uint32_t size, bool dynamic) { return NULL; } -GrIndexBuffer* GrGpuGL::createIndexBuffer(uint32_t size, bool dynamic) { +GrIndexBuffer* GrGpuGL::createIndexBufferHelper(uint32_t size, bool dynamic) { GLuint id; GR_GL(GenBuffers(1, &id)); if (id) { @@ -1066,7 +1060,7 @@ void GrGpuGL::flushScissor(const GrIRect* rect) { } } -void GrGpuGL::eraseColor(GrColor color) { +void GrGpuGL::eraseColorHelper(GrColor color) { if (NULL == fCurrDrawState.fRenderTarget) { return; } @@ -1121,12 +1115,12 @@ void GrGpuGL::eraseStencilClip(const GrIRect& rect) { fHWDrawState.fStencilSettings.invalidate(); } -void GrGpuGL::forceRenderTargetFlush() { +void GrGpuGL::forceRenderTargetFlushHelper() { flushRenderTarget(); } -bool GrGpuGL::readPixels(int left, int top, int width, int height, - GrTexture::PixelConfig config, void* buffer) { +bool GrGpuGL::readPixelsHelper(int left, int top, int width, int height, + GrTexture::PixelConfig config, void* buffer) { GLenum internalFormat; // we don't use this for glReadPixels GLenum format; GLenum type; @@ -1207,7 +1201,7 @@ GLenum gPrimitiveType2GLMode[] = { #define SWAP_PER_DRAW 0 -#if SWAP_PER_DRAW +#if SWAP_PER_DRAW #if GR_MAC_BUILD #include <AGL/agl.h> #elif GR_WIN32_BUILD diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h index a2905c5d30..ab504adbb2 100644 --- a/gpu/src/GrGpuGL.h +++ b/gpu/src/GrGpuGL.h @@ -31,28 +31,6 @@ public: GrGpuGL(); virtual ~GrGpuGL(); - // overrides from GrGpu - virtual void resetContext(); - - virtual GrTexture* createTexture(const TextureDesc& desc, - const void* srcData, size_t rowBytes); - virtual GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic); - virtual GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic); - - virtual GrRenderTarget* createPlatformRenderTarget( - intptr_t platformRenderTarget, - int stencilBits, - int width, int height); - - virtual GrRenderTarget* createRenderTargetFrom3DApiState(); - - virtual void eraseColor(GrColor color); - - virtual void forceRenderTargetFlush(); - - virtual bool readPixels(int left, int top, int width, int height, - GrTexture::PixelConfig, void* buffer); - /** * Gets the struct containing the GL extensions for the context * underlying the GrGpuGL @@ -97,6 +75,31 @@ protected: GrGLExts fExts; // GrGpu overrides + // overrides from GrGpu + virtual void resetContext(); + + virtual GrTexture* createTextureHelper(const TextureDesc& desc, + const void* srcData, + size_t rowBytes); + virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size, + bool dynamic); + virtual GrIndexBuffer* createIndexBufferHelper(uint32_t size, + bool dynamic); + + virtual GrRenderTarget* createPlatformRenderTargetHelper( + intptr_t platformRenderTarget, + int stencilBits, + int width, int height); + + virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper(); + + virtual void eraseColorHelper(GrColor color); + + virtual void forceRenderTargetFlushHelper(); + + virtual bool readPixelsHelper(int left, int top, int width, int height, + GrTexture::PixelConfig, void* buffer); + virtual void drawIndexedHelper(GrPrimitiveType type, uint32_t startVertex, uint32_t startIndex, @@ -140,8 +143,6 @@ protected: const GrSamplerState& sampler); private: - void resetContextHelper(); - // notify callbacks to update state tracking when related // objects are bound to GL or deleted outside of the class void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); @@ -190,4 +191,4 @@ private: typedef GrGpu INHERITED; }; -#endif
\ No newline at end of file +#endif diff --git a/gpu/src/GrGpuGLFixed.cpp b/gpu/src/GrGpuGLFixed.cpp index 516381e308..695b22c156 100644 --- a/gpu/src/GrGpuGLFixed.cpp +++ b/gpu/src/GrGpuGLFixed.cpp @@ -58,7 +58,6 @@ static const GLenum gMatrixMode2Enum[] = { /////////////////////////////////////////////////////////////////////////////// GrGpuGLFixed::GrGpuGLFixed() { - resetContextHelper(); } GrGpuGLFixed::~GrGpuGLFixed() { @@ -66,10 +65,7 @@ GrGpuGLFixed::~GrGpuGLFixed() { void GrGpuGLFixed::resetContext() { INHERITED::resetContext(); - resetContextHelper(); -} -void GrGpuGLFixed::resetContextHelper() { GR_GL(Disable(GL_TEXTURE_2D)); for (int s = 0; s < kNumStages; ++s) { @@ -204,11 +200,11 @@ bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) { } if (((1 << s) & fDirtyFlags.fTextureChangedMask) || - (fHWDrawState.fSamplerStates[s].getMatrix() != + (fHWDrawState.fSamplerStates[s].getMatrix() != getSamplerMatrix(s))) { GrMatrix texMat = getSamplerMatrix(s); - AdjustTextureMatrix(texture, + AdjustTextureMatrix(texture, GrSamplerState::kNormal_SampleMode, &texMat); GrGpuMatrix glm; diff --git a/gpu/src/GrGpuGLFixed.h b/gpu/src/GrGpuGLFixed.h index 5b81ea616d..077b6e2a38 100644 --- a/gpu/src/GrGpuGLFixed.h +++ b/gpu/src/GrGpuGLFixed.h @@ -26,8 +26,6 @@ public: GrGpuGLFixed(); virtual ~GrGpuGLFixed(); - virtual void resetContext(); - protected: // overrides from GrGpu virtual bool flushGraphicsState(GrPrimitiveType type); @@ -37,7 +35,7 @@ protected: int indexCount); private: - void resetContextHelper(); + virtual void resetContext(); // Helpers to make code more readable const GrMatrix& getHWSamplerMatrix(int stage) const { diff --git a/gpu/src/GrGpuGLShaders2.cpp b/gpu/src/GrGpuGLShaders2.cpp index 77847e9fba..f79e9c883a 100644 --- a/gpu/src/GrGpuGLShaders2.cpp +++ b/gpu/src/GrGpuGLShaders2.cpp @@ -1088,8 +1088,6 @@ void GrGpuGLShaders2::DeleteProgram(Program* program) { GrGpuGLShaders2::GrGpuGLShaders2() { - resetContextHelper(); - fProgram = NULL; fProgramCache = new ProgramCache(); @@ -1119,11 +1117,9 @@ void GrGpuGLShaders2::recordHWSamplerMatrix(int stage, const GrMatrix& matrix){ } void GrGpuGLShaders2::resetContext() { + INHERITED::resetContext(); - resetContextHelper(); -} -void GrGpuGLShaders2::resetContextHelper() { fHWGeometryState.fVertexLayout = 0; fHWGeometryState.fVertexOffset = ~0; GR_GL(DisableVertexAttribArray(COL_ATTR_LOCATION)); diff --git a/gpu/src/GrGpuGLShaders2.h b/gpu/src/GrGpuGLShaders2.h index e8785c9677..4c501be69e 100644 --- a/gpu/src/GrGpuGLShaders2.h +++ b/gpu/src/GrGpuGLShaders2.h @@ -26,8 +26,6 @@ public: GrGpuGLShaders2(); virtual ~GrGpuGLShaders2(); - virtual void resetContext(); - protected: // overrides from GrGpu virtual bool flushGraphicsState(GrPrimitiveType type); @@ -38,7 +36,7 @@ protected: private: - void resetContextHelper(); + virtual void resetContext(); // Helpers to make code more readable const GrMatrix& getHWSamplerMatrix(int stage); |