1 /* 2 * Copyright 2019 Google LLC 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 #include "include/core/SkRefCnt.h" 9 #include "include/gpu/gl/GrGLTypes.h" 10 11 #ifndef GrGLTypesPriv_DEFINED 12 #define GrGLTypesPriv_DEFINED 13 14 static constexpr int kGrGLColorFormatCount = static_cast<int>(GrGLFormat::kLastColorFormat) + 1; 15 16 class GrGLTextureParameters : public SkNVRefCnt<GrGLTextureParameters> { 17 public: 18 // We currently consider texture parameters invalid on all textures 19 // GrContext::resetContext(). We use this type to track whether instances of 20 // GrGLTextureParameters were updated before or after the most recent resetContext(). At 10 21 // resets / frame and 60fps a 64bit timestamp will overflow in about a billion years. 22 // TODO: Require clients to use GrBackendTexture::glTextureParametersModified() to invalidate 23 // texture parameters and get rid of timestamp checking. 24 using ResetTimestamp = uint64_t; 25 26 // This initializes the params to have an expired timestamp. They'll be considered invalid the 27 // first time the texture is used unless set() is called. 28 GrGLTextureParameters() = default; 29 30 // This is texture parameter state that is overridden when a non-zero sampler object is bound. 31 struct SamplerOverriddenState { 32 SamplerOverriddenState(); 33 void invalidate(); 34 35 GrGLenum fMinFilter; 36 GrGLenum fMagFilter; 37 GrGLenum fWrapS; 38 GrGLenum fWrapT; 39 GrGLfloat fMinLOD; 40 GrGLfloat fMaxLOD; 41 GrGLfloat fMaxAniso; 42 // We always want the border color to be transparent black, so no need to store 4 floats. 43 // Just track if it's been invalidated and no longer the default 44 bool fBorderColorInvalid; 45 }; 46 47 // Texture parameter state that is not overridden by a bound sampler object. 48 struct NonsamplerState { 49 NonsamplerState(); 50 void invalidate(); 51 52 GrGLint fBaseMipMapLevel; 53 GrGLint fMaxMipmapLevel; 54 bool fSwizzleIsRGBA; 55 }; 56 57 void invalidate(); 58 resetTimestamp()59 ResetTimestamp resetTimestamp() const { return fResetTimestamp; } samplerOverriddenState()60 const SamplerOverriddenState& samplerOverriddenState() const { return fSamplerOverriddenState; } nonsamplerState()61 const NonsamplerState& nonsamplerState() const { return fNonsamplerState; } 62 63 // SamplerOverriddenState is optional because we don't track it when we're using sampler 64 // objects. 65 void set(const SamplerOverriddenState* samplerState, 66 const NonsamplerState& nonsamplerState, 67 ResetTimestamp currTimestamp); 68 69 private: 70 static constexpr ResetTimestamp kExpiredTimestamp = 0; 71 72 SamplerOverriddenState fSamplerOverriddenState; 73 NonsamplerState fNonsamplerState; 74 ResetTimestamp fResetTimestamp = kExpiredTimestamp; 75 }; 76 77 class GrGLBackendTextureInfo { 78 public: GrGLBackendTextureInfo(const GrGLTextureInfo & info,sk_sp<GrGLTextureParameters> params)79 GrGLBackendTextureInfo(const GrGLTextureInfo& info, sk_sp<GrGLTextureParameters> params) 80 : fInfo(info), fParams(std::move(params)) {} info()81 const GrGLTextureInfo& info() const { return fInfo; } parameters()82 GrGLTextureParameters* parameters() const { return fParams.get(); } refParameters()83 sk_sp<GrGLTextureParameters> refParameters() const { return fParams; } 84 isProtected()85 bool isProtected() const { return fInfo.isProtected(); } 86 87 private: 88 GrGLTextureInfo fInfo; 89 sk_sp<GrGLTextureParameters> fParams; // not const because we might call invalidate() on it. 90 }; 91 92 struct GrGLTextureSpec { GrGLTextureSpecGrGLTextureSpec93 GrGLTextureSpec() : fTarget(0), fFormat(0) {} GrGLTextureSpecGrGLTextureSpec94 GrGLTextureSpec(const GrGLSurfaceInfo& info) : fTarget(info.fTarget), fFormat(info.fFormat) {} 95 96 GrGLenum fTarget; 97 GrGLenum fFormat; 98 }; 99 100 GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec, 101 uint32_t sampleCount, 102 uint32_t levelCount, 103 skgpu::Protected isProtected); 104 105 #endif 106