blob: cc0a05edfd889bea8ccb65126c387eff42514db8 [file] [log] [blame]
bsalomonafbf2d62014-09-30 12:18:44 -07001/*
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 Osman2c2bc112017-02-28 10:02:49 -050011#include "GrExternalTextureData.h"
bsalomonafbf2d62014-09-30 12:18:44 -070012#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). */
19class GrTexturePriv {
20public:
bsalomonf2703d82014-10-28 14:33:06 -070021 void setFlag(GrSurfaceFlags flags) {
bsalomonafbf2d62014-09-30 12:18:44 -070022 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags;
23 }
24
bsalomonf2703d82014-10-28 14:33:06 -070025 void resetFlag(GrSurfaceFlags flags) {
bsalomonafbf2d62014-09-30 12:18:44 -070026 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags;
27 }
28
bsalomonf2703d82014-10-28 14:33:06 -070029 bool isSetFlag(GrSurfaceFlags flags) const {
bsalomonafbf2d62014-09-30 12:18:44 -070030 return 0 != (fTexture->fDesc.fFlags & flags);
31 }
32
brianosmanfe199872016-06-13 07:59:48 -070033 void dirtyMipMaps(bool mipMapsDirty) {
34 fTexture->dirtyMipMaps(mipMapsDirty);
brianosman33f6b3f2016-06-02 05:49:21 -070035 }
bsalomonafbf2d62014-09-30 12:18:44 -070036
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
cblume55f2d2d2016-02-26 13:20:48 -080045 void setMaxMipMapLevel(int maxMipMapLevel) const {
46 fTexture->fMaxMipMapLevel = maxMipMapLevel;
47 }
48
49 int maxMipMapLevel() const {
50 return fTexture->fMaxMipMapLevel;
51 }
52
Brian Salomonf9f45122016-11-29 11:59:17 -050053 GrSLType imageStorageType() const {
54 if (GrPixelConfigIsSint(fTexture->config())) {
55 return kIImageStorage2D_GrSLType;
56 } else {
57 return kImageStorage2D_GrSLType;
58 }
59 }
60
Brian Salomon739c5bf2016-11-07 09:53:44 -050061 GrSLType samplerType() const { return fTexture->fSamplerType; }
62
Brian Salomon0bbecb22016-11-17 11:38:22 -050063 /** The filter used is clamped to this value in GrProcessor::TextureSampler. */
Brian Salomon514baff2016-11-17 15:17:07 -050064 GrSamplerParams::FilterMode highestFilterMode() const { return fTexture->fHighestFilterMode; }
Brian Salomon739c5bf2016-11-07 09:53:44 -050065
Brian Osman7b8400d2016-11-08 17:08:54 -050066 void setMipColorMode(SkDestinationSurfaceColorMode colorMode) const {
67 fTexture->fMipColorMode = colorMode;
brianosman33f6b3f2016-06-02 05:49:21 -070068 }
Brian Osman7b8400d2016-11-08 17:08:54 -050069 SkDestinationSurfaceColorMode mipColorMode() const { return fTexture->fMipColorMode; }
brianosman33f6b3f2016-06-02 05:49:21 -070070
Brian Osman2c2bc112017-02-28 10:02:49 -050071 /**
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
bsalomon7775c852014-12-30 12:50:52 -080080 static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*);
bsalomonafbf2d62014-09-30 12:18:44 -070081
bsalomonafbf2d62014-09-30 12:18:44 -070082private:
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;
cblume61214052016-01-26 09:10:48 -080092
bsalomonafbf2d62014-09-30 12:18:44 -070093 friend class GrTexture; // to construct/copy this type.
94};
95
96inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); }
97
98inline const GrTexturePriv GrTexture::texturePriv () const {
99 return GrTexturePriv(const_cast<GrTexture*>(this));
100}
101
102#endif