Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 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 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 8 | #include "include/core/SkScalar.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 9 | #include "include/private/GrGLTypesPriv.h" |
Brian Salomon | 3ec1f54 | 2019-06-17 17:54:57 +0000 | [diff] [blame] | 10 | #include "src/gpu/GrSwizzle.h" |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 11 | #include "src/gpu/gl/GrGLDefines.h" |
| 12 | |
| 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 | |
| 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 | |
| 33 | GrGLTextureParameters::NonsamplerState::NonsamplerState() |
| 34 | // These are the OpenGL defaults. |
Brian Salomon | 280fa3d | 2020-08-27 17:16:49 -0400 | [diff] [blame] | 35 | : fBaseMipMapLevel(0), fMaxMipmapLevel(1000), fSwizzleIsRGBA(true) {} |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 36 | |
| 37 | void GrGLTextureParameters::NonsamplerState::invalidate() { |
Brian Salomon | 280fa3d | 2020-08-27 17:16:49 -0400 | [diff] [blame] | 38 | fSwizzleIsRGBA = false; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 39 | fBaseMipMapLevel = ~0; |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 40 | fMaxMipmapLevel = ~0; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void GrGLTextureParameters::invalidate() { |
| 44 | fSamplerOverriddenState.invalidate(); |
| 45 | fNonsamplerState.invalidate(); |
| 46 | } |
| 47 | |
| 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 | |
| 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 | |
| 67 | void GrGLBackendTextureInfo::cleanup() { SkSafeUnref(fParams); } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 68 | |
| 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 | } |