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/SkScalar.h"
9 #include "include/private/GrGLTypesPriv.h"
10 #include "src/gpu/GrSwizzle.h"
11 #include "src/gpu/gl/GrGLDefines.h"
12
SamplerOverriddenState()13 GrGLTextureParameters::SamplerOverriddenState::SamplerOverriddenState()
14 // These are the OpenGL defaults.
15 : fMinFilter(GR_GL_NEAREST_MIPMAP_LINEAR)
16 , fMagFilter(GR_GL_LINEAR)
17 , fWrapS(GR_GL_REPEAT)
18 , fWrapT(GR_GL_REPEAT)
19 , fMinLOD(-1000.f)
20 , fMaxLOD(1000.f)
21 , fBorderColorInvalid(false) {}
22
invalidate()23 void GrGLTextureParameters::SamplerOverriddenState::invalidate() {
24 fMinFilter = ~0U;
25 fMagFilter = ~0U;
26 fWrapS = ~0U;
27 fWrapT = ~0U;
28 fMinLOD = SK_ScalarNaN;
29 fMaxLOD = SK_ScalarNaN;
30 fBorderColorInvalid = true;
31 }
32
NonsamplerState()33 GrGLTextureParameters::NonsamplerState::NonsamplerState()
34 // These are the OpenGL defaults.
35 : fBaseMipMapLevel(0), fMaxMipmapLevel(1000), fSwizzleIsRGBA(true) {}
36
invalidate()37 void GrGLTextureParameters::NonsamplerState::invalidate() {
38 fSwizzleIsRGBA = false;
39 fBaseMipMapLevel = ~0;
40 fMaxMipmapLevel = ~0;
41 }
42
invalidate()43 void GrGLTextureParameters::invalidate() {
44 fSamplerOverriddenState.invalidate();
45 fNonsamplerState.invalidate();
46 }
47
set(const SamplerOverriddenState * samplerState,const NonsamplerState & nonsamplerState,ResetTimestamp currTimestamp)48 void GrGLTextureParameters::set(const SamplerOverriddenState* samplerState,
49 const NonsamplerState& nonsamplerState,
50 ResetTimestamp currTimestamp) {
51 if (samplerState) {
52 fSamplerOverriddenState = *samplerState;
53 }
54 fNonsamplerState = nonsamplerState;
55 fResetTimestamp = currTimestamp;
56 }
57
assign(const GrGLBackendTextureInfo & that,bool thisIsValid)58 void GrGLBackendTextureInfo::assign(const GrGLBackendTextureInfo& that, bool thisIsValid) {
59 fInfo = that.fInfo;
60 SkSafeRef(that.fParams);
61 if (thisIsValid) {
62 SkSafeUnref(fParams);
63 }
64 fParams = that.fParams;
65 }
66
cleanup()67 void GrGLBackendTextureInfo::cleanup() { SkSafeUnref(fParams); }
68
GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec & glSpec,uint32_t sampleCount,uint32_t levelCount,GrProtected isProtected)69 GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec,
70 uint32_t sampleCount,
71 uint32_t levelCount,
72 GrProtected isProtected) {
73 GrGLSurfaceInfo info;
74 // Shared info
75 info.fSampleCount = sampleCount;
76 info.fLevelCount = levelCount;
77 info.fProtected = isProtected;
78
79 // GL info
80 info.fTarget = glSpec.fTarget;
81 info.fFormat = glSpec.fFormat;
82
83 return info;
84 }
85