gfx/skia/trunk/src/gpu/gl/GrGLTexture.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLTexture.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/*
     1.5 + * Copyright 2011 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +
    1.12 +#ifndef GrGLTexture_DEFINED
    1.13 +#define GrGLTexture_DEFINED
    1.14 +
    1.15 +#include "GrGpu.h"
    1.16 +#include "GrGLRenderTarget.h"
    1.17 +
    1.18 +/**
    1.19 + * A ref counted tex id that deletes the texture in its destructor.
    1.20 + */
    1.21 +class GrGLTexID : public SkRefCnt {
    1.22 +public:
    1.23 +    SK_DECLARE_INST_COUNT(GrGLTexID)
    1.24 +
    1.25 +    GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped)
    1.26 +        : fGL(gl)
    1.27 +        , fTexID(texID)
    1.28 +        , fIsWrapped(isWrapped) {
    1.29 +    }
    1.30 +
    1.31 +    virtual ~GrGLTexID() {
    1.32 +        if (0 != fTexID && !fIsWrapped) {
    1.33 +            GR_GL_CALL(fGL, DeleteTextures(1, &fTexID));
    1.34 +        }
    1.35 +    }
    1.36 +
    1.37 +    void abandon() { fTexID = 0; }
    1.38 +    GrGLuint id() const { return fTexID; }
    1.39 +
    1.40 +private:
    1.41 +    const GrGLInterface* fGL;
    1.42 +    GrGLuint             fTexID;
    1.43 +    bool                 fIsWrapped;
    1.44 +
    1.45 +    typedef SkRefCnt INHERITED;
    1.46 +};
    1.47 +
    1.48 +////////////////////////////////////////////////////////////////////////////////
    1.49 +
    1.50 +
    1.51 +class GrGLTexture : public GrTexture {
    1.52 +
    1.53 +public:
    1.54 +    struct TexParams {
    1.55 +        GrGLenum fMinFilter;
    1.56 +        GrGLenum fMagFilter;
    1.57 +        GrGLenum fWrapS;
    1.58 +        GrGLenum fWrapT;
    1.59 +        GrGLenum fSwizzleRGBA[4];
    1.60 +        void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
    1.61 +    };
    1.62 +
    1.63 +    struct Desc : public GrTextureDesc {
    1.64 +        GrGLuint        fTextureID;
    1.65 +        bool            fIsWrapped;
    1.66 +    };
    1.67 +
    1.68 +    // creates a texture that is also an RT
    1.69 +    GrGLTexture(GrGpuGL* gpu,
    1.70 +                const Desc& textureDesc,
    1.71 +                const GrGLRenderTarget::Desc& rtDesc);
    1.72 +
    1.73 +    // creates a non-RT texture
    1.74 +    GrGLTexture(GrGpuGL* gpu,
    1.75 +                const Desc& textureDesc);
    1.76 +
    1.77 +    virtual ~GrGLTexture() { this->release(); }
    1.78 +
    1.79 +    virtual GrBackendObject getTextureHandle() const SK_OVERRIDE;
    1.80 +
    1.81 +    virtual void invalidateCachedState() SK_OVERRIDE { fTexParams.invalidate(); }
    1.82 +
    1.83 +    // These functions are used to track the texture parameters associated with the texture.
    1.84 +    const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
    1.85 +        *timestamp = fTexParamsTimestamp;
    1.86 +        return fTexParams;
    1.87 +    }
    1.88 +
    1.89 +    void setCachedTexParams(const TexParams& texParams,
    1.90 +                            GrGpu::ResetTimestamp timestamp) {
    1.91 +        fTexParams = texParams;
    1.92 +        fTexParamsTimestamp = timestamp;
    1.93 +    }
    1.94 +
    1.95 +    GrGLuint textureID() const { return (NULL != fTexIDObj.get()) ? fTexIDObj->id() : 0; }
    1.96 +
    1.97 +protected:
    1.98 +    // overrides of GrTexture
    1.99 +    virtual void onAbandon() SK_OVERRIDE;
   1.100 +    virtual void onRelease() SK_OVERRIDE;
   1.101 +
   1.102 +private:
   1.103 +    TexParams                       fTexParams;
   1.104 +    GrGpu::ResetTimestamp           fTexParamsTimestamp;
   1.105 +    SkAutoTUnref<GrGLTexID>         fTexIDObj;
   1.106 +
   1.107 +    void init(GrGpuGL* gpu,
   1.108 +              const Desc& textureDesc,
   1.109 +              const GrGLRenderTarget::Desc* rtDesc);
   1.110 +
   1.111 +    typedef GrTexture INHERITED;
   1.112 +};
   1.113 +
   1.114 +#endif

mercurial