2013-04-09 15:04:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-12-19 20:42:06 +00:00
|
|
|
#include <set>
|
|
|
|
#include "GrClip.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrContext.h"
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
#include "GrContextPriv.h"
|
2015-11-10 19:54:56 +00:00
|
|
|
#include "GrGpu.h"
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-07-26 19:48:41 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrResourceProvider.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrTexture.h"
|
2018-12-06 15:00:03 +00:00
|
|
|
#include "GrTexturePriv.h"
|
|
|
|
#include "SkAutoPixmapStorage.h"
|
2017-06-02 12:45:06 +00:00
|
|
|
#include "SkMipMap.h"
|
2018-12-19 20:42:06 +00:00
|
|
|
#include "SkSurface.h"
|
2014-01-10 22:08:27 +00:00
|
|
|
#include "Test.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2014-11-25 15:41:12 +00:00
|
|
|
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
|
|
|
|
// and render targets to GrSurface all work as expected.
|
2016-04-06 21:02:39 +00:00
|
|
|
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
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
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 256;
|
|
|
|
desc.fHeight = 256;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2018-02-03 01:32:49 +00:00
|
|
|
desc.fSampleCnt = 1;
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2014-11-25 15:41:12 +00:00
|
|
|
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
|
|
|
|
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
|
|
|
|
texRT1->asTexture());
|
|
|
|
REPORTER_ASSERT(reporter, texRT1->asRenderTarget() ==
|
|
|
|
static_cast<GrSurface*>(texRT1->asTexture()));
|
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
|
|
|
|
static_cast<GrSurface*>(texRT1->asTexture()));
|
2014-11-25 15:41:12 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fFlags = kNone_GrSurfaceFlags;
|
2018-01-16 20:07:54 +00:00
|
|
|
sk_sp<GrTexture> tex1 = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
|
2017-04-06 11:59:41 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
|
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
2018-09-25 13:31:10 +00:00
|
|
|
nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
|
2015-11-10 19:54:56 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture(
|
|
|
|
backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2016-10-27 16:30:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
|
|
|
|
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
|
|
|
|
texRT2->asTexture());
|
|
|
|
REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
|
|
|
|
static_cast<GrSurface*>(texRT2->asTexture()));
|
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
|
|
|
|
static_cast<GrSurface*>(texRT2->asTexture()));
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2013-04-09 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 17:23:19 +00:00
|
|
|
// This test checks that the isConfigTexturable and isConfigRenderable are
|
|
|
|
// consistent with createTexture's result.
|
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2018-01-08 18:40:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
|
2018-05-11 14:14:21 +00:00
|
|
|
const GrCaps* caps = context->contextPriv().caps();
|
2017-05-22 17:23:19 +00:00
|
|
|
|
|
|
|
GrPixelConfig configs[] = {
|
|
|
|
kUnknown_GrPixelConfig,
|
|
|
|
kAlpha_8_GrPixelConfig,
|
2017-11-17 21:47:21 +00:00
|
|
|
kAlpha_8_as_Alpha_GrPixelConfig,
|
|
|
|
kAlpha_8_as_Red_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
kGray_8_GrPixelConfig,
|
2017-12-05 21:27:11 +00:00
|
|
|
kGray_8_as_Lum_GrPixelConfig,
|
|
|
|
kGray_8_as_Red_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
kRGB_565_GrPixelConfig,
|
|
|
|
kRGBA_4444_GrPixelConfig,
|
|
|
|
kRGBA_8888_GrPixelConfig,
|
2018-03-22 14:01:16 +00:00
|
|
|
kRGB_888_GrPixelConfig,
|
2018-12-05 18:38:59 +00:00
|
|
|
kRG_88_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
kBGRA_8888_GrPixelConfig,
|
|
|
|
kSRGBA_8888_GrPixelConfig,
|
|
|
|
kSBGRA_8888_GrPixelConfig,
|
2018-03-02 16:01:10 +00:00
|
|
|
kRGBA_1010102_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
kRGBA_float_GrPixelConfig,
|
|
|
|
kRG_float_GrPixelConfig,
|
|
|
|
kAlpha_half_GrPixelConfig,
|
2017-11-17 21:47:21 +00:00
|
|
|
kAlpha_half_as_Red_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
kRGBA_half_GrPixelConfig,
|
2019-01-15 18:24:45 +00:00
|
|
|
kRGB_ETC1_GrPixelConfig,
|
2017-05-22 17:23:19 +00:00
|
|
|
};
|
2018-03-22 14:01:16 +00:00
|
|
|
GR_STATIC_ASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));
|
2017-05-22 17:23:19 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
|
|
|
|
for (GrPixelConfig config : configs) {
|
|
|
|
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags;
|
|
|
|
desc.fConfig = config;
|
2018-02-03 01:32:49 +00:00
|
|
|
desc.fSampleCnt = 1;
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2017-05-24 11:44:02 +00:00
|
|
|
sk_sp<GrSurface> tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2018-01-29 14:50:47 +00:00
|
|
|
bool ict = caps->isConfigTexturable(desc.fConfig);
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == ict,
|
|
|
|
"config:%d, tex:%d, isConfigTexturable:%d", config, SkToBool(tex), ict);
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSRGBEncoded srgbEncoded = GrSRGBEncoded::kNo;
|
|
|
|
GrColorType colorType = GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded);
|
|
|
|
const GrBackendFormat format =
|
|
|
|
caps->getBackendFormatFromGrColorType(colorType, srgbEncoded);
|
|
|
|
|
2018-03-04 03:43:43 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy =
|
2018-11-16 20:43:41 +00:00
|
|
|
proxyProvider->createMipMapProxy(format, desc, origin, SkBudgeted::kNo);
|
2017-06-02 12:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(proxy.get()) ==
|
|
|
|
(caps->isConfigTexturable(desc.fConfig) &&
|
2018-02-05 20:55:54 +00:00
|
|
|
caps->mipMapSupport()));
|
2017-06-02 12:45:06 +00:00
|
|
|
|
2017-05-22 17:23:19 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2017-05-24 11:44:02 +00:00
|
|
|
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2018-02-03 01:32:49 +00:00
|
|
|
bool isRenderable = caps->isConfigRenderable(config);
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
|
|
|
|
"config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex),
|
|
|
|
isRenderable);
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
desc.fSampleCnt = 2;
|
2017-05-24 11:44:02 +00:00
|
|
|
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2018-02-03 01:32:49 +00:00
|
|
|
isRenderable = SkToBool(caps->getRenderTargetSampleCount(2, config));
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
|
|
|
|
"config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex),
|
|
|
|
isRenderable);
|
2017-05-22 17:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 20:53:47 +00:00
|
|
|
#include "GrDrawingManager.h"
|
|
|
|
#include "GrSurfaceProxy.h"
|
|
|
|
#include "GrTextureContext.h"
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(InitialTextureClear, reporter, context_info) {
|
|
|
|
static constexpr int kSize = 100;
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = desc.fHeight = kSize;
|
|
|
|
std::unique_ptr<uint32_t[]> data(new uint32_t[kSize * kSize]);
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2017-05-23 20:53:47 +00:00
|
|
|
GrContext* context = context_info.grContext();
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrCaps* caps = context->contextPriv().caps();
|
2018-01-16 13:06:32 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
|
|
|
|
2017-05-23 20:53:47 +00:00
|
|
|
for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
|
|
|
|
desc.fConfig = static_cast<GrPixelConfig>(c);
|
2018-11-16 20:43:41 +00:00
|
|
|
if (!caps->isConfigTexturable(desc.fConfig)) {
|
2017-05-23 20:53:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
desc.fFlags = kPerformInitialClear_GrSurfaceFlag;
|
|
|
|
for (bool rt : {false, true}) {
|
2018-11-16 20:43:41 +00:00
|
|
|
if (rt && !caps->isConfigRenderable(desc.fConfig)) {
|
2017-05-23 20:53:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
desc.fFlags |= rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
|
2017-09-25 16:26:58 +00:00
|
|
|
for (GrSurfaceOrigin origin :
|
|
|
|
{kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
|
2018-01-16 13:06:32 +00:00
|
|
|
for (auto fit : { SkBackingFit::kApprox, SkBackingFit::kExact }) {
|
2017-09-25 16:26:58 +00:00
|
|
|
// Try directly creating the texture.
|
|
|
|
// Do this twice in an attempt to hit the cache on the second time through.
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2018-09-27 15:28:03 +00:00
|
|
|
auto proxy = proxyProvider->testingOnly_createInstantiatedProxy(
|
2018-03-04 03:43:43 +00:00
|
|
|
desc, origin, fit, SkBudgeted::kYes);
|
2018-01-16 13:06:32 +00:00
|
|
|
if (!proxy) {
|
2017-09-25 16:26:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto texCtx = context->contextPriv().makeWrappedSurfaceContext(
|
2018-07-02 19:21:46 +00:00
|
|
|
std::move(proxy));
|
2017-09-25 16:26:58 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(
|
|
|
|
kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
|
|
|
|
if (texCtx->readPixels(info, data.get(), 0, 0, 0)) {
|
|
|
|
uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
|
|
|
|
for (int i = 0; i < kSize * kSize; ++i) {
|
|
|
|
if (cmp != data.get()[i]) {
|
|
|
|
ERRORF(reporter, "Failed on config %d", desc.fConfig);
|
|
|
|
break;
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-25 16:26:58 +00:00
|
|
|
memset(data.get(), 0xBC, kSize * kSize * sizeof(uint32_t));
|
|
|
|
// Here we overwrite the texture so that the second time through we
|
|
|
|
// test against recycling without reclearing.
|
|
|
|
if (0 == i) {
|
|
|
|
texCtx->writePixels(info, data.get(), 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-03-06 13:20:37 +00:00
|
|
|
context->contextPriv().purgeAllUnlockedResources_ForTesting();
|
2017-09-25 16:26:58 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSRGBEncoded srgbEncoded = GrSRGBEncoded::kNo;
|
|
|
|
GrColorType colorType = GrPixelConfigToColorTypeAndEncoding(desc.fConfig,
|
|
|
|
&srgbEncoded);
|
|
|
|
const GrBackendFormat format =
|
|
|
|
caps->getBackendFormatFromGrColorType(colorType, srgbEncoded);
|
|
|
|
|
2017-09-25 16:26:58 +00:00
|
|
|
// Try creating the texture as a deferred proxy.
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
auto surfCtx = context->contextPriv().makeDeferredSurfaceContext(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes);
|
2017-09-25 16:26:58 +00:00
|
|
|
if (!surfCtx) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkImageInfo info = SkImageInfo::Make(
|
|
|
|
kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
|
|
|
|
if (surfCtx->readPixels(info, data.get(), 0, 0, 0)) {
|
|
|
|
uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
|
|
|
|
for (int i = 0; i < kSize * kSize; ++i) {
|
|
|
|
if (cmp != data.get()[i]) {
|
|
|
|
ERRORF(reporter, "Failed on config %d", desc.fConfig);
|
|
|
|
break;
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-25 16:26:58 +00:00
|
|
|
// Here we overwrite the texture so that the second time through we
|
|
|
|
// test against recycling without reclearing.
|
|
|
|
if (0 == i) {
|
|
|
|
surfCtx->writePixels(info, data.get(), 0, 0, 0);
|
|
|
|
}
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
2018-03-06 13:20:37 +00:00
|
|
|
context->contextPriv().purgeAllUnlockedResources_ForTesting();
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-06 15:00:03 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
|
|
|
|
auto fillPixels = [](const SkPixmap* p, const std::function<uint32_t(int x, int y)>& f) {
|
|
|
|
for (int y = 0; y < p->height(); ++y) {
|
|
|
|
for (int x = 0; x < p->width(); ++x) {
|
|
|
|
*p->writable_addr32(x, y) = f(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto comparePixels = [](const SkPixmap& p1, const SkPixmap& p2, skiatest::Reporter* reporter) {
|
|
|
|
SkASSERT(p1.info() == p2.info());
|
|
|
|
for (int y = 0; y < p1.height(); ++y) {
|
|
|
|
for (int x = 0; x < p1.width(); ++x) {
|
|
|
|
REPORTER_ASSERT(reporter, p1.getColor(x, y) == p2.getColor(x, y));
|
|
|
|
if (p1.getColor(x, y) != p2.getColor(x, y)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr int kSize = 100;
|
|
|
|
SkAutoPixmapStorage pixels;
|
|
|
|
pixels.alloc(SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType));
|
|
|
|
fillPixels(&pixels,
|
|
|
|
[](int x, int y) { return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t(x * y); });
|
|
|
|
|
|
|
|
GrContext* context = context_info.grContext();
|
|
|
|
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
|
|
|
|
|
|
|
// We test both kRW in addition to kRead mostly to ensure that the calls are structured such
|
|
|
|
// that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with
|
|
|
|
// kRead for the right reason.
|
|
|
|
for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) {
|
|
|
|
auto backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
|
|
|
|
pixels.addr(), kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kNo);
|
|
|
|
auto proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
|
2019-01-24 21:03:07 +00:00
|
|
|
kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, ioType);
|
2018-12-06 15:00:03 +00:00
|
|
|
auto surfContext = context->contextPriv().makeWrappedSurfaceContext(proxy);
|
|
|
|
|
|
|
|
// Read pixels should work with a read-only texture.
|
|
|
|
SkAutoPixmapStorage read;
|
|
|
|
read.alloc(pixels.info());
|
|
|
|
auto readResult = surfContext->readPixels(pixels.info(), read.writable_addr(), 0, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, readResult);
|
|
|
|
if (readResult) {
|
|
|
|
comparePixels(pixels, read, reporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write pixels should not work with a read-only texture.
|
|
|
|
SkAutoPixmapStorage write;
|
|
|
|
write.alloc(pixels.info());
|
|
|
|
fillPixels(&write, [&pixels](int x, int y) { return ~*pixels.addr32(); });
|
|
|
|
auto writeResult = surfContext->writePixels(pixels.info(), pixels.addr(), 0, 0, 0);
|
|
|
|
REPORTER_ASSERT(reporter, writeResult == (ioType == kRW_GrIOType));
|
|
|
|
// Try the low level write.
|
|
|
|
context->flush();
|
|
|
|
auto gpuWriteResult = context->contextPriv().getGpu()->writePixels(
|
|
|
|
proxy->peekTexture(), 0, 0, kSize, kSize, GrColorType::kRGBA_8888, write.addr32(),
|
|
|
|
0);
|
|
|
|
REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType));
|
|
|
|
|
|
|
|
// Copies should not work with a read-only texture
|
|
|
|
auto copySrc = proxyProvider->createTextureProxy(
|
|
|
|
SkImage::MakeFromRaster(write, nullptr, nullptr), kNone_GrSurfaceFlags, 1,
|
|
|
|
SkBudgeted::kYes, SkBackingFit::kExact);
|
|
|
|
REPORTER_ASSERT(reporter, copySrc);
|
|
|
|
auto copyResult = surfContext->copy(copySrc.get());
|
|
|
|
REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType));
|
|
|
|
// Try the low level copy.
|
|
|
|
context->flush();
|
|
|
|
auto gpuCopyResult = context->contextPriv().getGpu()->copySurface(
|
|
|
|
proxy->peekTexture(), kTopLeft_GrSurfaceOrigin, copySrc->peekTexture(),
|
|
|
|
kTopLeft_GrSurfaceOrigin, SkIRect::MakeWH(kSize, kSize), {0, 0});
|
|
|
|
REPORTER_ASSERT(reporter, gpuCopyResult == (ioType == kRW_GrIOType));
|
|
|
|
|
|
|
|
// Mip regen should not work with a read only texture.
|
|
|
|
if (context->contextPriv().caps()->mipMapSupport()) {
|
|
|
|
backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
|
|
|
|
nullptr, kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kYes);
|
|
|
|
proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
|
2019-01-24 21:03:07 +00:00
|
|
|
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
|
|
|
|
ioType);
|
2018-12-06 15:00:03 +00:00
|
|
|
context->flush();
|
|
|
|
proxy->peekTexture()->texturePriv().markMipMapsDirty(); // avoids assert in GrGpu.
|
|
|
|
auto regenResult =
|
|
|
|
context->contextPriv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
|
|
|
|
REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-19 20:42:06 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST(TextureIdleProcTest, reporter, options) {
|
|
|
|
static const int kS = 10;
|
|
|
|
|
|
|
|
// Helper to delete a backend texture in a GrTexture's release proc.
|
|
|
|
static const auto installBackendTextureReleaseProc = [](GrTexture* texture) {
|
|
|
|
auto backendTexture = texture->getBackendTexture();
|
|
|
|
auto context = texture->getContext();
|
|
|
|
struct ReleaseContext {
|
|
|
|
GrContext* fContext;
|
|
|
|
GrBackendTexture fBackendTexture;
|
|
|
|
};
|
|
|
|
auto release = [](void* rc) {
|
|
|
|
auto releaseContext = static_cast<ReleaseContext*>(rc);
|
|
|
|
if (!releaseContext->fContext->abandoned()) {
|
|
|
|
if (auto gpu = releaseContext->fContext->contextPriv().getGpu()) {
|
|
|
|
gpu->deleteTestingOnlyBackendTexture(releaseContext->fBackendTexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete releaseContext;
|
|
|
|
};
|
|
|
|
texture->setRelease(sk_make_sp<GrReleaseProcHelper>(
|
|
|
|
release, new ReleaseContext{context, backendTexture}));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Various ways of making textures.
|
|
|
|
auto makeWrapped = [](GrContext* context) {
|
|
|
|
auto backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
|
|
|
|
nullptr, kS, kS, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
|
|
|
|
auto texture = context->contextPriv().resourceProvider()->wrapBackendTexture(
|
2019-01-24 21:03:07 +00:00
|
|
|
backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
|
2018-12-19 20:42:06 +00:00
|
|
|
installBackendTextureReleaseProc(texture.get());
|
|
|
|
return texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto makeWrappedRenderable = [](GrContext* context) {
|
|
|
|
auto backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
|
|
|
|
nullptr, kS, kS, GrColorType::kRGBA_8888, true, GrMipMapped::kNo);
|
|
|
|
auto texture = context->contextPriv().resourceProvider()->wrapRenderableBackendTexture(
|
2019-01-24 21:03:07 +00:00
|
|
|
backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
|
2018-12-19 20:42:06 +00:00
|
|
|
installBackendTextureReleaseProc(texture.get());
|
|
|
|
return texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto makeNormal = [](GrContext* context) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fWidth = desc.fHeight = kS;
|
|
|
|
return context->contextPriv().resourceProvider()->createTexture(desc, SkBudgeted::kNo);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto makeRenderable = [](GrContext* context) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
desc.fWidth = desc.fHeight = kS;
|
|
|
|
return context->contextPriv().resourceProvider()->createTexture(desc, SkBudgeted::kNo);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::function<sk_sp<GrTexture>(GrContext*)> makers[] = {makeWrapped, makeWrappedRenderable,
|
|
|
|
makeNormal, makeRenderable};
|
|
|
|
|
|
|
|
// Add a unique key, or not.
|
|
|
|
auto addKey = [](GrTexture* texture) {
|
|
|
|
static uint32_t gN = 0;
|
|
|
|
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
|
|
|
|
GrUniqueKey key;
|
|
|
|
GrUniqueKey::Builder builder(&key, kDomain, 1);
|
|
|
|
builder[0] = gN++;
|
|
|
|
builder.finish();
|
|
|
|
texture->resourcePriv().setUniqueKey(key);
|
|
|
|
};
|
|
|
|
auto dontAddKey = [](GrTexture* texture) {};
|
|
|
|
std::function<void(GrTexture*)> keyAdders[] = {addKey, dontAddKey};
|
|
|
|
|
|
|
|
for (const auto& m : makers) {
|
|
|
|
for (const auto& keyAdder : keyAdders) {
|
|
|
|
for (int type = 0; type < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++type) {
|
|
|
|
sk_gpu_test::GrContextFactory factory;
|
|
|
|
auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(type);
|
2019-01-24 17:18:33 +00:00
|
|
|
GrContext* context = factory.get(contextType);
|
2018-12-19 20:42:06 +00:00
|
|
|
if (!context) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback we add simply adds an integer to a set.
|
|
|
|
std::set<int> idleIDs;
|
|
|
|
struct Context {
|
|
|
|
std::set<int>* fIdleIDs;
|
|
|
|
int fNum;
|
|
|
|
};
|
|
|
|
auto proc = [](void* context) {
|
|
|
|
static_cast<Context*>(context)->fIdleIDs->insert(
|
|
|
|
static_cast<Context*>(context)->fNum);
|
|
|
|
delete static_cast<Context*>(context);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Makes a texture, possibly adds a key, and sets the callback.
|
|
|
|
auto make = [&m, &keyAdder, &proc, &idleIDs](GrContext* context, int num) {
|
|
|
|
sk_sp<GrTexture> texture = m(context);
|
|
|
|
texture->setIdleProc(proc, new Context{&idleIDs, num});
|
|
|
|
keyAdder(texture.get());
|
|
|
|
return texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto texture = make(context, 1);
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(1) == idleIDs.end());
|
|
|
|
bool isRT = SkToBool(texture->asRenderTarget());
|
|
|
|
auto backendFormat = texture->backendFormat();
|
|
|
|
texture.reset();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(1) != idleIDs.end());
|
|
|
|
|
|
|
|
texture = make(context, 2);
|
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr);
|
|
|
|
auto rtc = rt->getCanvas()->internal_private_accessTopLayerRenderTargetContext();
|
|
|
|
auto singleUseLazyCB = [&texture](GrResourceProvider* rp) {
|
|
|
|
return rp ? std::move(texture) : nullptr;
|
|
|
|
};
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = desc.fHeight = kS;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
if (isRT) {
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
}
|
2019-01-24 20:58:58 +00:00
|
|
|
SkBudgeted budgeted;
|
|
|
|
if (texture->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) {
|
|
|
|
budgeted = SkBudgeted::kYes;
|
|
|
|
} else {
|
|
|
|
budgeted = SkBudgeted::kNo;
|
|
|
|
}
|
2018-12-19 20:42:06 +00:00
|
|
|
auto proxy = context->contextPriv().proxyProvider()->createLazyProxy(
|
|
|
|
singleUseLazyCB, backendFormat, desc,
|
|
|
|
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
|
|
|
|
GrInternalSurfaceFlags ::kNone, SkBackingFit::kExact, budgeted,
|
|
|
|
GrSurfaceProxy::LazyInstantiationType::kSingleUse);
|
|
|
|
rtc->drawTexture(GrNoClip(), proxy, GrSamplerState::Filter::kNearest, SkPMColor4f(),
|
|
|
|
SkRect::MakeWH(kS, kS), SkRect::MakeWH(kS, kS),
|
|
|
|
GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkMatrix::I(), nullptr);
|
|
|
|
// We still have the proxy, which should remain instantiated, thereby keeping the
|
|
|
|
// texture not purgeable.
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end());
|
|
|
|
context->flush();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end());
|
|
|
|
context->contextPriv().getGpu()->testingOnly_flushGpuAndSync();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end());
|
|
|
|
|
|
|
|
// This time we move the proxy into the draw.
|
|
|
|
rtc->drawTexture(GrNoClip(), std::move(proxy), GrSamplerState::Filter::kNearest,
|
|
|
|
SkPMColor4f(), SkRect::MakeWH(kS, kS), SkRect::MakeWH(kS, kS),
|
|
|
|
GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkMatrix::I(), nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(2) == idleIDs.end());
|
|
|
|
context->flush();
|
|
|
|
context->contextPriv().getGpu()->testingOnly_flushGpuAndSync();
|
|
|
|
// Now that the draw is fully consumed by the GPU, the texture should be idle.
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(2) != idleIDs.end());
|
|
|
|
|
|
|
|
// Make a proxy that should deinstantiate even if we keep a ref on it.
|
|
|
|
auto deinstantiateLazyCB = [&make, &context](GrResourceProvider* rp) {
|
|
|
|
return rp ? make(context, 3) : nullptr;
|
|
|
|
};
|
|
|
|
proxy = context->contextPriv().proxyProvider()->createLazyProxy(
|
|
|
|
deinstantiateLazyCB, backendFormat, desc,
|
|
|
|
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
|
|
|
|
GrInternalSurfaceFlags ::kNone, SkBackingFit::kExact, budgeted,
|
|
|
|
GrSurfaceProxy::LazyInstantiationType::kDeinstantiate);
|
|
|
|
rtc->drawTexture(GrNoClip(), std::move(proxy), GrSamplerState::Filter::kNearest,
|
|
|
|
SkPMColor4f(), SkRect::MakeWH(kS, kS), SkRect::MakeWH(kS, kS),
|
|
|
|
GrQuadAAFlags::kNone, SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkMatrix::I(), nullptr);
|
|
|
|
// At this point the proxy shouldn't even be instantiated, there is no texture with
|
|
|
|
// id 3.
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(3) == idleIDs.end());
|
|
|
|
context->flush();
|
|
|
|
context->contextPriv().getGpu()->testingOnly_flushGpuAndSync();
|
|
|
|
// Now that the draw is fully consumed, we should have deinstantiated the proxy and
|
|
|
|
// the texture it made should be idle.
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(3) != idleIDs.end());
|
|
|
|
|
2019-01-24 17:18:33 +00:00
|
|
|
// Make sure we make the call during various shutdown scenarios where the texture
|
|
|
|
// might persist after context is destroyed, abandoned, etc. We test three
|
|
|
|
// variations of each scenario. One where the texture is just created. Another,
|
|
|
|
// where the texture has been used in a draw and then the context is flushed. And
|
|
|
|
// one where the the texture was drawn but the context is not flushed.
|
|
|
|
// In each scenario we test holding a ref beyond the context shutdown and not.
|
|
|
|
|
|
|
|
// These tests are difficult to get working with Vulkan. See http://skbug.com/8705
|
|
|
|
// and http://skbug.com/8275
|
|
|
|
GrBackendApi api = sk_gpu_test::GrContextFactory::ContextTypeBackend(contextType);
|
|
|
|
if (api == GrBackendApi::kVulkan) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int id = 4;
|
|
|
|
enum class DrawType {
|
|
|
|
kNoDraw,
|
|
|
|
kDraw,
|
|
|
|
kDrawAndFlush,
|
|
|
|
};
|
|
|
|
for (auto drawType :
|
|
|
|
{DrawType::kNoDraw, DrawType::kDraw, DrawType::kDrawAndFlush}) {
|
|
|
|
for (bool unrefFirst : {false, true}) {
|
|
|
|
auto possiblyDrawAndFlush = [&context, &texture, drawType, unrefFirst] {
|
|
|
|
if (drawType == DrawType::kNoDraw) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkImageInfo info = SkImageInfo::Make(kS, kS, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
auto rt = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0,
|
|
|
|
nullptr);
|
|
|
|
auto rtc =
|
|
|
|
rt->getCanvas()
|
|
|
|
->internal_private_accessTopLayerRenderTargetContext();
|
|
|
|
auto proxy = context->contextPriv()
|
|
|
|
.proxyProvider()
|
|
|
|
->testingOnly_createWrapped(
|
|
|
|
texture, kTopLeft_GrSurfaceOrigin);
|
|
|
|
rtc->drawTexture(GrNoClip(), proxy, GrSamplerState::Filter::kNearest,
|
|
|
|
SkPMColor4f(), SkRect::MakeWH(kS, kS),
|
|
|
|
SkRect::MakeWH(kS, kS), GrQuadAAFlags::kNone,
|
|
|
|
SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(),
|
|
|
|
nullptr);
|
|
|
|
if (drawType == DrawType::kDrawAndFlush) {
|
|
|
|
context->flush();
|
|
|
|
}
|
|
|
|
if (unrefFirst) {
|
|
|
|
texture.reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
texture = make(context, id);
|
|
|
|
possiblyDrawAndFlush();
|
|
|
|
context->abandonContext();
|
|
|
|
texture.reset();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end());
|
|
|
|
factory.destroyContexts();
|
|
|
|
context = factory.get(contextType);
|
|
|
|
++id;
|
|
|
|
|
|
|
|
// Similar to previous, but reset the texture after the context was
|
|
|
|
// abandoned and then destroyed.
|
|
|
|
texture = make(context, id);
|
|
|
|
possiblyDrawAndFlush();
|
|
|
|
context->abandonContext();
|
|
|
|
factory.destroyContexts();
|
|
|
|
texture.reset();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end());
|
|
|
|
context = factory.get(contextType);
|
|
|
|
id++;
|
|
|
|
|
|
|
|
texture = make(context, id);
|
|
|
|
possiblyDrawAndFlush();
|
|
|
|
factory.destroyContexts();
|
|
|
|
texture.reset();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end());
|
|
|
|
context = factory.get(contextType);
|
|
|
|
id++;
|
|
|
|
|
|
|
|
texture = make(context, id);
|
|
|
|
possiblyDrawAndFlush();
|
|
|
|
factory.releaseResourcesAndAbandonContexts();
|
|
|
|
texture.reset();
|
|
|
|
REPORTER_ASSERT(reporter, idleIDs.find(id) != idleIDs.end());
|
|
|
|
context = factory.get(contextType);
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
}
|
2018-12-19 20:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|