diff options
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrBackendEffectFactory.h | 70 | ||||
-rw-r--r-- | include/gpu/GrEffect.h | 6 | ||||
-rw-r--r-- | include/gpu/GrEffectStage.h | 23 | ||||
-rw-r--r-- | include/gpu/GrRenderTarget.h | 11 | ||||
-rw-r--r-- | include/gpu/GrSurface.h | 31 | ||||
-rw-r--r-- | include/gpu/GrTBackendEffectFactory.h | 73 | ||||
-rw-r--r-- | include/gpu/GrTexture.h | 4 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 2 |
8 files changed, 135 insertions, 85 deletions
diff --git a/include/gpu/GrBackendEffectFactory.h b/include/gpu/GrBackendEffectFactory.h index 89562d5239..c496f5a13a 100644 --- a/include/gpu/GrBackendEffectFactory.h +++ b/include/gpu/GrBackendEffectFactory.h @@ -10,14 +10,21 @@ #include "GrTypes.h" #include "SkTemplates.h" +#include "SkThread_platform.h" #include "GrNoncopyable.h" -/** Given a GrEffect of a particular type, creates the corresponding - graphics-backend-specific GrGLEffect. Also tracks equivalence - of shaders generated via a key. +/** Given a GrEffect of a particular type, creates the corresponding graphics-backend-specific + effect object. Also tracks equivalence of shaders generated via a key. Each factory instance + is assigned a generation ID at construction. The ID of the return of GrEffect::getFactory() + is used as a type identifier. Thus a GrEffect subclass must return a singleton from + getFactory(). GrEffect subclasses should use the derived class GrTBackendEffectFactory that is + templated on the GrEffect subclass as their factory object. It requires that the GrEffect + subclass has a nested class (or typedef) GLEffect which is its GL implementation and a subclass + of GrGLEffect. */ class GrEffect; +class GrEffectStage; class GrGLEffect; class GrGLCaps; @@ -35,7 +42,7 @@ public: kTextureKeyBits = 6 }; - virtual EffectKey glEffectKey(const GrEffect&, const GrGLCaps&) const = 0; + virtual EffectKey glEffectKey(const GrEffectStage&, const GrGLCaps&) const = 0; virtual GrGLEffect* createGLInstance(const GrEffect&) const = 0; bool operator ==(const GrBackendEffectFactory& b) const { @@ -71,59 +78,4 @@ private: static int32_t fCurrEffectClassID; }; -template <typename EffectClass> -class GrTBackendEffectFactory : public GrBackendEffectFactory { - -public: - typedef typename EffectClass::GLEffect GLEffect; - - /** Returns a human-readable name that is accessible via GrEffect or - GrGLEffect and is consistent between the two of them. - */ - virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } - - /** Returns a value that identifies the GLSL shader code generated by - a GrEffect. This enables caching of generated shaders. Part of the - id identifies the GrEffect subclass. The remainder is based - on the aspects of the GrEffect object's configuration that affect - GLSL code generation. */ - virtual EffectKey glEffectKey(const GrEffect& effect, const GrGLCaps& caps) const SK_OVERRIDE { - GrAssert(kIllegalEffectClassID != fEffectClassID); - EffectKey effectKey = GLEffect::GenKey(effect, caps); - EffectKey textureKey = GLEffect::GenTextureKey(effect, caps); -#if GR_DEBUG - static const EffectKey kIllegalIDMask = (uint16_t) (~((1U << kEffectKeyBits) - 1)); - GrAssert(!(kIllegalIDMask & effectKey)); - - static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTextureKeyBits) - 1)); - GrAssert(!(kIllegalTextureKeyMask & textureKey)); -#endif - return fEffectClassID | (textureKey << kEffectKeyBits) | effectKey; - } - - /** Returns a new instance of the appropriate *GL* implementation class - for the given GrEffect; caller is responsible for deleting - the object. */ - virtual GLEffect* createGLInstance(const GrEffect& effect) const SK_OVERRIDE { - return SkNEW_ARGS(GLEffect, (*this, effect)); - } - - /** This class is a singleton. This function returns the single instance. - */ - static const GrBackendEffectFactory& getInstance() { - static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; - static const GrTBackendEffectFactory* gInstance; - if (!gInstance) { - gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), - GrTBackendEffectFactory); - } - return *gInstance; - } - -protected: - GrTBackendEffectFactory() { - fEffectClassID = GenID() << (kEffectKeyBits + kTextureKeyBits) ; - } -}; - #endif diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h index d7209ff563..0adc00be00 100644 --- a/include/gpu/GrEffect.h +++ b/include/gpu/GrEffect.h @@ -10,10 +10,10 @@ #include "GrRefCnt.h" #include "GrNoncopyable.h" -#include "GrBackendEffectFactory.h" #include "GrEffectUnitTest.h" #include "GrTextureAccess.h" +class GrBackendEffectFactory; class GrContext; class GrTexture; class SkString; @@ -33,8 +33,6 @@ class GrEffect : public GrRefCnt { public: SK_DECLARE_INST_COUNT(GrEffect) - typedef GrBackendEffectFactory::EffectKey EffectKey; - explicit GrEffect(int numTextures); virtual ~GrEffect(); @@ -77,7 +75,7 @@ public: /** Human-meaningful string to identify this effect; may be embedded in generated shader code. */ - const char* name() const { return this->getFactory().name(); } + const char* name() const; int numTextures() const { return fNumTextures; } diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h index 6f8b23fea9..5cd0af3b83 100644 --- a/include/gpu/GrEffectStage.h +++ b/include/gpu/GrEffectStage.h @@ -8,9 +8,10 @@ -#ifndef GrSamplerState_DEFINED -#define GrSamplerState_DEFINED +#ifndef GrEffectStage_DEFINED +#define GrEffectStage_DEFINED +#include "GrBackendEffectFactory.h" #include "GrEffect.h" #include "GrMatrix.h" #include "GrTypes.h" @@ -70,7 +71,7 @@ public: class SavedCoordChange { private: GrMatrix fCoordChangeMatrix; - GR_DEBUGCODE(mutable SkAutoTUnref<GrEffect> fEffect;) + GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;) friend class GrEffectStage; }; @@ -79,7 +80,7 @@ public: * This gets the current coordinate system change. It is the accumulation of * preConcatCoordChange calls since the effect was installed. It is used when then caller * wants to temporarily change the source geometry coord system, draw something, and then - * restore the previous coord system (e.g. temporarily draw in device coords).s + * restore the previous coord system (e.g. temporarily draw in device coords). */ void saveCoordChange(SavedCoordChange* savedCoordChange) const { savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; @@ -106,18 +107,24 @@ public: /** * Gets the matrix to apply at draw time. This is the original texture matrix combined with - * any coord system changes. + * any coord system changes. This will be removed when the matrix is managed by GrEffect. */ void getTotalMatrix(GrMatrix* matrix) const { *matrix = fMatrix; matrix->preConcat(fCoordChangeMatrix); } + /** + * Gets the matrix representing all changes of coordinate system since the GrEffect was + * installed in the stage. + */ + const GrMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; } + void reset() { GrSafeSetNull(fEffect); } - GrEffect* setEffect(GrEffect* effect) { + const GrEffect* setEffect(const GrEffect* effect) { GrAssert(0 == fSavedCoordChangeCnt); GrSafeAssign(fEffect, effect); fMatrix.reset(); @@ -125,7 +132,7 @@ public: return effect; } - GrEffect* setEffect(GrEffect* effect, const GrMatrix& matrix) { + const GrEffect* setEffect(const GrEffect* effect, const GrMatrix& matrix) { GrAssert(0 == fSavedCoordChangeCnt); GrSafeAssign(fEffect, effect); fMatrix = matrix; @@ -138,7 +145,7 @@ public: private: GrMatrix fCoordChangeMatrix; GrMatrix fMatrix; // TODO: remove this, store in GrEffect - GrEffect* fEffect; + const GrEffect* fEffect; GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;) }; diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h index 58a3aa5220..2a6e62ac01 100644 --- a/include/gpu/GrRenderTarget.h +++ b/include/gpu/GrRenderTarget.h @@ -40,7 +40,7 @@ public: // GrSurface overrides /** - * @return the texture associated with the rendertarget, may be NULL. + * @return the texture associated with the render target, may be NULL. */ virtual GrTexture* asTexture() SK_OVERRIDE { return fTexture; } virtual const GrTexture* asTexture() const SK_OVERRIDE { return fTexture; } @@ -75,7 +75,7 @@ public: /** * If this RT is multisampled, this is the buffer it is resolved to. * Otherwise, same as getRenderTargetHandle(). - * (In GL a separate FBO ID is used for the msaa and resolved buffers) + * (In GL a separate FBO ID is used for the MSAA and resolved buffers) * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL) */ virtual GrBackendObject getRenderTargetResolvedHandle() const = 0; @@ -150,15 +150,16 @@ public: protected: GrRenderTarget(GrGpu* gpu, GrTexture* texture, - const GrTextureDesc& desc) - : INHERITED(gpu, desc) + const GrTextureDesc& desc, + Origin origin) + : INHERITED(gpu, desc, origin) , fStencilBuffer(NULL) , fTexture(texture) { fResolveRect.setLargestInverted(); } friend class GrTexture; - // When a texture unrefs an owned rendertarget this func + // When a texture unrefs an owned render target this func // removes the back pointer. This could be called from // texture's destructor but would have to be done in derived // classes. By the time of texture base destructor it has already diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h index aa237aee4d..d7aa2672d8 100644 --- a/include/gpu/GrSurface.h +++ b/include/gpu/GrSurface.h @@ -34,6 +34,22 @@ public: int height() const { return fDesc.fHeight; } /** + * Some surfaces will be stored such that the upper and left edges of the content meet at the + * the origin (in texture coord space) and for other surfaces the lower and left edges meet at + * the origin. Render-targets are always consistent with the convention of the underlying + * backend API to make it easier to mix native backend rendering with Skia rendering. Wrapped + * backend surfaces always use the backend's convention as well. + */ + enum Origin { + kTopLeft_Origin, + kBottomLeft_Origin, + }; + Origin origin() const { + GrAssert(kTopLeft_Origin == fOrigin || kBottomLeft_Origin == fOrigin); + return fOrigin; + } + + /** * Retrieves the pixel config specified when the surface was created. * For render targets this can be kUnknown_GrPixelConfig * if client asked us to render to a target that has a pixel @@ -66,7 +82,7 @@ public: * @param height height of rectangle to read in pixels. * @param config the pixel config of the destination buffer * @param buffer memory to read the rectangle into. - * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly + * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly * packed. * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. * @@ -88,7 +104,7 @@ public: * @param height height of rectangle to write in pixels. * @param config the pixel config of the source buffer * @param buffer memory to read the rectangle from. - * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly + * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly * packed. * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum. */ @@ -99,14 +115,17 @@ public: uint32_t pixelOpsFlags = 0) = 0; protected: - GrTextureDesc fDesc; - - GrSurface(GrGpu* gpu, const GrTextureDesc& desc) + GrSurface(GrGpu* gpu, const GrTextureDesc& desc, Origin origin) : INHERITED(gpu) - , fDesc(desc) { + , fDesc(desc) + , fOrigin(origin) { } + GrTextureDesc fDesc; + private: + Origin fOrigin; + typedef GrResource INHERITED; }; diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h new file mode 100644 index 0000000000..52dbc64dd8 --- /dev/null +++ b/include/gpu/GrTBackendEffectFactory.h @@ -0,0 +1,73 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTBackendEffectFactory_DEFINED +#define GrTBackendEffectFactory_DEFINED + +#include "GrBackendEffectFactory.h" +#include "GrEffectStage.h" + +/** + * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. + */ +template <typename EffectClass> +class GrTBackendEffectFactory : public GrBackendEffectFactory { + +public: + typedef typename EffectClass::GLEffect GLEffect; + + /** Returns a human-readable name that is accessible via GrEffect or + GrGLEffect and is consistent between the two of them. + */ + virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } + + /** Returns a value that identifies the GLSL shader code generated by + a GrEffect. This enables caching of generated shaders. Part of the + id identifies the GrEffect subclass. The remainder is based + on the aspects of the GrEffect object's configuration that affect + GLSL code generation. */ + virtual EffectKey glEffectKey(const GrEffectStage& stage, + const GrGLCaps& caps) const SK_OVERRIDE { + GrAssert(kIllegalEffectClassID != fEffectClassID); + EffectKey effectKey = GLEffect::GenKey(stage, caps); + EffectKey textureKey = GLEffect::GenTextureKey(*stage.getEffect(), caps); +#if GR_DEBUG + static const EffectKey kIllegalIDMask = (uint16_t) (~((1U << kEffectKeyBits) - 1)); + GrAssert(!(kIllegalIDMask & effectKey)); + + static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTextureKeyBits) - 1)); + GrAssert(!(kIllegalTextureKeyMask & textureKey)); +#endif + return fEffectClassID | (textureKey << kEffectKeyBits) | effectKey; + } + + /** Returns a new instance of the appropriate *GL* implementation class + for the given GrEffect; caller is responsible for deleting + the object. */ + virtual GLEffect* createGLInstance(const GrEffect& effect) const SK_OVERRIDE { + return SkNEW_ARGS(GLEffect, (*this, effect)); + } + + /** This class is a singleton. This function returns the single instance. + */ + static const GrBackendEffectFactory& getInstance() { + static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; + static const GrTBackendEffectFactory* gInstance; + if (!gInstance) { + gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), + GrTBackendEffectFactory); + } + return *gInstance; + } + +protected: + GrTBackendEffectFactory() { + fEffectClassID = GenID() << (kEffectKeyBits + kTextureKeyBits) ; + } +}; + +#endif diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h index a8d67e7529..65950a6a96 100644 --- a/include/gpu/GrTexture.h +++ b/include/gpu/GrTexture.h @@ -146,8 +146,8 @@ protected: // base class cons sets to NULL // subclass cons can create and set - GrTexture(GrGpu* gpu, const GrTextureDesc& desc) - : INHERITED(gpu, desc) + GrTexture(GrGpu* gpu, const GrTextureDesc& desc, Origin origin) + : INHERITED(gpu, desc, origin) , fRenderTarget(NULL) { // only make sense if alloc size is pow2 diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index 8bd1f2f8a8..9723868be9 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -457,7 +457,7 @@ struct GrTextureDesc { * applies if the kRenderTarget_GrTextureFlagBit is set. The actual number * of samples may not exactly match the request. The request will be rounded * up to the next supported sample count, or down if it is larger than the - * max supportex count. + * max supported count. */ int fSampleCnt; }; |