2019-06-04 19:58:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
|
|
|
|
#ifdef SK_GL
|
|
|
|
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-06-04 19:58:31 +00:00
|
|
|
#include "include/gpu/gl/GrGLTypes.h"
|
|
|
|
#include "include/private/GrGLTypesPriv.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-06-04 19:58:31 +00:00
|
|
|
#include "src/gpu/gl/GrGLCaps.h"
|
|
|
|
#include "src/gpu/gl/GrGLTexture.h"
|
|
|
|
#include "src/image/SkImage_Base.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2019-06-04 19:58:31 +00:00
|
|
|
|
|
|
|
static bool sampler_params_invalid(const GrGLTextureParameters& parameters) {
|
|
|
|
return SkScalarIsNaN(parameters.samplerOverriddenState().fMaxLOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool nonsampler_params_invalid(const GrGLTextureParameters& parameters) {
|
2020-08-27 21:16:49 +00:00
|
|
|
GrGLTextureParameters::NonsamplerState nsState = parameters.nonsamplerState();
|
2019-06-04 19:58:31 +00:00
|
|
|
GrGLTextureParameters::NonsamplerState invalidNSState;
|
|
|
|
invalidNSState.invalidate();
|
2020-08-27 21:16:49 +00:00
|
|
|
return nsState.fBaseMipMapLevel == invalidNSState.fBaseMipMapLevel &&
|
|
|
|
nsState.fMaxMipmapLevel == invalidNSState.fMaxMipmapLevel &&
|
|
|
|
nsState.fSwizzleIsRGBA == invalidNSState.fSwizzleIsRGBA;
|
2019-06-04 19:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool params_invalid(const GrGLTextureParameters& parameters) {
|
|
|
|
return sampler_params_invalid(parameters) && nonsampler_params_invalid(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool params_valid(const GrGLTextureParameters& parameters, const GrGLCaps* caps) {
|
|
|
|
if (nonsampler_params_invalid(parameters)) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-01 16:42:26 +00:00
|
|
|
// We should only set the texture params that are equivalent to sampler param to valid if we're
|
|
|
|
// not using sampler objects.
|
|
|
|
return caps->useSamplerObjects() == sampler_params_invalid(parameters);
|
2019-06-04 19:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2020-08-17 15:27:40 +00:00
|
|
|
auto caps = static_cast<const GrGLCaps*>(dContext->priv().caps());
|
2019-06-04 19:58:31 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
GrBackendTexture backendTex = dContext->createBackendTexture(
|
2020-07-21 13:27:25 +00:00
|
|
|
1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
|
2019-06-04 19:58:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
|
|
|
|
|
|
|
GrGLTextureInfo info;
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getGLTextureInfo(&info));
|
|
|
|
|
|
|
|
GrBackendTexture backendTexCopy = backendTex;
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.isSameTexture(backendTex));
|
|
|
|
|
|
|
|
sk_sp<SkImage> wrappedImage =
|
2020-08-11 15:48:49 +00:00
|
|
|
SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
|
2019-06-04 19:58:31 +00:00
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, wrappedImage);
|
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
|
2021-02-03 15:15:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
|
|
|
auto texture = static_cast<GrGLTexture*>(proxy->peekTexture());
|
2019-06-04 19:58:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
auto parameters = texture->parameters();
|
|
|
|
REPORTER_ASSERT(reporter, parameters);
|
|
|
|
GrGLTextureParameters::SamplerOverriddenState invalidSState;
|
|
|
|
invalidSState.invalidate();
|
|
|
|
GrGLTextureParameters::NonsamplerState invalidNSState;
|
|
|
|
invalidNSState.invalidate();
|
|
|
|
|
|
|
|
auto surf = SkSurface::MakeRenderTarget(
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext, SkBudgeted::kYes,
|
2019-06-04 19:58:31 +00:00
|
|
|
SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, surf);
|
|
|
|
|
|
|
|
// Test invalidating from the GL backend texture.
|
|
|
|
backendTex.glTextureParametersModified();
|
|
|
|
REPORTER_ASSERT(reporter, params_invalid(*parameters));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, surf);
|
|
|
|
surf->getCanvas()->drawImage(wrappedImage, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surf->flushAndSubmit();
|
2019-06-04 19:58:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, params_valid(*parameters, caps));
|
|
|
|
|
|
|
|
// Test invalidating from the copy.
|
|
|
|
backendTexCopy.glTextureParametersModified();
|
|
|
|
REPORTER_ASSERT(reporter, params_invalid(*parameters));
|
|
|
|
|
|
|
|
// Check that we can do things like assigning the backend texture to invalid one, assign an
|
2020-08-17 15:27:40 +00:00
|
|
|
// invalid one, assign a backend texture to itself etc. Success here is that we don't hit any
|
|
|
|
// of our ref counting asserts.
|
2019-06-04 19:58:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy));
|
|
|
|
|
|
|
|
GrBackendTexture invalidTexture;
|
|
|
|
REPORTER_ASSERT(reporter, !invalidTexture.isValid());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
!GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
|
|
|
|
|
|
|
|
backendTexCopy = invalidTexture;
|
|
|
|
REPORTER_ASSERT(reporter, !backendTexCopy.isValid());
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
!GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
|
|
|
|
|
|
|
|
invalidTexture = backendTex;
|
|
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex));
|
|
|
|
|
|
|
|
invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
|
|
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
|
|
|
|
|
|
|
|
wrappedImage.reset();
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
dContext->deleteBackendTexture(backendTex);
|
2019-06-04 19:58:31 +00:00
|
|
|
}
|
|
|
|
#endif
|