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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include "GrBackendSurface.h"
|
2017-10-23 13:37:36 +00:00
|
|
|
#include "GrBackendTextureImageGenerator.h"
|
2017-10-12 16:27:11 +00:00
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrContextPriv.h"
|
|
|
|
#include "GrGpu.h"
|
|
|
|
#include "GrRenderTargetContext.h"
|
2017-10-23 13:37:36 +00:00
|
|
|
#include "GrSemaphore.h"
|
2017-10-12 16:27:11 +00:00
|
|
|
#include "GrSurfaceProxyPriv.h"
|
|
|
|
#include "GrTest.h"
|
|
|
|
#include "GrTexturePriv.h"
|
|
|
|
#include "GrTextureProxy.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkImage_Base.h"
|
|
|
|
#include "SkGpuDevice.h"
|
2017-10-23 13:37:36 +00:00
|
|
|
#include "SkPoint.h"
|
2017-10-12 16:27:11 +00:00
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "SkSurface_Gpu.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
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();
|
2018-05-11 14:14:21 +00:00
|
|
|
if (!context->contextPriv().caps()->mipMapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
2017-10-12 16:27:11 +00:00
|
|
|
for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
|
|
|
|
for (auto isRT : {false, true}) {
|
|
|
|
// CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps
|
|
|
|
// 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.
|
2018-01-22 15:48:15 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
2017-11-16 19:59:48 +00:00
|
|
|
nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, isRT, mipMapped);
|
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;
|
|
|
|
if (isRT) {
|
|
|
|
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);
|
2017-11-13 17:47:24 +00:00
|
|
|
proxy = as_IB(image)->asTextureProxyRef();
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
if (!proxy) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2017-10-12 16:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, proxy->priv().isInstantiated());
|
|
|
|
|
|
|
|
GrTexture* texture = proxy->priv().peekTexture();
|
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
if (!texture) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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());
|
2017-10-12 16:27:11 +00:00
|
|
|
if (isRT) {
|
|
|
|
REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty());
|
|
|
|
} else {
|
2018-06-21 21:00:26 +00:00
|
|
|
#if 1
|
|
|
|
// This is temporarily checks that the new image DOES have dirty MIP levels. See
|
|
|
|
// comment in SkImage_Gpu.cpp, new_wrapped_texture_common().
|
|
|
|
REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty());
|
|
|
|
#else
|
2017-10-12 16:27:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty());
|
2018-06-21 21:00:26 +00:00
|
|
|
#endif
|
2017-10-12 16:27:11 +00:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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();
|
2018-05-11 14:14:21 +00:00
|
|
|
if (!context->contextPriv().caps()->mipMapSupport()) {
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
2017-10-23 13:37:36 +00:00
|
|
|
for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
|
|
|
|
for (auto willUseMips : {false, true}) {
|
2018-01-22 15:48:15 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
2017-10-23 13:37:36 +00:00
|
|
|
nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, mipMapped);
|
|
|
|
|
|
|
|
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) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, proxy->priv().isInstantiated());
|
|
|
|
|
|
|
|
sk_sp<GrTexture> texture = sk_ref_sp(proxy->priv().peekTexture());
|
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
if (!texture) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint origin = SkIPoint::Make(0,0);
|
|
|
|
// The transfer function behavior isn't used in the generator so set we set it
|
|
|
|
// arbitrarily here.
|
|
|
|
SkTransferFunctionBehavior behavior = SkTransferFunctionBehavior::kIgnore;
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
sk_sp<GrTextureProxy> genProxy = imageGen->generateTexture(context, imageInfo,
|
|
|
|
origin, behavior,
|
|
|
|
willUseMips);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, genProxy);
|
|
|
|
if (!genProxy) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2017-10-23 13:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:52:04 +00:00
|
|
|
if (GrSurfaceProxy::LazyState::kNot != genProxy->lazyInstantiationState()) {
|
|
|
|
genProxy->priv().doLazyInstantiation(context->contextPriv().resourceProvider());
|
2018-02-15 18:06:26 +00:00
|
|
|
} else if (!genProxy->priv().isInstantiated()) {
|
|
|
|
genProxy->instantiate(context->contextPriv().resourceProvider());
|
2018-01-17 15:52:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 13:37:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, genProxy->priv().isInstantiated());
|
2018-01-24 18:22:24 +00:00
|
|
|
if (!genProxy->priv().isInstantiated()) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2018-01-24 18:22:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-23 13:37:36 +00:00
|
|
|
|
|
|
|
GrTexture* genTexture = genProxy->priv().peekTexture();
|
|
|
|
REPORTER_ASSERT(reporter, genTexture);
|
|
|
|
if (!genTexture) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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-04-10 13:34:07 +00:00
|
|
|
if (kOpenGL_GrBackend == genBackendTex.backend()) {
|
|
|
|
GrGLTextureInfo genTexInfo;
|
|
|
|
GrGLTextureInfo origTexInfo;
|
|
|
|
if (genBackendTex.getGLTextureInfo(&genTexInfo) &&
|
|
|
|
backendTex.getGLTextureInfo(&origTexInfo)) {
|
|
|
|
if (willUseMips && GrMipMapped::kNo == mipMapped) {
|
|
|
|
// 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-04-10 13:34:07 +00:00
|
|
|
} else if (kVulkan_GrBackend == genBackendTex.backend()) {
|
|
|
|
GrVkImageInfo genImageInfo;
|
|
|
|
GrVkImageInfo origImageInfo;
|
|
|
|
if (genBackendTex.getVkImageInfo(&genImageInfo) &&
|
|
|
|
backendTex.getVkImageInfo(&origImageInfo)) {
|
|
|
|
if (willUseMips && GrMipMapped::kNo == mipMapped) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
#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.
|
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
2017-10-23 13:37:36 +00:00
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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();
|
2018-05-11 14:14:21 +00:00
|
|
|
if (!context->contextPriv().caps()->mipMapSupport()) {
|
2017-10-30 17:41:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:07:54 +00:00
|
|
|
auto resourceProvider = context->contextPriv().resourceProvider();
|
2018-01-22 15:48:15 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
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;
|
2018-01-22 15:48:15 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
2017-12-12 18:01:25 +00:00
|
|
|
nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, true, mipMapped);
|
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) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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);
|
2017-10-30 17:41:26 +00:00
|
|
|
GrTexture* texture = texProxy->priv().peekTexture();
|
|
|
|
REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped());
|
|
|
|
|
|
|
|
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
if (!image) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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);
|
2017-10-30 17:41:26 +00:00
|
|
|
texture = texProxy->priv().peekTexture();
|
|
|
|
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.
|
|
|
|
context->flush();
|
2018-04-16 14:24:45 +00:00
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2017-10-30 17:41:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|