blob: 4ce3e057ea639f7f24786e4e955e13944755eda1 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTexture.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040012#include "src/gpu/GrSamplerState.h"
bsalomonafbf2d62014-09-30 12:18:44 -070013
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:
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040021 void markMipMapsDirty() {
22 fTexture->markMipMapsDirty();
23 }
24
25 void markMipMapsClean() {
26 fTexture->markMipMapsClean();
brianosman33f6b3f2016-06-02 05:49:21 -070027 }
bsalomonafbf2d62014-09-30 12:18:44 -070028
Chris Dalton95d8ceb2019-07-30 11:17:59 -060029 GrMipMapsStatus mipMapsStatus() const { return fTexture->fMipMapsStatus; }
30
bsalomonafbf2d62014-09-30 12:18:44 -070031 bool mipMapsAreDirty() const {
Chris Dalton95d8ceb2019-07-30 11:17:59 -060032 return GrMipMapsStatus::kValid != this->mipMapsStatus();
bsalomonafbf2d62014-09-30 12:18:44 -070033 }
34
Greg Daniele252f082017-10-23 16:05:23 -040035 GrMipMapped mipMapped() const {
Chris Dalton95d8ceb2019-07-30 11:17:59 -060036 if (GrMipMapsStatus::kNotAllocated != this->mipMapsStatus()) {
Greg Daniele252f082017-10-23 16:05:23 -040037 return GrMipMapped::kYes;
38 }
39 return GrMipMapped::kNo;
Greg Daniel834f1202017-10-09 15:06:20 -040040 }
41
cblume55f2d2d2016-02-26 13:20:48 -080042 int maxMipMapLevel() const {
43 return fTexture->fMaxMipMapLevel;
44 }
45
Brian Salomon60dd8c72018-07-30 10:24:13 -040046 GrTextureType textureType() const { return fTexture->fTextureType; }
Brian Salomon7226c232018-07-30 13:13:17 -040047 bool hasRestrictedSampling() const {
48 return GrTextureTypeHasRestrictedSampling(this->textureType());
49 }
Brian Salomone632dfc2018-08-01 13:01:16 -040050 /** Filtering is clamped to this value. */
51 GrSamplerState::Filter highestFilterMode() const {
52 return this->hasRestrictedSampling() ? GrSamplerState::Filter::kBilerp
53 : GrSamplerState::Filter::kMipMap;
54 }
Brian Salomon739c5bf2016-11-07 09:53:44 -050055
Brian Salomon14cb4132019-09-16 13:14:47 -040056 static void ComputeScratchKey(GrPixelConfig config,
57 int width,
58 int height,
59 GrRenderable,
60 int sampleCnt,
61 GrMipMapped,
62 GrProtected,
63 GrScratchKey* key);
Brian Salomoncfe910d2017-07-06 16:40:18 -040064
65private:
bsalomonafbf2d62014-09-30 12:18:44 -070066 GrTexturePriv(GrTexture* texture) : fTexture(texture) { }
67 GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { }
68 GrTexturePriv& operator=(const GrTexturePriv&); // unimpl
69
70 // No taking addresses of this type.
71 const GrTexturePriv* operator&() const;
72 GrTexturePriv* operator&();
73
74 GrTexture* fTexture;
cblume61214052016-01-26 09:10:48 -080075
bsalomonafbf2d62014-09-30 12:18:44 -070076 friend class GrTexture; // to construct/copy this type.
77};
78
79inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); }
80
81inline const GrTexturePriv GrTexture::texturePriv () const {
82 return GrTexturePriv(const_cast<GrTexture*>(this));
83}
84
85#endif