2017-10-12 16:27:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2017-10-12 16:27:11 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2021-05-07 20:25:49 +00:00
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
#include "include/gpu/d3d/GrD3DTypes.h"
|
|
|
|
#endif
|
2021-07-06 16:21:37 +00:00
|
|
|
#include "src/gpu/BaseDevice.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrBackendTextureImageGenerator.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-08-14 15:24:37 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2020-01-21 19:29:57 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrSemaphore.h"
|
|
|
|
#include "src/gpu/GrSurfaceProxyPriv.h"
|
2020-07-23 14:33:24 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
|
|
|
#include "src/image/SkSurface_Gpu.h"
|
|
|
|
#include "tests/Test.h"
|
2020-05-06 15:40:03 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/BackendSurfaceFactory.h"
|
|
|
|
#include "tools/gpu/BackendTextureImageFactory.h"
|
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2017-10-12 16:27:11 +00:00
|
|
|
|
2017-10-30 17:41:26 +00:00
|
|
|
static constexpr int kSize = 8;
|
|
|
|
|
2017-10-12 16:27:11 +00:00
|
|
|
// Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in
|
|
|
|
// SkImages and SkSurfaces
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext->priv().caps()->mipmapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
|
2021-01-26 22:46:50 +00:00
|
|
|
for (auto mipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
2019-05-13 14:40:06 +00:00
|
|
|
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
|
2019-05-17 14:01:21 +00:00
|
|
|
// createBackendTexture currently doesn't support uploading data to mip maps
|
2017-10-12 16:27:11 +00:00
|
|
|
// so we don't send any. However, we pretend there is data for the checks below which is
|
|
|
|
// fine since we are never actually using these textures for any work on the gpu.
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
kSize,
|
|
|
|
kSize,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent,
|
2021-01-26 22:46:50 +00:00
|
|
|
mipmapped,
|
2020-10-13 00:45:06 +00:00
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2020-11-05 16:11:20 +00:00
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not make texture.");
|
|
|
|
return;
|
|
|
|
}
|
2017-10-12 16:27:11 +00:00
|
|
|
|
2017-11-13 17:47:24 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2017-10-12 16:27:11 +00:00
|
|
|
sk_sp<SkImage> image;
|
2021-01-26 22:46:50 +00:00
|
|
|
if (renderable == GrRenderable::kYes) {
|
2017-10-12 16:27:11 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
|
2020-10-13 00:45:06 +00:00
|
|
|
dContext,
|
|
|
|
mbet->texture(),
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
0,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
/*color space*/ nullptr,
|
|
|
|
/*surface props*/ nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2017-10-12 16:27:11 +00:00
|
|
|
|
2021-07-06 16:21:37 +00:00
|
|
|
auto device = ((SkSurface_Gpu*)surface.get())->getDevice();
|
2021-05-24 19:35:08 +00:00
|
|
|
proxy = device->readSurfaceView().asTextureProxyRef();
|
2017-10-12 16:27:11 +00:00
|
|
|
} else {
|
2020-10-13 00:45:06 +00:00
|
|
|
image = SkImage::MakeFromTexture(dContext,
|
|
|
|
mbet->texture(),
|
2017-10-12 16:27:11 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin,
|
2017-12-18 19:48:15 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
2020-10-13 00:45:06 +00:00
|
|
|
kPremul_SkAlphaType,
|
|
|
|
/* color space */ nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, (mipmapped == GrMipmapped::kYes) == image->hasMipmaps());
|
2021-02-23 15:45:39 +00:00
|
|
|
proxy = sk_ref_sp(sk_gpu_test::GetTextureImageProxy(image.get(), dContext));
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
if (!proxy) {
|
2020-10-13 00:45:06 +00:00
|
|
|
continue;
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
2017-10-12 16:27:11 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
GrTexture* texture = proxy->peekTexture();
|
2017-10-12 16:27:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
if (!texture) {
|
2020-10-13 00:45:06 +00:00
|
|
|
continue;
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 22:46:50 +00:00
|
|
|
if (mipmapped == GrMipmapped::kYes) {
|
2020-07-23 14:33:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrMipmapped::kYes == texture->mipmapped());
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2020-07-23 14:33:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture->mipmapsAreDirty());
|
2017-10-12 16:27:11 +00:00
|
|
|
} else {
|
2020-07-23 14:33:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, !texture->mipmapsAreDirty());
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-23 14:33:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped());
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:37:36 +00:00
|
|
|
// Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator
|
|
|
|
// based on if we will use mips in the draw and the mip status of the GrBackendTexture.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext->priv().caps()->mipmapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
|
2021-01-26 22:46:50 +00:00
|
|
|
for (auto betMipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
|
|
|
for (auto requestMipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
2020-10-13 00:45:06 +00:00
|
|
|
auto ii =
|
|
|
|
SkImageInfo::Make({kSize, kSize}, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage(
|
2021-01-26 22:46:50 +00:00
|
|
|
dContext, ii, SkColors::kTransparent, betMipmapped);
|
|
|
|
REPORTER_ASSERT(reporter, (betMipmapped == GrMipmapped::kYes) == image->hasMipmaps());
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext);
|
2017-10-23 13:37:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
if (!proxy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture());
|
2017-10-23 13:37:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make(
|
2018-03-27 13:56:31 +00:00
|
|
|
texture, kTopLeft_GrSurfaceOrigin, nullptr, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
2017-10-23 13:37:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, imageGen);
|
|
|
|
if (!imageGen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint origin = SkIPoint::Make(0,0);
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2020-03-18 14:06:13 +00:00
|
|
|
GrSurfaceProxyView genView = imageGen->generateTexture(
|
2021-01-26 22:46:50 +00:00
|
|
|
dContext, imageInfo, origin, requestMipmapped, GrImageTexGenPolicy::kDraw);
|
2020-02-03 19:17:08 +00:00
|
|
|
GrSurfaceProxy* genProxy = genView.proxy();
|
2017-10-23 13:37:36 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, genProxy);
|
|
|
|
if (!genProxy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:42 +00:00
|
|
|
if (genProxy->isLazy()) {
|
2020-08-11 15:48:49 +00:00
|
|
|
genProxy->priv().doLazyInstantiation(dContext->priv().resourceProvider());
|
2018-07-31 21:25:29 +00:00
|
|
|
} else if (!genProxy->isInstantiated()) {
|
2020-08-11 15:48:49 +00:00
|
|
|
genProxy->instantiate(dContext->priv().resourceProvider());
|
2018-01-17 15:52:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, genProxy->isInstantiated());
|
|
|
|
if (!genProxy->isInstantiated()) {
|
2018-01-24 18:22:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
GrTexture* genTexture = genProxy->peekTexture();
|
2017-10-23 13:37:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, genTexture);
|
|
|
|
if (!genTexture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
GrBackendTexture backendTex = texture->getBackendTexture();
|
2017-12-13 20:00:45 +00:00
|
|
|
GrBackendTexture genBackendTex = genTexture->getBackendTexture();
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2018-10-12 13:31:11 +00:00
|
|
|
if (GrBackendApi::kOpenGL == genBackendTex.backend()) {
|
2018-04-10 13:34:07 +00:00
|
|
|
GrGLTextureInfo genTexInfo;
|
|
|
|
GrGLTextureInfo origTexInfo;
|
|
|
|
if (genBackendTex.getGLTextureInfo(&genTexInfo) &&
|
|
|
|
backendTex.getGLTextureInfo(&origTexInfo)) {
|
2021-01-26 22:46:50 +00:00
|
|
|
if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
|
2018-04-10 13:34:07 +00:00
|
|
|
// We did a copy so the texture IDs should be different
|
|
|
|
REPORTER_ASSERT(reporter, origTexInfo.fID != genTexInfo.fID);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, origTexInfo.fID == genTexInfo.fID);
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
} else {
|
2018-04-10 13:34:07 +00:00
|
|
|
ERRORF(reporter, "Failed to get GrGLTextureInfo");
|
2017-10-23 13:37:36 +00:00
|
|
|
}
|
|
|
|
#ifdef SK_VULKAN
|
2018-10-12 13:31:11 +00:00
|
|
|
} else if (GrBackendApi::kVulkan == genBackendTex.backend()) {
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo genImageInfo;
|
|
|
|
GrVkImageInfo origImageInfo;
|
|
|
|
if (genBackendTex.getVkImageInfo(&genImageInfo) &&
|
|
|
|
backendTex.getVkImageInfo(&origImageInfo)) {
|
2021-01-26 22:46:50 +00:00
|
|
|
if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
|
2018-04-10 13:34:07 +00:00
|
|
|
// We did a copy so the texture IDs should be different
|
|
|
|
REPORTER_ASSERT(reporter, origImageInfo.fImage != genImageInfo.fImage);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, origImageInfo.fImage == genImageInfo.fImage);
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
} else {
|
2018-04-10 13:34:07 +00:00
|
|
|
ERRORF(reporter, "Failed to get GrVkImageInfo");
|
2017-10-23 13:37:36 +00:00
|
|
|
}
|
2019-04-10 19:11:12 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SK_METAL
|
|
|
|
} else if (GrBackendApi::kMetal == genBackendTex.backend()) {
|
|
|
|
GrMtlTextureInfo genImageInfo;
|
|
|
|
GrMtlTextureInfo origImageInfo;
|
|
|
|
if (genBackendTex.getMtlTextureInfo(&genImageInfo) &&
|
|
|
|
backendTex.getMtlTextureInfo(&origImageInfo)) {
|
2021-01-26 22:46:50 +00:00
|
|
|
if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
|
2019-04-10 19:11:12 +00:00
|
|
|
// We did a copy so the texture IDs should be different
|
|
|
|
REPORTER_ASSERT(reporter, origImageInfo.fTexture != genImageInfo.fTexture);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, origImageInfo.fTexture == genImageInfo.fTexture);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERRORF(reporter, "Failed to get GrMtlTextureInfo");
|
|
|
|
}
|
2020-10-08 17:43:40 +00:00
|
|
|
#endif
|
2021-05-07 20:25:49 +00:00
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
} else if (GrBackendApi::kDirect3D == genBackendTex.backend()) {
|
|
|
|
GrD3DTextureResourceInfo genImageInfo;
|
|
|
|
GrD3DTextureResourceInfo origImageInfo;
|
|
|
|
if (genBackendTex.getD3DTextureResourceInfo(&genImageInfo) &&
|
|
|
|
backendTex.getD3DTextureResourceInfo(&origImageInfo)) {
|
|
|
|
if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
|
|
|
|
// We did a copy so the texture resources should be different
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
origImageInfo.fResource != genImageInfo.fResource);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
origImageInfo.fResource == genImageInfo.fResource);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERRORF(reporter, "Failed to get GrMtlTextureInfo");
|
|
|
|
}
|
|
|
|
#endif
|
2020-10-08 17:43:40 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
} else if (GrBackendApi::kDawn == genBackendTex.backend()) {
|
|
|
|
GrDawnTextureInfo genImageInfo;
|
|
|
|
GrDawnTextureInfo origImageInfo;
|
|
|
|
if (genBackendTex.getDawnTextureInfo(&genImageInfo) &&
|
|
|
|
backendTex.getDawnTextureInfo(&origImageInfo)) {
|
2021-01-26 22:46:50 +00:00
|
|
|
if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
|
2020-10-08 17:43:40 +00:00
|
|
|
// We did a copy so the texture IDs should be different
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
origImageInfo.fTexture.Get() != genImageInfo.fTexture.Get());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
origImageInfo.fTexture.Get() == genImageInfo.fTexture.Get());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERRORF(reporter, "Failed to get GrDawnTextureInfo");
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 17:41:26 +00:00
|
|
|
// Test that when we call makeImageSnapshot on an SkSurface we retains the same mip status as the
|
|
|
|
// resource we took the snapshot of.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext->priv().caps()->mipmapSupport()) {
|
2017-10-30 17:41:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
auto resourceProvider = dContext->priv().resourceProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
|
2017-10-30 17:41:26 +00:00
|
|
|
for (auto willUseMips : {false, true}) {
|
|
|
|
for (auto isWrapped : {false, true}) {
|
2021-01-26 22:46:50 +00:00
|
|
|
GrMipmapped mipmapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo;
|
2017-10-30 17:41:26 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
2020-10-13 00:45:06 +00:00
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2017-10-30 17:41:26 +00:00
|
|
|
if (isWrapped) {
|
2020-10-13 00:45:06 +00:00
|
|
|
surface = sk_gpu_test::MakeBackendTextureSurface(dContext,
|
|
|
|
info,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
/* sample count */ 1,
|
2021-01-26 22:46:50 +00:00
|
|
|
mipmapped);
|
2017-10-30 17:41:26 +00:00
|
|
|
} else {
|
2020-10-13 00:45:06 +00:00
|
|
|
surface = SkSurface::MakeRenderTarget(dContext,
|
|
|
|
SkBudgeted::kYes,
|
|
|
|
info,
|
|
|
|
/* sample count */ 1,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
nullptr,
|
2017-10-30 17:41:26 +00:00
|
|
|
willUseMips);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, surface);
|
2021-07-06 16:21:37 +00:00
|
|
|
auto device = ((SkSurface_Gpu*)surface.get())->getDevice();
|
2021-05-24 19:35:08 +00:00
|
|
|
GrTextureProxy* texProxy = device->readSurfaceView().asTextureProxy();
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapped == texProxy->mipmapped());
|
2017-10-30 17:41:26 +00:00
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
texProxy->instantiate(resourceProvider);
|
2018-07-31 21:25:29 +00:00
|
|
|
GrTexture* texture = texProxy->peekTexture();
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapped == texture->mipmapped());
|
2017-10-30 17:41:26 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, willUseMips == image->hasMipmaps());
|
2017-10-30 17:41:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
2021-02-23 15:45:39 +00:00
|
|
|
texProxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext);
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapped == texProxy->mipmapped());
|
2017-10-30 17:41:26 +00:00
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
texProxy->instantiate(resourceProvider);
|
2018-07-31 21:25:29 +00:00
|
|
|
texture = texProxy->peekTexture();
|
2021-01-26 22:46:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapped == texture->mipmapped());
|
2017-10-30 17:41:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 14:30:48 +00:00
|
|
|
|
|
|
|
// Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set
|
|
|
|
// to use mips. This test passes by not crashing or hitting asserts in code.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
if (!dContext->priv().caps()->mipmapSupport()) {
|
2018-07-20 14:30:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make surface to draw into
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType);
|
2020-08-11 15:48:49 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
|
2018-07-20 14:30:48 +00:00
|
|
|
|
|
|
|
// Make 1x1 raster bitmap
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.allocN32Pixels(1, 1);
|
|
|
|
SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels());
|
|
|
|
*pixel = 0;
|
|
|
|
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> bmpImage = bmp.asImage();
|
2018-07-20 14:30:48 +00:00
|
|
|
|
|
|
|
// Make sure we scale so we don't optimize out the use of mips.
|
|
|
|
surface->getCanvas()->scale(0.5f, 0.5f);
|
|
|
|
|
|
|
|
// This should upload the image to a non mipped GrTextureProxy.
|
2021-01-28 02:21:08 +00:00
|
|
|
surface->getCanvas()->drawImage(bmpImage, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2018-07-20 14:30:48 +00:00
|
|
|
|
|
|
|
// Now set the filter quality to high so we use mip maps. We should find the non mipped texture
|
|
|
|
// in the cache for the SkImage. Since the texture is 1x1 we should just use that texture
|
|
|
|
// instead of trying to do a copy to a mipped texture.
|
2021-01-28 02:21:08 +00:00
|
|
|
surface->getCanvas()->drawImage(bmpImage, 0, 0, SkSamplingOptions({1.0f/3, 1.0f/3}));
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2018-07-20 14:30:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 19:55:05 +00:00
|
|
|
// Create a new render target and draw 'mipmapView' into it using the provided 'filter'.
|
2021-07-28 19:13:20 +00:00
|
|
|
static std::unique_ptr<skgpu::v1::SurfaceDrawContext> draw_mipmap_into_new_render_target(
|
2020-08-11 15:48:49 +00:00
|
|
|
GrRecordingContext* rContext,
|
2020-07-22 15:18:06 +00:00
|
|
|
GrColorType colorType,
|
|
|
|
SkAlphaType alphaType,
|
|
|
|
GrSurfaceProxyView mipmapView,
|
|
|
|
GrSamplerState::MipmapMode mm) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto proxyProvider = rContext->priv().proxyProvider();
|
2020-07-22 15:18:06 +00:00
|
|
|
sk_sp<GrSurfaceProxy> renderTarget =
|
|
|
|
proxyProvider->createProxy(mipmapView.proxy()->backendFormat(),
|
|
|
|
{1, 1},
|
|
|
|
GrRenderable::kYes,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBackingFit::kApprox,
|
|
|
|
SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(rContext,
|
|
|
|
colorType,
|
|
|
|
std::move(renderTarget),
|
|
|
|
nullptr,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
SkSurfaceProps(),
|
|
|
|
false);
|
2020-07-22 15:18:06 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->drawTexture(nullptr,
|
2020-07-22 15:18:06 +00:00
|
|
|
std::move(mipmapView),
|
|
|
|
alphaType,
|
|
|
|
GrSamplerState::Filter::kLinear,
|
|
|
|
mm,
|
|
|
|
SkBlendMode::kSrcOver,
|
|
|
|
{1, 1, 1, 1},
|
|
|
|
SkRect::MakeWH(4, 4),
|
|
|
|
SkRect::MakeWH(1, 1),
|
|
|
|
GrAA::kYes,
|
|
|
|
GrQuadAAFlags::kAll,
|
|
|
|
SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkMatrix::I(),
|
2019-11-23 00:09:27 +00:00
|
|
|
nullptr);
|
2021-07-28 19:13:20 +00:00
|
|
|
return sdc;
|
2019-08-14 15:24:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
// Test that two opsTasks using the same mipmaps both depend on the same GrTextureResolveRenderTask.
|
2019-08-21 16:22:50 +00:00
|
|
|
DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
|
|
|
|
using Enable = GrContextOptions::Enable;
|
2020-07-22 15:18:06 +00:00
|
|
|
using MipmapMode = GrSamplerState::MipmapMode;
|
2019-08-21 16:22:50 +00:00
|
|
|
|
|
|
|
for (auto enableSortingAndReduction : {Enable::kYes, Enable::kNo}) {
|
|
|
|
GrMockOptions mockOptions;
|
2020-07-21 14:49:25 +00:00
|
|
|
mockOptions.fMipmapSupport = true;
|
2019-08-21 16:22:50 +00:00
|
|
|
GrContextOptions ctxOptions;
|
2019-08-22 21:15:39 +00:00
|
|
|
ctxOptions.fReduceOpsTaskSplitting = enableSortingAndReduction;
|
2020-08-11 15:48:49 +00:00
|
|
|
sk_sp<GrDirectContext> dContext = GrDirectContext::MakeMock(&mockOptions, ctxOptions);
|
|
|
|
GrDrawingManager* drawingManager = dContext->priv().drawingManager();
|
|
|
|
if (!dContext) {
|
|
|
|
ERRORF(reporter, "could not create mock dContext with fReduceOpsTaskSplitting %s.",
|
2019-08-21 16:22:50 +00:00
|
|
|
(Enable::kYes == enableSortingAndReduction) ? "enabled" : "disabled");
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-14 15:24:37 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
SkASSERT(dContext->priv().caps()->mipmapSupport());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
GrBackendFormat format = dContext->defaultBackendFormat(
|
2019-08-21 16:22:50 +00:00
|
|
|
kRGBA_8888_SkColorType, GrRenderable::kYes);
|
|
|
|
GrColorType colorType = GrColorType::kRGBA_8888;
|
2019-11-23 00:09:27 +00:00
|
|
|
SkAlphaType alphaType = kPremul_SkAlphaType;
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
2019-08-21 16:22:50 +00:00
|
|
|
|
|
|
|
// Create a mipmapped render target.
|
2020-01-21 19:29:57 +00:00
|
|
|
|
2019-08-30 20:19:42 +00:00
|
|
|
sk_sp<GrTextureProxy> mipmapProxy = proxyProvider->createProxy(
|
2020-07-21 13:27:25 +00:00
|
|
|
format, {4, 4}, GrRenderable::kYes, 1, GrMipmapped::kYes, SkBackingFit::kExact,
|
2020-03-27 00:37:01 +00:00
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Mark the mipmaps clean to ensure things still work properly when they won't be marked
|
|
|
|
// dirty again until GrRenderTask::makeClosed().
|
2020-07-21 16:09:58 +00:00
|
|
|
mipmapProxy->markMipmapsClean();
|
2019-08-21 06:01:21 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
auto mipmapSDC = skgpu::v1::SurfaceDrawContext::Make(
|
2021-05-24 17:14:39 +00:00
|
|
|
dContext.get(), colorType, mipmapProxy, nullptr, kTopLeft_GrSurfaceOrigin,
|
2021-04-19 23:27:09 +00:00
|
|
|
SkSurfaceProps(), false);
|
2020-01-07 20:42:57 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
mipmapSDC->clear(SkPMColor4f{.1f, .2f, .3f, .4f});
|
2020-06-08 19:55:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, drawingManager->getLastRenderTask(mipmapProxy.get()));
|
2019-08-22 20:19:24 +00:00
|
|
|
// mipmapProxy's last render task should now just be the opsTask containing the clear.
|
2019-08-21 16:22:50 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2021-07-28 19:13:20 +00:00
|
|
|
mipmapSDC->testingOnly_PeekLastOpsTask() ==
|
2020-06-08 19:55:00 +00:00
|
|
|
drawingManager->getLastRenderTask(mipmapProxy.get()));
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Mipmaps don't get marked dirty until makeClosed().
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
|
2019-08-21 06:01:21 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(format, colorType);
|
2020-01-30 19:55:05 +00:00
|
|
|
GrSurfaceProxyView mipmapView(mipmapProxy, kTopLeft_GrSurfaceOrigin, swizzle);
|
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
// Draw the dirty mipmap texture into a render target.
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
|
2020-08-11 15:48:49 +00:00
|
|
|
mipmapView, MipmapMode::kLinear);
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc1Task = sk_ref_sp(sdc1->testingOnly_PeekLastOpsTask());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Mipmaps should have gotten marked dirty during makeClosed, then marked clean again as
|
|
|
|
// soon as a GrTextureResolveRenderTask was inserted. The way we know they were resolved is
|
2019-08-22 20:19:24 +00:00
|
|
|
// if mipmapProxy->getLastRenderTask() has switched from the opsTask that drew to it, to the
|
2019-08-21 06:01:21 +00:00
|
|
|
// task that resolved its mips.
|
2020-06-08 19:55:00 +00:00
|
|
|
GrRenderTask* initialMipmapRegenTask = drawingManager->getLastRenderTask(mipmapProxy.get());
|
2019-08-21 16:22:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, initialMipmapRegenTask);
|
|
|
|
REPORTER_ASSERT(reporter,
|
2021-07-28 19:13:20 +00:00
|
|
|
initialMipmapRegenTask != mipmapSDC->testingOnly_PeekLastOpsTask());
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
|
|
|
// Draw the now-clean mipmap texture into a second target.
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
|
2020-08-11 15:48:49 +00:00
|
|
|
mipmapView, MipmapMode::kLinear);
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc2Task = sk_ref_sp(sdc2->testingOnly_PeekLastOpsTask());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
|
|
|
// Make sure the mipmap texture still has the same regen task.
|
2020-06-08 19:55:00 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
drawingManager->getLastRenderTask(mipmapProxy.get()) == initialMipmapRegenTask);
|
2020-07-21 16:09:58 +00:00
|
|
|
SkASSERT(!mipmapProxy->mipmapsAreDirty());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
|
|
|
// Reset everything so we can go again, this time with the first draw not mipmapped.
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->flushAndSubmit();
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-09-18 19:41:50 +00:00
|
|
|
// Mip regen tasks don't get added as dependencies until makeClosed().
|
2021-07-28 19:13:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, sdc1Task->dependsOn(initialMipmapRegenTask));
|
|
|
|
REPORTER_ASSERT(reporter, sdc2Task->dependsOn(initialMipmapRegenTask));
|
2019-09-18 19:41:50 +00:00
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
// Render something to dirty the mips.
|
2021-07-28 19:13:20 +00:00
|
|
|
mipmapSDC->clear(SkPMColor4f{.1f, .2f, .3f, .4f});
|
|
|
|
auto mipmapRTCTask = sk_ref_sp(mipmapSDC->testingOnly_PeekLastOpsTask());
|
2020-04-21 16:43:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapRTCTask);
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
// mipmapProxy's last render task should now just be the opsTask containing the clear.
|
2020-06-08 19:55:00 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
mipmapRTCTask.get() == drawingManager->getLastRenderTask(mipmapProxy.get()));
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Mipmaps don't get marked dirty until makeClosed().
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
|
2019-08-21 06:01:21 +00:00
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
// Draw the dirty mipmap texture into a render target, but don't do mipmap filtering.
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
|
2020-08-11 15:48:49 +00:00
|
|
|
mipmapView, MipmapMode::kNone);
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Mipmaps should have gotten marked dirty during makeClosed() when adding the dependency.
|
|
|
|
// Since the last draw did not use mips, they will not have been regenerated and should
|
|
|
|
// therefore still be dirty.
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapProxy->mipmapsAreDirty());
|
2019-08-21 06:01:21 +00:00
|
|
|
|
|
|
|
// Since mips weren't regenerated, the last render task shouldn't have changed.
|
2020-06-08 19:55:00 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
mipmapRTCTask.get() == drawingManager->getLastRenderTask(mipmapProxy.get()));
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Draw the stil-dirty mipmap texture into a second target with mipmap filtering.
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
|
2020-08-11 15:48:49 +00:00
|
|
|
std::move(mipmapView), MipmapMode::kLinear);
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc2Task = sk_ref_sp(sdc2->testingOnly_PeekLastOpsTask());
|
2019-08-21 16:22:50 +00:00
|
|
|
|
2019-08-21 06:01:21 +00:00
|
|
|
// Make sure the mipmap texture now has a new last render task that regenerates the mips,
|
|
|
|
// and that the mipmaps are now clean.
|
2020-06-08 19:55:00 +00:00
|
|
|
auto mipRegenTask2 = drawingManager->getLastRenderTask(mipmapProxy.get());
|
2019-09-18 19:41:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipRegenTask2);
|
2020-04-21 16:43:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipmapRTCTask.get() != mipRegenTask2);
|
2020-07-21 16:09:58 +00:00
|
|
|
SkASSERT(!mipmapProxy->mipmapsAreDirty());
|
2019-09-18 19:41:50 +00:00
|
|
|
|
|
|
|
// Mip regen tasks don't get added as dependencies until makeClosed().
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->flushAndSubmit();
|
2021-07-28 19:13:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, sdc2Task->dependsOn(mipRegenTask2));
|
2019-08-21 16:22:50 +00:00
|
|
|
}
|
2019-08-14 15:24:37 +00:00
|
|
|
}
|