bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 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 "GrTexture.h" |
| 12 | |
| 13 | /** Class that adds methods to GrTexture that are only intended for use internal to Skia. |
| 14 | This class is purely a privileged window into GrTexture. It should never have additional data |
| 15 | members or virtual methods. |
| 16 | Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and |
| 17 | implemented privately in GrTexture with a inline public method here). */ |
| 18 | class GrTexturePriv { |
| 19 | public: |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 20 | void setFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 21 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags; |
| 22 | } |
| 23 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 24 | void resetFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 25 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags; |
| 26 | } |
| 27 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 28 | bool isSetFlag(GrSurfaceFlags flags) const { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 29 | return 0 != (fTexture->fDesc.fFlags & flags); |
| 30 | } |
| 31 | |
brianosman | fe19987 | 2016-06-13 07:59:48 -0700 | [diff] [blame] | 32 | void dirtyMipMaps(bool mipMapsDirty) { |
| 33 | fTexture->dirtyMipMaps(mipMapsDirty); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 34 | } |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 35 | |
| 36 | bool mipMapsAreDirty() const { |
| 37 | return GrTexture::kValid_MipMapsStatus != fTexture->fMipMapsStatus; |
| 38 | } |
| 39 | |
| 40 | bool hasMipMaps() const { |
| 41 | return GrTexture::kNotAllocated_MipMapsStatus != fTexture->fMipMapsStatus; |
| 42 | } |
| 43 | |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 44 | void setMaxMipMapLevel(int maxMipMapLevel) const { |
| 45 | fTexture->fMaxMipMapLevel = maxMipMapLevel; |
| 46 | } |
| 47 | |
| 48 | int maxMipMapLevel() const { |
| 49 | return fTexture->fMaxMipMapLevel; |
| 50 | } |
| 51 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 52 | GrSLType imageStorageType() const { |
| 53 | if (GrPixelConfigIsSint(fTexture->config())) { |
| 54 | return kIImageStorage2D_GrSLType; |
| 55 | } else { |
| 56 | return kImageStorage2D_GrSLType; |
| 57 | } |
| 58 | } |
| 59 | |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 60 | GrSLType samplerType() const { return fTexture->fSamplerType; } |
| 61 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 62 | /** The filter used is clamped to this value in GrProcessor::TextureSampler. */ |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 63 | GrSamplerParams::FilterMode highestFilterMode() const { return fTexture->fHighestFilterMode; } |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 64 | |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 65 | void setMipColorMode(SkDestinationSurfaceColorMode colorMode) const { |
| 66 | fTexture->fMipColorMode = colorMode; |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 67 | } |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 68 | SkDestinationSurfaceColorMode mipColorMode() const { return fTexture->fMipColorMode; } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 69 | |
bsalomon | 7775c85 | 2014-12-30 12:50:52 -0800 | [diff] [blame] | 70 | static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 71 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 72 | private: |
| 73 | GrTexturePriv(GrTexture* texture) : fTexture(texture) { } |
| 74 | GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { } |
| 75 | GrTexturePriv& operator=(const GrTexturePriv&); // unimpl |
| 76 | |
| 77 | // No taking addresses of this type. |
| 78 | const GrTexturePriv* operator&() const; |
| 79 | GrTexturePriv* operator&(); |
| 80 | |
| 81 | GrTexture* fTexture; |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 82 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 83 | friend class GrTexture; // to construct/copy this type. |
| 84 | }; |
| 85 | |
| 86 | inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); } |
| 87 | |
| 88 | inline const GrTexturePriv GrTexture::texturePriv () const { |
| 89 | return GrTexturePriv(const_cast<GrTexture*>(this)); |
| 90 | } |
| 91 | |
| 92 | #endif |