blob: 3034ddbb396910d645fc1e00d588275bd7584ea0 [file] [log] [blame]
Brian Salomone2826ab2019-06-04 15:58:31 -04001/*
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
Brian Salomone2826ab2019-06-04 15:58:31 -04008#include "include/core/SkScalar.h"
Mike Klein4b432fa2019-06-06 11:44:05 -05009#include "include/private/GrGLTypesPriv.h"
Brian Salomon3ec1f542019-06-17 17:54:57 +000010#include "src/gpu/GrSwizzle.h"
Brian Salomone2826ab2019-06-04 15:58:31 -040011#include "src/gpu/gl/GrGLDefines.h"
12
13GrGLTextureParameters::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
23void 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
33GrGLTextureParameters::NonsamplerState::NonsamplerState()
34 // These are the OpenGL defaults.
Brian Salomon280fa3d2020-08-27 17:16:49 -040035 : fBaseMipMapLevel(0), fMaxMipmapLevel(1000), fSwizzleIsRGBA(true) {}
Brian Salomone2826ab2019-06-04 15:58:31 -040036
37void GrGLTextureParameters::NonsamplerState::invalidate() {
Brian Salomon280fa3d2020-08-27 17:16:49 -040038 fSwizzleIsRGBA = false;
Brian Salomone2826ab2019-06-04 15:58:31 -040039 fBaseMipMapLevel = ~0;
Brian Salomon8c82a872020-07-21 12:09:58 -040040 fMaxMipmapLevel = ~0;
Brian Salomone2826ab2019-06-04 15:58:31 -040041}
42
43void GrGLTextureParameters::invalidate() {
44 fSamplerOverriddenState.invalidate();
45 fNonsamplerState.invalidate();
46}
47
48void 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
58void 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
67void GrGLBackendTextureInfo::cleanup() { SkSafeUnref(fParams); }
Greg Daniel84261652021-09-19 17:53:40 -040068
69GrGLSurfaceInfo 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}