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 | |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 11 | #include "GrExternalTextureData.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 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: |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 21 | void setFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 22 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags; |
| 23 | } |
| 24 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 25 | void resetFlag(GrSurfaceFlags flags) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 26 | fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags; |
| 27 | } |
| 28 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 29 | bool isSetFlag(GrSurfaceFlags flags) const { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 30 | return 0 != (fTexture->fDesc.fFlags & flags); |
| 31 | } |
| 32 | |
brianosman | fe19987 | 2016-06-13 07:59:48 -0700 | [diff] [blame] | 33 | void dirtyMipMaps(bool mipMapsDirty) { |
| 34 | fTexture->dirtyMipMaps(mipMapsDirty); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 35 | } |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 36 | |
| 37 | bool mipMapsAreDirty() const { |
| 38 | return GrTexture::kValid_MipMapsStatus != fTexture->fMipMapsStatus; |
| 39 | } |
| 40 | |
| 41 | bool hasMipMaps() const { |
| 42 | return GrTexture::kNotAllocated_MipMapsStatus != fTexture->fMipMapsStatus; |
| 43 | } |
| 44 | |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 45 | void setMaxMipMapLevel(int maxMipMapLevel) const { |
| 46 | fTexture->fMaxMipMapLevel = maxMipMapLevel; |
| 47 | } |
| 48 | |
| 49 | int maxMipMapLevel() const { |
| 50 | return fTexture->fMaxMipMapLevel; |
| 51 | } |
| 52 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 53 | GrSLType imageStorageType() const { |
| 54 | if (GrPixelConfigIsSint(fTexture->config())) { |
| 55 | return kIImageStorage2D_GrSLType; |
| 56 | } else { |
| 57 | return kImageStorage2D_GrSLType; |
| 58 | } |
| 59 | } |
| 60 | |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 61 | GrSLType samplerType() const { return fTexture->fSamplerType; } |
| 62 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 63 | /** The filter used is clamped to this value in GrProcessor::TextureSampler. */ |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 64 | GrSamplerParams::FilterMode highestFilterMode() const { return fTexture->fHighestFilterMode; } |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 65 | |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 66 | void setMipColorMode(SkDestinationSurfaceColorMode colorMode) const { |
| 67 | fTexture->fMipColorMode = colorMode; |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 68 | } |
Brian Osman | 7b8400d | 2016-11-08 17:08:54 -0500 | [diff] [blame] | 69 | SkDestinationSurfaceColorMode mipColorMode() const { return fTexture->fMipColorMode; } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 70 | |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 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 | */ |
| 76 | std::unique_ptr<GrExternalTextureData> detachBackendTexture() { |
| 77 | return fTexture->detachBackendTexture(); |
| 78 | } |
| 79 | |
bsalomon | 7775c85 | 2014-12-30 12:50:52 -0800 | [diff] [blame] | 80 | static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 81 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 82 | private: |
| 83 | GrTexturePriv(GrTexture* texture) : fTexture(texture) { } |
| 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; |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 92 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 93 | friend class GrTexture; // to construct/copy this type. |
| 94 | }; |
| 95 | |
| 96 | inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); } |
| 97 | |
| 98 | inline const GrTexturePriv GrTexture::texturePriv () const { |
| 99 | return GrTexturePriv(const_cast<GrTexture*>(this)); |
| 100 | } |
| 101 | |
| 102 | #endif |