Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 
      9 #ifndef GrGLTexture_DEFINED
     10 #define GrGLTexture_DEFINED
     11 
     12 #include "GrGpu.h"
     13 #include "GrTexture.h"
     14 #include "GrGLUtil.h"
     15 
     16 class GrGLGpu;
     17 
     18 class GrGLTexture : public GrTexture {
     19 public:
     20     struct TexParams {
     21         GrGLenum fMinFilter;
     22         GrGLenum fMagFilter;
     23         GrGLenum fWrapS;
     24         GrGLenum fWrapT;
     25         GrGLenum fMaxMipMapLevel;
     26         GrGLenum fSwizzleRGBA[4];
     27         GrGLenum fSRGBDecode;
     28         void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
     29     };
     30 
     31     struct IDDesc {
     32         GrGLTextureInfo             fInfo;
     33         GrBackendObjectOwnership    fOwnership;
     34     };
     35     GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
     36 
     37     ~GrGLTexture() override {
     38         // check that invokeReleaseProc has been called (if needed)
     39         SkASSERT(!fReleaseHelper);
     40     }
     41 
     42     GrBackendObject getTextureHandle() const override;
     43     GrBackendTexture getBackendTexture() const override;
     44 
     45     void textureParamsModified() override { fTexParams.invalidate(); }
     46 
     47     void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
     48         fReleaseHelper = std::move(releaseHelper);
     49     }
     50 
     51     // These functions are used to track the texture parameters associated with the texture.
     52     const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
     53         *timestamp = fTexParamsTimestamp;
     54         return fTexParams;
     55     }
     56 
     57     void setCachedTexParams(const TexParams& texParams,
     58                             GrGpu::ResetTimestamp timestamp) {
     59         fTexParams = texParams;
     60         fTexParamsTimestamp = timestamp;
     61     }
     62 
     63     GrGLuint textureID() const { return fInfo.fID; }
     64 
     65     GrGLenum target() const { return fInfo.fTarget; }
     66 
     67     bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
     68     void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
     69 
     70     static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus,
     71                                           const IDDesc&);
     72 
     73     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
     74 
     75 protected:
     76     // Constructor for subclasses.
     77     GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus);
     78 
     79     enum Wrapped { kWrapped };
     80     // Constructor for instances wrapping backend objects.
     81     GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&);
     82 
     83     void init(const GrSurfaceDesc&, const IDDesc&);
     84 
     85     void onAbandon() override;
     86     void onRelease() override;
     87 
     88     bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override;
     89 
     90 private:
     91     void invokeReleaseProc() {
     92         if (fReleaseHelper) {
     93             // Depending on the ref count of fReleaseHelper this may or may not actually trigger the
     94             // ReleaseProc to be called.
     95             fReleaseHelper.reset();
     96         }
     97     }
     98 
     99     TexParams                       fTexParams;
    100     GrGpu::ResetTimestamp           fTexParamsTimestamp;
    101     // Holds the texture target and ID. A pointer to this may be shared to external clients for
    102     // direct interaction with the GL object.
    103     GrGLTextureInfo                 fInfo;
    104     GrBackendObjectOwnership        fTextureIDOwnership;
    105     bool                            fBaseLevelHasBeenBoundToFBO = false;
    106 
    107     sk_sp<GrReleaseProcHelper>      fReleaseHelper;
    108 
    109     typedef GrTexture INHERITED;
    110 };
    111 
    112 #endif
    113