diff options
author | bsalomon <bsalomon@google.com> | 2014-11-03 08:47:23 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-03 08:47:23 -0800 |
commit | 37dd331b20a92ce79cc26556e065dec98a66cb0b (patch) | |
tree | cac1c6927c1f8f9860890e37b9d08cca01de251b /include | |
parent | 89a9ecef9ead1f6093e796173b28b82dca4adcbd (diff) |
Add class GrGLTextureRenderTarget for GL texture/rendertarget objects
BUG=skia:2889
Review URL: https://codereview.chromium.org/695813003
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrGpuResource.h | 6 | ||||
-rw-r--r-- | include/gpu/GrGpuResourceRef.h | 47 | ||||
-rw-r--r-- | include/gpu/GrRenderTarget.h | 33 | ||||
-rw-r--r-- | include/gpu/GrSurface.h | 12 | ||||
-rw-r--r-- | include/gpu/GrTexture.h | 15 |
5 files changed, 58 insertions, 55 deletions
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 9b298dd2a6..4ffe17e739 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -13,10 +13,10 @@ #include "SkInstCnt.h" #include "SkTInternalLList.h" -class GrResourceCacheEntry; -class GrResourceCache2; -class GrGpu; class GrContext; +class GrGpu; +class GrResourceCache2; +class GrResourceCacheEntry; /** * Base class for GrGpuResource. Handles the various types of refs we need. Separated out as a base diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h index 0223f18977..93298f0656 100644 --- a/include/gpu/GrGpuResourceRef.h +++ b/include/gpu/GrGpuResourceRef.h @@ -9,6 +9,8 @@ #define GrGpuResourceRef_DEFINED #include "GrGpuResource.h" +#include "GrRenderTarget.h" +#include "GrTexture.h" #include "SkRefCnt.h" /** @@ -96,7 +98,7 @@ public: /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as pending on the resource when markPendingIO is called. */ - GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType) {} + GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType) { } T* get() const { return static_cast<T*>(this->getResource()); } @@ -108,6 +110,49 @@ private: typedef GrGpuResourceRef INHERITED; }; +// Specializations for GrTexture and GrRenderTarget because they use virtual inheritance. +template<> class GrTGpuResourceRef<GrTexture> : public GrGpuResourceRef { +public: + GrTGpuResourceRef() {} + + GrTGpuResourceRef(GrTexture* texture, GrIOType ioType) : INHERITED(texture, ioType) { } + + GrTexture* get() const { + GrSurface* surface = static_cast<GrSurface*>(this->getResource()); + if (surface) { + return surface->asTexture(); + } else { + return NULL; + } + } + + void set(GrTexture* texture, GrIOType ioType) { this->setResource(texture, ioType); } + +private: + typedef GrGpuResourceRef INHERITED; +}; + +template<> class GrTGpuResourceRef<GrRenderTarget> : public GrGpuResourceRef { +public: + GrTGpuResourceRef() {} + + GrTGpuResourceRef(GrRenderTarget* rt, GrIOType ioType) : INHERITED(rt, ioType) { } + + GrRenderTarget* get() const { + GrSurface* surface = static_cast<GrSurface*>(this->getResource()); + if (surface) { + return surface->asRenderTarget(); + } else { + return NULL; + } + } + + void set(GrRenderTarget* rt, GrIOType ioType) { this->setResource(rt, ioType); } + +private: + typedef GrGpuResourceRef INHERITED; +}; + /** * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a * ref. diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h index b8e30d905c..e0f11999f4 100644 --- a/include/gpu/GrRenderTarget.h +++ b/include/gpu/GrRenderTarget.h @@ -12,36 +12,21 @@ #include "SkRect.h" class GrStencilBuffer; -class GrTexture; /** * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. * A context's render target is set by setRenderTarget(). Render targets are - * created by a createTexture with the kRenderTarget_TextureFlag flag. + * created by a createTexture with the kRenderTarget_SurfaceFlag flag. * Additionally, GrContext provides methods for creating GrRenderTargets * that wrap externally created render targets. */ -class GrRenderTarget : public GrSurface { +class GrRenderTarget : virtual public GrSurface { public: SK_DECLARE_INST_COUNT(GrRenderTarget) - // GrResource overrides - virtual size_t gpuMemorySize() const SK_OVERRIDE; - // GrSurface overrides - /** - * @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; } - - /** - * @return this render target. - */ virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; } - virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { - return this; - } + virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return this; } // GrRenderTarget /** @@ -134,11 +119,9 @@ public: protected: GrRenderTarget(GrGpu* gpu, bool isWrapped, - GrTexture* texture, const GrSurfaceDesc& desc) : INHERITED(gpu, isWrapped, desc) - , fStencilBuffer(NULL) - , fTexture(texture) { + , fStencilBuffer(NULL) { fResolveRect.setLargestInverted(); } @@ -147,15 +130,7 @@ protected: virtual void onRelease() SK_OVERRIDE; private: - friend class GrTexture; - // called by ~GrTexture to remove the non-ref'ed back ptr. - void owningTextureDestroyed() { - SkASSERT(fTexture); - fTexture = NULL; - } - GrStencilBuffer* fStencilBuffer; - GrTexture* fTexture; // not ref'ed SkIRect fResolveRect; diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h index 9a76d3ab4f..9d891493b0 100644 --- a/include/gpu/GrSurface.h +++ b/include/gpu/GrSurface.h @@ -24,15 +24,11 @@ public: /** * Retrieves the width of the surface. - * - * @return the width in texels */ int width() const { return fDesc.fWidth; } /** * Retrieves the height of the surface. - * - * @return the height in texels */ int height() const { return fDesc.fHeight; } @@ -63,14 +59,14 @@ public: /** * @return the texture associated with the surface, may be NULL. */ - virtual GrTexture* asTexture() = 0; - virtual const GrTexture* asTexture() const = 0; + virtual GrTexture* asTexture() { return NULL; } + virtual const GrTexture* asTexture() const { return NULL; } /** * @return the render target underlying this surface, may be NULL. */ - virtual GrRenderTarget* asRenderTarget() = 0; - virtual const GrRenderTarget* asRenderTarget() const = 0; + virtual GrRenderTarget* asRenderTarget() { return NULL; } + virtual const GrRenderTarget* asRenderTarget() const { return NULL; } /** * Reads a rectangle of pixels from the surface. diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h index 13d5667811..87f0d5ab0a 100644 --- a/include/gpu/GrTexture.h +++ b/include/gpu/GrTexture.h @@ -10,7 +10,6 @@ #define GrTexture_DEFINED #include "GrSurface.h" -#include "GrRenderTarget.h" #include "SkPoint.h" #include "SkRefCnt.h" @@ -18,7 +17,7 @@ class GrResourceKey; class GrTextureParams; class GrTexturePriv; -class GrTexture : public GrSurface { +class GrTexture : virtual public GrSurface { public: /** * Approximate number of bytes used by the texture @@ -27,8 +26,6 @@ public: virtual GrTexture* asTexture() SK_OVERRIDE { return this; } virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; } - virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return fRenderTarget.get(); } - virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return fRenderTarget.get(); } /** * Return the native ID or handle to the texture, depending on the @@ -54,18 +51,8 @@ public: inline const GrTexturePriv texturePriv() const; protected: - // A texture refs its rt representation but not vice-versa. It is up to - // the subclass constructor to initialize this pointer. - SkAutoTUnref<GrRenderTarget> fRenderTarget; - GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc); - virtual ~GrTexture(); - - // GrResource overrides - virtual void onRelease() SK_OVERRIDE; - virtual void onAbandon() SK_OVERRIDE; - void validateDesc() const; private: |