Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GLBackendSurfaceTest.cpp
Go to the documentation of this file.
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
9
10#ifdef SK_GL
24#include "include/gpu/GrTypes.h"
36#include "tests/Test.h"
38struct GrContextOptions;
39
40static bool sampler_params_invalid(const GrGLTextureParameters& parameters) {
41 return SkIsNaN(parameters.samplerOverriddenState().fMaxLOD);
42}
43
44static bool nonsampler_params_invalid(const GrGLTextureParameters& parameters) {
47 invalidNSState.invalidate();
48 return nsState.fBaseMipMapLevel == invalidNSState.fBaseMipMapLevel &&
49 nsState.fMaxMipmapLevel == invalidNSState.fMaxMipmapLevel &&
50 nsState.fSwizzleIsRGBA == invalidNSState.fSwizzleIsRGBA;
51}
52
53static bool params_invalid(const GrGLTextureParameters& parameters) {
54 return sampler_params_invalid(parameters) && nonsampler_params_invalid(parameters);
55}
56
57static bool params_valid(const GrGLTextureParameters& parameters, const GrGLCaps* caps) {
58 if (nonsampler_params_invalid(parameters)) {
59 return false;
60 }
61 // We should only set the texture params that are equivalent to sampler param to valid if we're
62 // not using sampler objects.
63 return caps->useSamplerObjects() == sampler_params_invalid(parameters);
64}
65
66DEF_GANESH_TEST_FOR_GL_CONTEXT(GLTextureParameters,
68 ctxInfo,
70 auto dContext = ctxInfo.directContext();
71 auto caps = static_cast<const GrGLCaps*>(dContext->priv().caps());
72
73 GrBackendTexture backendTex = dContext->createBackendTexture(1,
74 1,
76 skgpu::Mipmapped::kNo,
77 GrRenderable::kNo,
78 GrProtected::kNo);
79 REPORTER_ASSERT(reporter, backendTex.isValid());
80
83
84 GrBackendTexture backendTexCopy = backendTex;
85 REPORTER_ASSERT(reporter, backendTexCopy.isSameTexture(backendTex));
86
87 sk_sp<SkImage> wrappedImage = SkImages::BorrowTextureFrom(dContext,
88 backendTex,
92 nullptr);
93 REPORTER_ASSERT(reporter, wrappedImage);
94
95 GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
98 auto texture = static_cast<GrGLTexture*>(proxy->peekTexture());
100 auto parameters = texture->parameters();
101 REPORTER_ASSERT(reporter, parameters);
103 invalidSState.invalidate();
105 invalidNSState.invalidate();
106
107 auto surf = SkSurfaces::RenderTarget(
108 dContext,
111 1,
112 nullptr);
114
115 // Test invalidating from the GL backend texture.
117 REPORTER_ASSERT(reporter, params_invalid(*parameters));
118
120 surf->getCanvas()->drawImage(wrappedImage, 0, 0);
121 dContext->flushAndSubmit(surf.get(), GrSyncCpu::kNo);
122 REPORTER_ASSERT(reporter, params_valid(*parameters, caps));
123
124 // Test invalidating from the copy.
126 REPORTER_ASSERT(reporter, params_invalid(*parameters));
127
128 // Check that we can do things like assigning the backend texture to invalid one, assign an
129 // invalid one, assign a backend texture to itself etc. Success here is that we don't hit any
130 // of our ref counting asserts.
131 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy));
132
133 GrBackendTexture invalidTexture;
134 REPORTER_ASSERT(reporter, !invalidTexture.isValid());
136 !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
137
138 backendTexCopy = invalidTexture;
139 REPORTER_ASSERT(reporter, !backendTexCopy.isValid());
141 !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
142
143 invalidTexture = backendTex;
144 REPORTER_ASSERT(reporter, invalidTexture.isValid());
145 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex));
146
147 invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
148 REPORTER_ASSERT(reporter, invalidTexture.isValid());
149 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
150
151 wrappedImage.reset();
152 dContext->flush();
153 dContext->submit(GrSyncCpu::kYes);
154 dContext->deleteBackendTexture(backendTex);
155}
156#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static bool SkIsNaN(T x)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_GL_CONTEXT(name, reporter, context_info, ctsEnforcement)
Definition Test.h:442
bool isSameTexture(const GrBackendTexture &)
bool useSamplerObjects() const
Definition GrGLCaps.h:499
const SamplerOverriddenState & samplerOverriddenState() const
const NonsamplerState & nonsamplerState() const
GrTexture * peekTexture() const
bool isInstantiated() const
T * get() const
Definition SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
FlTexture * texture
SK_API void GLTextureParametersModified(GrBackendTexture *)
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)