skia2/tests/GLBackendSurfaceTest.cpp

132 lines
5.2 KiB
C++
Raw Normal View History

/*
* 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"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/gl/GrGLTypes.h"
#include "include/private/GrGLTypesPriv.h"
#include "src/gpu/GrDirectContextPriv.h"
Reland "Move GrGpuResource GrSurface and GrTexture into src." This reverts commit f6ed96d1c23b79130ca7344c984b07ef9d94fb7b. Reason for revert: google3 change landed Original change's description: > Revert "Move GrGpuResource GrSurface and GrTexture into src." > > This reverts commit e5a06ce678aad7640411f99f70f220f82ad49908. > > Reason for revert: Need to make change in google3 first > > Original change's description: > > Move GrGpuResource GrSurface and GrTexture into src. > > > > Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980 > > before this can land. > > > > Bug: skia:7966 > > Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:7966 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I746ce739cb084cefc46f9dab24ef773e7c3cc621 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7966 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275436 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 19:14:18 +00:00
#include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/gl/GrGLTexture.h"
#include "src/image/SkImage_Base.h"
#include "tools/gpu/ProxyUtils.h"
static bool sampler_params_invalid(const GrGLTextureParameters& parameters) {
return SkScalarIsNaN(parameters.samplerOverriddenState().fMaxLOD);
}
static bool nonsampler_params_invalid(const GrGLTextureParameters& parameters) {
GrGLTextureParameters::NonsamplerState nsState = parameters.nonsamplerState();
GrGLTextureParameters::NonsamplerState invalidNSState;
invalidNSState.invalidate();
return nsState.fBaseMipMapLevel == invalidNSState.fBaseMipMapLevel &&
nsState.fMaxMipmapLevel == invalidNSState.fMaxMipmapLevel &&
nsState.fSwizzleIsRGBA == invalidNSState.fSwizzleIsRGBA;
}
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;
}
// 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);
}
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
auto dContext = ctxInfo.directContext();
auto caps = static_cast<const GrGLCaps*>(dContext->priv().caps());
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
GrBackendTexture backendTex = dContext->createBackendTexture(
1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
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 =
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, wrappedImage);
GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
REPORTER_ASSERT(reporter, proxy);
REPORTER_ASSERT(reporter, proxy->isInstantiated());
auto texture = static_cast<GrGLTexture*>(proxy->peekTexture());
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(
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
dContext, SkBudgeted::kYes,
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);
surf->flushAndSubmit();
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
// invalid one, assign a backend texture to itself etc. Success here is that we don't hit any
// of our ref counting asserts.
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();
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
dContext->flush();
dContext->submit(true);
dContext->deleteBackendTexture(backendTex);
}
#endif