1 /*
2  * Copyright 2014 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 #ifndef GrTexturePriv_DEFINED
9 #define GrTexturePriv_DEFINED
10 
11 #include "GrExternalTextureData.h"
12 #include "GrTexture.h"
13 
14 /** Class that adds methods to GrTexture that are only intended for use internal to Skia.
15     This class is purely a privileged window into GrTexture. It should never have additional data
16     members or virtual methods.
17     Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and
18     implemented privately in GrTexture with a inline public method here). */
19 class GrTexturePriv {
20 public:
setFlag(GrSurfaceFlags flags)21     void setFlag(GrSurfaceFlags flags) {
22         fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags;
23     }
24 
resetFlag(GrSurfaceFlags flags)25     void resetFlag(GrSurfaceFlags flags) {
26         fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags;
27     }
28 
isSetFlag(GrSurfaceFlags flags)29     bool isSetFlag(GrSurfaceFlags flags) const {
30         return 0 != (fTexture->fDesc.fFlags & flags);
31     }
32 
dirtyMipMaps(bool mipMapsDirty)33     void dirtyMipMaps(bool mipMapsDirty) {
34         fTexture->dirtyMipMaps(mipMapsDirty);
35     }
36 
mipMapsAreDirty()37     bool mipMapsAreDirty() const {
38         return GrTexture::kValid_MipMapsStatus != fTexture->fMipMapsStatus;
39     }
40 
hasMipMaps()41     bool hasMipMaps() const {
42         return GrTexture::kNotAllocated_MipMapsStatus != fTexture->fMipMapsStatus;
43     }
44 
setMaxMipMapLevel(int maxMipMapLevel)45     void setMaxMipMapLevel(int maxMipMapLevel) const {
46         fTexture->fMaxMipMapLevel = maxMipMapLevel;
47     }
48 
maxMipMapLevel()49     int maxMipMapLevel() const {
50         return fTexture->fMaxMipMapLevel;
51     }
52 
imageStorageType()53     GrSLType imageStorageType() const {
54         if (GrPixelConfigIsSint(fTexture->config())) {
55             return kIImageStorage2D_GrSLType;
56         } else {
57             return kImageStorage2D_GrSLType;
58         }
59     }
60 
samplerType()61     GrSLType samplerType() const { return fTexture->fSamplerType; }
62 
63     /** The filter used is clamped to this value in GrProcessor::TextureSampler. */
highestFilterMode()64     GrSamplerParams::FilterMode highestFilterMode() const { return fTexture->fHighestFilterMode; }
65 
setMipColorMode(SkDestinationSurfaceColorMode colorMode)66     void setMipColorMode(SkDestinationSurfaceColorMode colorMode) const {
67         fTexture->fMipColorMode = colorMode;
68     }
mipColorMode()69     SkDestinationSurfaceColorMode mipColorMode() const { return fTexture->fMipColorMode; }
70 
71     /**
72      *  Return the native bookkeeping data for this texture, and detach the backend object from
73      *  this GrTexture. It's lifetime will no longer be managed by Ganesh, and this GrTexture will
74      *  no longer refer to it. Leaves this GrTexture in an orphan state.
75      */
detachBackendTexture()76     std::unique_ptr<GrExternalTextureData> detachBackendTexture() {
77         return fTexture->detachBackendTexture();
78     }
79 
80     static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*);
81 
82 private:
GrTexturePriv(GrTexture * texture)83     GrTexturePriv(GrTexture* texture) : fTexture(texture) { }
GrTexturePriv(const GrTexturePriv & that)84     GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { }
85     GrTexturePriv& operator=(const GrTexturePriv&); // unimpl
86 
87     // No taking addresses of this type.
88     const GrTexturePriv* operator&() const;
89     GrTexturePriv* operator&();
90 
91     GrTexture* fTexture;
92 
93     friend class GrTexture; // to construct/copy this type.
94 };
95 
texturePriv()96 inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); }
97 
texturePriv()98 inline const GrTexturePriv GrTexture::texturePriv () const {
99     return GrTexturePriv(const_cast<GrTexture*>(this));
100 }
101 
102 #endif
103