• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,GrGLTextureParameters * params)79     GrGLBackendTextureInfo(const GrGLTextureInfo& info, GrGLTextureParameters* params)
80             : fInfo(info), fParams(params) {}
81     GrGLBackendTextureInfo(const GrGLBackendTextureInfo&) = delete;
82     GrGLBackendTextureInfo& operator=(const GrGLBackendTextureInfo&) = delete;
info()83     const GrGLTextureInfo& info() const { return fInfo; }
parameters()84     GrGLTextureParameters* parameters() const { return fParams; }
refParameters()85     sk_sp<GrGLTextureParameters> refParameters() const { return sk_ref_sp(fParams); }
86 
87     void cleanup();
88     void assign(const GrGLBackendTextureInfo&, bool thisIsValid);
89 
90 private:
91     GrGLTextureInfo fInfo;
92     GrGLTextureParameters* fParams;
93 };
94 
95 struct GrGLTextureSpec {
GrGLTextureSpecGrGLTextureSpec96     GrGLTextureSpec() : fTarget(0), fFormat(0) {}
GrGLTextureSpecGrGLTextureSpec97     GrGLTextureSpec(const GrGLSurfaceInfo& info) : fTarget(info.fTarget), fFormat(info.fFormat) {}
98 
99     GrGLenum fTarget;
100     GrGLenum fFormat;
101 };
102 
103 GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec,
104                                              uint32_t sampleCount,
105                                              uint32_t levelCount,
106                                              GrProtected isProtected);
107 
108 #endif
109