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"
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/GrBackendTextureImageGenerator.h"
|
|
|
|
#include "src/gpu/GrContextPriv.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/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrSemaphore.h"
|
|
|
|
#include "src/gpu/GrSurfaceProxyPriv.h"
|
|
|
|
#include "src/gpu/GrTexturePriv.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGpuDevice.h"
|
|
|
|
#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"
|
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) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->priv().caps()->mipMapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
|
2017-10-12 16:27:11 +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-05-06 15:40:03 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent, mipMapped, renderable);
|
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;
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2017-10-12 16:27:11 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
|
|
|
|
context,
|
|
|
|
backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
0,
|
2017-12-19 18:15:02 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
2017-10-12 16:27:11 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
|
2017-11-13 17:47:24 +00:00
|
|
|
proxy = device->accessRenderTargetContext()->asTextureProxyRef();
|
2017-10-12 16:27:11 +00:00
|
|
|
} else {
|
|
|
|
image = SkImage::MakeFromTexture(context, backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
2017-12-18 19:48:15 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
nullptr, nullptr);
|
2020-02-05 22:06:27 +00:00
|
|
|
const GrSurfaceProxyView* view = as_IB(image)->view(context);
|
|
|
|
REPORTER_ASSERT(reporter, view);
|
|
|
|
if (!view) {
|
|
|
|
context->deleteBackendTexture(backendTex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
proxy = view->asTextureProxyRef();
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
if (!proxy) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-12 16:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-12 16:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GrMipMapped::kYes == mipMapped) {
|
2017-10-23 20:05:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrMipMapped::kYes == texture->texturePriv().mipMapped());
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2017-10-12 16:27:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty());
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-23 20:05:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrMipMapped::kNo == texture->texturePriv().mipMapped());
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
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) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->priv().caps()->mipMapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
|
2020-02-28 23:07:32 +00:00
|
|
|
for (auto betMipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
|
|
|
|
for (auto requestMipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
|
2020-05-06 15:40:03 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent, betMipMapped, GrRenderable::kNo);
|
2017-10-23 13:37:36 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
2017-12-18 19:48:15 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
nullptr, nullptr);
|
2017-10-23 13:37:36 +00:00
|
|
|
|
|
|
|
GrTextureProxy* proxy = as_IB(image)->peekProxy();
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
if (!proxy) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
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) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
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) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
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(
|
|
|
|
context, 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) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:42 +00:00
|
|
|
if (genProxy->isLazy()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
genProxy->priv().doLazyInstantiation(context->priv().resourceProvider());
|
2018-07-31 21:25:29 +00:00
|
|
|
} else if (!genProxy->isInstantiated()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
genProxy->instantiate(context->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()) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
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) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)) {
|
2020-02-28 23:07:32 +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)) {
|
2020-02-28 23:07:32 +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)) {
|
2020-02-28 23:07:32 +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");
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must make sure the uses of the backend texture have finished (we possibly have a
|
2018-03-08 14:49:58 +00:00
|
|
|
// queued up copy) before we delete the backend texture.
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2019-05-17 14:01:21 +00:00
|
|
|
context->priv().getGpu()->testingOnly_flushGpuAndSync();
|
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->priv().caps()->mipMapSupport()) {
|
2017-10-30 17:41:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
auto resourceProvider = context->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}) {
|
|
|
|
GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo;
|
|
|
|
sk_sp<SkSurface> surface;
|
2020-05-06 15:40:03 +00:00
|
|
|
GrBackendTexture backendTex;
|
|
|
|
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent, mipMapped, GrRenderable::kYes);
|
2017-10-30 17:41:26 +00:00
|
|
|
if (isWrapped) {
|
|
|
|
surface = SkSurface::MakeFromBackendTexture(context,
|
|
|
|
backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
0,
|
2017-12-19 18:15:02 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
2017-10-30 17:41:26 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
} else {
|
|
|
|
SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0,
|
|
|
|
kTopLeft_GrSurfaceOrigin, nullptr,
|
|
|
|
willUseMips);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, surface);
|
|
|
|
if (!surface) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-30 17:41:26 +00:00
|
|
|
}
|
|
|
|
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
|
|
|
|
GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped());
|
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
texProxy->instantiate(resourceProvider);
|
2018-07-31 21:25:29 +00:00
|
|
|
GrTexture* texture = texProxy->peekTexture();
|
2017-10-30 17:41:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped());
|
|
|
|
|
|
|
|
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
if (!image) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-10-30 17:41:26 +00:00
|
|
|
}
|
|
|
|
texProxy = as_IB(image)->peekProxy();
|
|
|
|
REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped());
|
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
texProxy->instantiate(resourceProvider);
|
2018-07-31 21:25:29 +00:00
|
|
|
texture = texProxy->peekTexture();
|
2017-10-30 17:41:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped());
|
|
|
|
|
|
|
|
// Must flush the context to make sure all the cmds (copies, etc.) from above are sent
|
|
|
|
// to the gpu before we delete the backendHandle.
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2019-05-17 14:01:21 +00:00
|
|
|
context->priv().getGpu()->testingOnly_flushGpuAndSync();
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
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) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->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);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
|
|
|
|
|
|
|
|
// Make 1x1 raster bitmap
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.allocN32Pixels(1, 1);
|
|
|
|
SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels());
|
|
|
|
*pixel = 0;
|
|
|
|
|
|
|
|
sk_sp<SkImage> bmpImage = SkImage::MakeFromBitmap(bmp);
|
|
|
|
|
|
|
|
// Make sure we scale so we don't optimize out the use of mips.
|
|
|
|
surface->getCanvas()->scale(0.5f, 0.5f);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
// This should upload the image to a non mipped GrTextureProxy.
|
|
|
|
surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint);
|
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.
|
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
|
|
|
surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint);
|
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'.
|
2019-08-21 13:38:10 +00:00
|
|
|
static std::unique_ptr<GrRenderTargetContext> draw_mipmap_into_new_render_target(
|
2020-01-07 20:42:57 +00:00
|
|
|
GrRecordingContext* context, GrProxyProvider* proxyProvider, GrColorType colorType,
|
2020-01-30 19:55:05 +00:00
|
|
|
SkAlphaType alphaType, GrSurfaceProxyView mipmapView, GrSamplerState::Filter filter) {
|
2019-08-14 15:24:37 +00:00
|
|
|
sk_sp<GrSurfaceProxy> renderTarget = proxyProvider->createProxy(
|
2020-03-27 00:37:01 +00:00
|
|
|
mipmapView.proxy()->backendFormat(), {1, 1}, GrRenderable::kYes, 1, GrMipMapped::kNo,
|
|
|
|
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
|
2020-01-07 20:42:57 +00:00
|
|
|
|
|
|
|
auto rtc = GrRenderTargetContext::Make(
|
|
|
|
context, colorType, nullptr, std::move(renderTarget), kTopLeft_GrSurfaceOrigin,
|
|
|
|
nullptr);
|
|
|
|
|
2020-05-29 13:54:07 +00:00
|
|
|
rtc->drawTexture(nullptr, std::move(mipmapView), alphaType, filter, SkBlendMode::kSrcOver,
|
2019-10-15 18:01:49 +00:00
|
|
|
{1,1,1,1}, SkRect::MakeWH(4, 4), SkRect::MakeWH(1,1), GrAA::kYes,
|
2019-11-23 00:09:27 +00:00
|
|
|
GrQuadAAFlags::kAll, SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(),
|
|
|
|
nullptr);
|
2019-08-14 15:24:37 +00:00
|
|
|
return rtc;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
using Filter = GrSamplerState::Filter;
|
|
|
|
|
|
|
|
for (auto enableSortingAndReduction : {Enable::kYes, Enable::kNo}) {
|
|
|
|
GrMockOptions mockOptions;
|
|
|
|
mockOptions.fMipMapSupport = true;
|
|
|
|
GrContextOptions ctxOptions;
|
2019-08-22 21:15:39 +00:00
|
|
|
ctxOptions.fReduceOpsTaskSplitting = enableSortingAndReduction;
|
2019-08-21 16:22:50 +00:00
|
|
|
sk_sp<GrContext> context = GrContext::MakeMock(&mockOptions, ctxOptions);
|
2020-06-08 19:55:00 +00:00
|
|
|
GrDrawingManager* drawingManager = context->priv().drawingManager();
|
2019-08-21 16:22:50 +00:00
|
|
|
if (!context) {
|
2019-08-22 20:19:24 +00:00
|
|
|
ERRORF(reporter, "could not create mock context 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
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
SkASSERT(context->priv().caps()->mipMapSupport());
|
|
|
|
|
|
|
|
GrBackendFormat format = context->defaultBackendFormat(
|
|
|
|
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
|
|
|
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
|
|
|
|
// 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-03-27 00:37:01 +00:00
|
|
|
format, {4, 4}, GrRenderable::kYes, 1, GrMipMapped::kYes, SkBackingFit::kExact,
|
|
|
|
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().
|
|
|
|
mipmapProxy->markMipMapsClean();
|
|
|
|
|
2020-01-07 20:42:57 +00:00
|
|
|
auto mipmapRTC = GrRenderTargetContext::Make(
|
|
|
|
context.get(), colorType, nullptr, mipmapProxy, kTopLeft_GrSurfaceOrigin, nullptr);
|
|
|
|
|
2020-05-26 20:57:38 +00:00
|
|
|
mipmapRTC->clear({.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,
|
2020-06-08 19:55:00 +00:00
|
|
|
mipmapRTC->testingOnly_PeekLastOpsTask() ==
|
|
|
|
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().
|
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty());
|
|
|
|
|
2020-03-27 00:37:01 +00:00
|
|
|
GrSwizzle swizzle = context->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.
|
2020-01-07 20:42:57 +00:00
|
|
|
auto rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
|
2020-01-30 19:55:05 +00:00
|
|
|
alphaType, mipmapView, Filter::kMipMap);
|
2020-04-21 16:43:26 +00:00
|
|
|
auto rtc1Task = sk_ref_sp(rtc1->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,
|
2019-08-22 20:19:24 +00:00
|
|
|
initialMipmapRegenTask != mipmapRTC->testingOnly_PeekLastOpsTask());
|
2019-08-21 16:22:50 +00:00
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty());
|
|
|
|
|
|
|
|
// Draw the now-clean mipmap texture into a second target.
|
2020-01-07 20:42:57 +00:00
|
|
|
auto rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
|
2020-01-30 19:55:05 +00:00
|
|
|
alphaType, mipmapView, Filter::kMipMap);
|
2020-04-21 16:43:26 +00:00
|
|
|
auto rtc2Task = sk_ref_sp(rtc2->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);
|
2019-08-21 16:22:50 +00:00
|
|
|
SkASSERT(!mipmapProxy->mipMapsAreDirty());
|
|
|
|
|
|
|
|
// Reset everything so we can go again, this time with the first draw not mipmapped.
|
2020-05-14 19:45:44 +00:00
|
|
|
context->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().
|
2020-04-21 16:43:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtc1Task->dependsOn(initialMipmapRegenTask));
|
|
|
|
REPORTER_ASSERT(reporter, rtc2Task->dependsOn(initialMipmapRegenTask));
|
2019-09-18 19:41:50 +00:00
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
// Render something to dirty the mips.
|
2020-05-26 20:57:38 +00:00
|
|
|
mipmapRTC->clear({.1f,.2f,.3f,.4f});
|
2020-04-21 16:43:26 +00:00
|
|
|
auto mipmapRTCTask = sk_ref_sp(mipmapRTC->testingOnly_PeekLastOpsTask());
|
|
|
|
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().
|
|
|
|
REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty());
|
|
|
|
|
2019-08-21 16:22:50 +00:00
|
|
|
// Draw the dirty mipmap texture into a render target, but don't do mipmap filtering.
|
2020-01-07 20:42:57 +00:00
|
|
|
rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
|
2020-01-30 19:55:05 +00:00
|
|
|
alphaType, mipmapView, Filter::kBilerp);
|
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.
|
2019-08-21 16:22:50 +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.
|
2020-01-07 20:42:57 +00:00
|
|
|
rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
|
2020-01-30 19:55:05 +00:00
|
|
|
alphaType, std::move(mipmapView),
|
|
|
|
Filter::kMipMap);
|
2020-04-21 16:43:26 +00:00
|
|
|
rtc2Task = sk_ref_sp(rtc2->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);
|
2019-08-21 16:22:50 +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-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2020-04-21 16:43:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtc2Task->dependsOn(mipRegenTask2));
|
2019-08-21 16:22:50 +00:00
|
|
|
}
|
2019-08-14 15:24:37 +00:00
|
|
|
}
|