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.
|
|
|
|
*/
|
|
|
|
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2020-12-23 14:16:59 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2020-01-27 21:11:57 +00:00
|
|
|
#include "src/core/SkCompressedDataUtils.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrBackendUtils.h"
|
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrGpu.h"
|
|
|
|
#include "src/gpu/ganesh/GrImageInfo.h"
|
|
|
|
#include "src/gpu/ganesh/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/ganesh/GrRenderTarget.h"
|
|
|
|
#include "src/gpu/ganesh/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/ganesh/GrTexture.h"
|
|
|
|
#include "src/gpu/ganesh/SkGr.h"
|
|
|
|
#include "src/gpu/ganesh/SurfaceContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/BackendTextureImageFactory.h"
|
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2022-04-05 16:56:01 +00:00
|
|
|
#include <set>
|
|
|
|
|
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.
|
2019-04-03 16:04:45 +00:00
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
auto resourceProvider = context->priv().resourceProvider();
|
2018-01-16 20:07:54 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDesc = {256, 256};
|
2019-08-05 16:58:39 +00:00
|
|
|
auto format = context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kYes);
|
2022-05-03 20:00:24 +00:00
|
|
|
sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(kDesc,
|
|
|
|
format,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
GrRenderable::kYes,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{});
|
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
|
|
|
|
2022-05-03 20:00:24 +00:00
|
|
|
sk_sp<GrTexture> tex1 = resourceProvider->createTexture(kDesc,
|
|
|
|
format,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{});
|
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
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture backendTex = context->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
256, 256, kRGBA_8888_SkColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
|
2015-11-10 19:54:56 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture(
|
2020-03-27 14:42:15 +00:00
|
|
|
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
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2013-04-09 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 18:23:53 +00:00
|
|
|
// This test checks that the isFormatTexturable and isFormatRenderable are
|
2017-05-22 17:23:19 +00:00
|
|
|
// consistent with createTexture's result.
|
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
// TODO: Should only need format here but need to determine compression type from format
|
|
|
|
// without config.
|
2019-12-16 19:20:53 +00:00
|
|
|
auto createTexture = [](SkISize dimensions, GrColorType colorType,
|
2019-08-05 16:58:39 +00:00
|
|
|
const GrBackendFormat& format, GrRenderable renderable,
|
2019-06-27 14:52:13 +00:00
|
|
|
GrResourceProvider* rp) -> sk_sp<GrTexture> {
|
2020-06-12 20:58:17 +00:00
|
|
|
SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);
|
2019-12-13 16:17:46 +00:00
|
|
|
if (compression != SkImage::CompressionType::kNone) {
|
2019-06-27 14:52:13 +00:00
|
|
|
if (renderable == GrRenderable::kYes) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-01-27 21:11:57 +00:00
|
|
|
auto size = SkCompressedDataSize(compression, dimensions, nullptr, false);
|
2019-06-27 14:52:13 +00:00
|
|
|
auto data = SkData::MakeUninitialized(size);
|
|
|
|
SkColor4f color = {0, 0, 0, 0};
|
2020-07-21 13:27:25 +00:00
|
|
|
GrFillInCompressedData(compression, dimensions, GrMipmapped::kNo,
|
2019-12-16 19:20:53 +00:00
|
|
|
(char*)data->writable_data(), color);
|
2022-05-03 20:00:24 +00:00
|
|
|
return rp->createCompressedTexture(dimensions,
|
|
|
|
format,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
data.get(),
|
|
|
|
/*label=*/{});
|
2019-06-27 14:52:13 +00:00
|
|
|
} else {
|
2022-05-03 20:00:24 +00:00
|
|
|
return rp->createTexture(dimensions,
|
|
|
|
format,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
renderable,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{});
|
2019-06-27 14:52:13 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDims = {64, 64};
|
2019-07-09 16:34:38 +00:00
|
|
|
|
2019-08-01 14:08:07 +00:00
|
|
|
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
|
2020-07-31 00:24:57 +00:00
|
|
|
caps->getTestingCombinations();
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
|
2019-07-16 11:47:56 +00:00
|
|
|
|
2019-08-01 14:08:07 +00:00
|
|
|
SkASSERT(combo.fColorType != GrColorType::kUnknown);
|
|
|
|
SkASSERT(combo.fFormat.isValid());
|
|
|
|
|
|
|
|
// Right now Vulkan has two backend formats that support ABGR_4444 (R4G4B4A4 and B4G4R4A4).
|
|
|
|
// Until we can create textures directly from the backend format this yields some
|
|
|
|
// ambiguity in what is actually supported and which textures can be created.
|
|
|
|
if (ctxInfo.backend() == kVulkan_GrBackend && combo.fColorType == GrColorType::kABGR_4444) {
|
2019-07-16 11:47:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
// Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap
|
|
|
|
// support check is working
|
|
|
|
{
|
|
|
|
bool isCompressed = caps->isFormatCompressed(combo.fFormat);
|
2021-08-13 20:20:18 +00:00
|
|
|
bool isTexturable = caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D);
|
2019-12-16 18:40:51 +00:00
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrSurface> tex = createTexture(kDims, combo.fColorType, combo.fFormat,
|
|
|
|
GrRenderable::kNo, resourceProvider);
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == isTexturable,
|
|
|
|
"ct:%s format:%s, tex:%d, isTexturable:%d",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
SkToBool(tex), isTexturable);
|
|
|
|
|
|
|
|
// Check that the lack of mipmap support blocks the creation of mipmapped
|
|
|
|
// proxies
|
2020-07-21 14:49:25 +00:00
|
|
|
bool expectedMipMapability = isTexturable && caps->mipmapSupport() && !isCompressed;
|
2020-02-14 15:47:18 +00:00
|
|
|
|
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
|
2020-07-21 13:27:25 +00:00
|
|
|
combo.fFormat, kDims, GrRenderable::kNo, 1, GrMipmapped::kYes,
|
2022-05-26 15:24:19 +00:00
|
|
|
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
|
2020-02-14 15:47:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(proxy.get()) == expectedMipMapability,
|
|
|
|
"ct:%s format:%s, tex:%d, expectedMipMapability:%d",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
SkToBool(proxy.get()), expectedMipMapability);
|
|
|
|
}
|
2019-08-14 18:23:53 +00:00
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' (w/o MSAA)
|
|
|
|
{
|
|
|
|
bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1);
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2022-05-03 20:00:24 +00:00
|
|
|
sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
|
|
|
|
combo.fFormat,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
GrRenderable::kYes,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{});
|
2020-02-14 15:47:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
|
|
|
|
"ct:%s format:%s, tex:%d, isRenderable:%d",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
SkToBool(tex), isRenderable);
|
|
|
|
}
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' w/ MSAA
|
|
|
|
{
|
|
|
|
bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2);
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2022-05-03 20:00:24 +00:00
|
|
|
sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
|
|
|
|
combo.fFormat,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
GrRenderable::kYes,
|
|
|
|
2,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{});
|
2020-02-14 15:47:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
|
|
|
|
"ct:%s format:%s, tex:%d, isRenderable:%d",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
SkToBool(tex), isRenderable);
|
2017-05-22 17:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/ganesh/GrSurfaceProxy.h"
|
2017-05-23 20:53:47 +00:00
|
|
|
|
2019-08-01 14:08:07 +00:00
|
|
|
// For each context, set it to always clear the textures and then run through all the
|
|
|
|
// supported formats checking that the textures are actually cleared
|
2019-07-16 15:52:08 +00:00
|
|
|
DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
|
|
|
|
GrContextOptions options = baseOptions;
|
|
|
|
options.fClearAllTextures = true;
|
2019-08-02 16:26:22 +00:00
|
|
|
|
2017-05-23 20:53:47 +00:00
|
|
|
static constexpr int kSize = 100;
|
2019-08-02 16:26:22 +00:00
|
|
|
static constexpr SkColor kClearColor = 0xABABABAB;
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2021-08-11 19:42:39 +00:00
|
|
|
const SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2019-08-02 16:26:22 +00:00
|
|
|
SkAutoPixmapStorage readback;
|
2021-08-11 19:42:39 +00:00
|
|
|
readback.alloc(imageInfo);
|
2019-08-02 16:26:22 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
SkISize desc;
|
2019-08-01 14:08:07 +00:00
|
|
|
desc.fWidth = desc.fHeight = kSize;
|
|
|
|
|
2019-07-16 15:52:08 +00:00
|
|
|
for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
|
|
|
|
sk_gpu_test::GrContextFactory factory(options);
|
|
|
|
auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
|
|
|
|
if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-11 16:02:22 +00:00
|
|
|
auto dContext = factory.get(contextType);
|
|
|
|
if (!dContext) {
|
2017-05-23 20:53:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-07-16 15:52:08 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
|
|
|
const GrCaps* caps = dContext->priv().caps();
|
2019-07-16 15:52:08 +00:00
|
|
|
|
2019-08-01 14:08:07 +00:00
|
|
|
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
|
2020-07-31 00:24:57 +00:00
|
|
|
caps->getTestingCombinations();
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
|
2019-08-01 14:08:07 +00:00
|
|
|
|
|
|
|
SkASSERT(combo.fColorType != GrColorType::kUnknown);
|
|
|
|
SkASSERT(combo.fFormat.isValid());
|
|
|
|
|
2021-08-13 20:20:18 +00:00
|
|
|
if (!caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D)) {
|
2017-05-23 20:53:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2019-09-26 15:04:28 +00:00
|
|
|
auto checkColor = [reporter](const GrCaps::TestFormatColorTypeCombination& combo,
|
|
|
|
uint32_t readColor) {
|
|
|
|
// We expect that if there is no alpha in the src color type and we read it to a
|
|
|
|
// color type with alpha that we will get one for alpha rather than zero. We used to
|
|
|
|
// require this but the Intel Iris 6100 on Win 10 test bot doesn't put one in the
|
|
|
|
// alpha channel when reading back from GL_RG16 or GL_RG16F. So now we allow either.
|
2020-03-26 20:17:56 +00:00
|
|
|
uint32_t channels = GrColorTypeChannelFlags(combo.fColorType);
|
|
|
|
bool allowAlphaOne = !(channels & kAlpha_SkColorChannelFlag);
|
2019-09-26 15:04:28 +00:00
|
|
|
if (allowAlphaOne) {
|
|
|
|
if (readColor != 0x00000000 && readColor != 0xFF000000) {
|
|
|
|
ERRORF(reporter,
|
|
|
|
"Failed on ct %s format %s 0x%08x is not 0x00000000 or 0xFF000000",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
readColor);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (readColor) {
|
|
|
|
ERRORF(reporter, "Failed on ct %s format %s 0x%08x != 0x00000000",
|
|
|
|
GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
|
|
|
|
readColor);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2019-07-17 13:59:59 +00:00
|
|
|
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
|
2019-08-01 14:08:07 +00:00
|
|
|
if (renderable == GrRenderable::kYes &&
|
2019-08-06 16:05:31 +00:00
|
|
|
!caps->isFormatAsColorTypeRenderable(combo.fColorType, combo.fFormat)) {
|
2019-07-16 15:52:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-08-01 14:08:07 +00:00
|
|
|
|
|
|
|
for (auto fit : {SkBackingFit::kApprox, SkBackingFit::kExact}) {
|
|
|
|
|
|
|
|
// Does directly allocating a texture clear it?
|
|
|
|
{
|
2018-09-27 15:28:03 +00:00
|
|
|
auto proxy = proxyProvider->testingOnly_createInstantiatedProxy(
|
2020-03-27 00:37:01 +00:00
|
|
|
{kSize, kSize}, combo.fFormat, renderable, 1, fit, SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
2019-08-01 14:08:07 +00:00
|
|
|
if (proxy) {
|
2022-02-15 21:30:59 +00:00
|
|
|
skgpu::Swizzle swizzle = caps->getReadSwizzle(combo.fFormat,
|
|
|
|
combo.fColorType);
|
2020-01-14 14:56:04 +00:00
|
|
|
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
|
|
|
|
swizzle);
|
2020-12-07 17:19:47 +00:00
|
|
|
GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr);
|
2021-08-02 15:14:38 +00:00
|
|
|
auto texCtx = dContext->priv().makeSC(std::move(view), info);
|
2019-08-01 14:08:07 +00:00
|
|
|
|
2019-08-02 16:26:22 +00:00
|
|
|
readback.erase(kClearColor);
|
2020-12-24 01:36:44 +00:00
|
|
|
if (texCtx->readPixels(dContext, readback, {0, 0})) {
|
2019-08-01 14:08:07 +00:00
|
|
|
for (int i = 0; i < kSize * kSize; ++i) {
|
2019-09-26 15:04:28 +00:00
|
|
|
if (!checkColor(combo, readback.addr32()[i])) {
|
2019-08-01 14:08:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 11:47:56 +00:00
|
|
|
|
2021-06-10 00:49:48 +00:00
|
|
|
dContext->priv().getResourceCache()->purgeUnlockedResources();
|
2019-08-01 14:08:07 +00:00
|
|
|
}
|
2019-07-16 11:47:56 +00:00
|
|
|
|
2019-08-01 14:08:07 +00:00
|
|
|
// Try creating the texture as a deferred proxy.
|
|
|
|
{
|
2021-07-29 15:23:48 +00:00
|
|
|
GrImageInfo info(combo.fColorType,
|
|
|
|
GrColorTypeHasAlpha(combo.fColorType)
|
|
|
|
? kPremul_SkAlphaType
|
|
|
|
: kOpaque_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
{desc.fHeight, desc.fHeight});
|
|
|
|
|
2021-08-16 15:41:27 +00:00
|
|
|
auto sc = dContext->priv().makeSC(info,
|
|
|
|
combo.fFormat,
|
|
|
|
fit,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
renderable);
|
2021-07-29 15:23:48 +00:00
|
|
|
if (!sc) {
|
2017-09-25 16:26:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-07-16 15:52:08 +00:00
|
|
|
|
2019-08-02 16:26:22 +00:00
|
|
|
readback.erase(kClearColor);
|
2021-07-29 15:23:48 +00:00
|
|
|
if (sc->readPixels(dContext, readback, {0, 0})) {
|
2019-08-01 14:08:07 +00:00
|
|
|
for (int i = 0; i < kSize * kSize; ++i) {
|
2019-09-26 15:04:28 +00:00
|
|
|
if (!checkColor(combo, readback.addr32()[i])) {
|
2019-08-01 14:08:07 +00:00
|
|
|
break;
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-25 16:26:58 +00:00
|
|
|
}
|
2021-06-10 00:49:48 +00:00
|
|
|
dContext->priv().getResourceCache()->purgeUnlockedResources();
|
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) {
|
2019-06-10 19:09:34 +00:00
|
|
|
auto fillPixels = [](SkPixmap* p, const std::function<uint32_t(int x, int y)>& f) {
|
2018-12-06 15:00:03 +00:00
|
|
|
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;
|
2019-07-23 17:44:16 +00:00
|
|
|
SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkAutoPixmapStorage srcPixmap;
|
|
|
|
srcPixmap.alloc(ii);
|
|
|
|
fillPixels(&srcPixmap,
|
2019-06-10 19:09:34 +00:00
|
|
|
[](int x, int y) {
|
|
|
|
return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t((x * y) & 0xFF);
|
|
|
|
});
|
2018-12-06 15:00:03 +00:00
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
auto dContext = context_info.directContext();
|
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
2018-12-06 15:00:03 +00:00
|
|
|
|
|
|
|
// 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}) {
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(
|
2020-12-07 16:30:16 +00:00
|
|
|
dContext, srcPixmap, kTopLeft_GrSurfaceOrigin, GrRenderable::kNo, GrProtected::kNo);
|
2020-11-05 16:11:20 +00:00
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not make texture.");
|
|
|
|
return;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, ioType,
|
|
|
|
mbet->refCountedCallback());
|
2022-02-15 21:30:59 +00:00
|
|
|
skgpu::Swizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
|
|
|
|
GrColorType::kRGBA_8888);
|
2020-01-14 14:56:04 +00:00
|
|
|
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
|
2021-08-02 15:14:38 +00:00
|
|
|
auto surfContext = dContext->priv().makeSC(std::move(view), ii.colorInfo());
|
2018-12-06 15:00:03 +00:00
|
|
|
// Read pixels should work with a read-only texture.
|
2019-07-23 17:44:16 +00:00
|
|
|
{
|
|
|
|
SkAutoPixmapStorage read;
|
|
|
|
read.alloc(srcPixmap.info());
|
2020-12-24 01:36:44 +00:00
|
|
|
auto readResult = surfContext->readPixels(dContext, read, {0, 0});
|
2019-07-23 17:44:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, readResult);
|
|
|
|
if (readResult) {
|
|
|
|
comparePixels(srcPixmap, read, reporter);
|
|
|
|
}
|
2018-12-06 15:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write pixels should not work with a read-only texture.
|
|
|
|
SkAutoPixmapStorage write;
|
2019-07-23 17:44:16 +00:00
|
|
|
write.alloc(srcPixmap.info());
|
|
|
|
fillPixels(&write, [&srcPixmap](int x, int y) { return ~*srcPixmap.addr32(); });
|
2020-12-24 01:36:44 +00:00
|
|
|
auto writeResult = surfContext->writePixels(dContext, write, {0, 0});
|
2018-12-06 15:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, writeResult == (ioType == kRW_GrIOType));
|
|
|
|
// Try the low level write.
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->flushAndSubmit();
|
|
|
|
auto gpuWriteResult = dContext->priv().getGpu()->writePixels(
|
2021-05-24 16:40:46 +00:00
|
|
|
proxy->peekTexture(),
|
|
|
|
SkIRect::MakeWH(kSize, kSize),
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
write.addr32(),
|
|
|
|
kSize*GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888));
|
2018-12-06 15:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType));
|
|
|
|
|
2020-01-28 22:02:49 +00:00
|
|
|
SkBitmap copySrcBitmap;
|
|
|
|
copySrcBitmap.installPixels(write);
|
|
|
|
copySrcBitmap.setImmutable();
|
|
|
|
|
2021-04-28 16:39:21 +00:00
|
|
|
auto copySrc = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, copySrcBitmap));
|
2020-01-28 22:02:49 +00:00
|
|
|
|
2021-04-28 16:39:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, copySrc);
|
2021-01-21 15:43:35 +00:00
|
|
|
auto copyResult = surfContext->testCopy(copySrc.refProxy());
|
2018-12-06 15:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType));
|
|
|
|
// Try the low level copy.
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->flushAndSubmit();
|
|
|
|
auto gpuCopyResult = dContext->priv().getGpu()->copySurface(
|
2020-02-03 19:17:08 +00:00
|
|
|
proxy->peekSurface(), copySrc.proxy()->peekSurface(), SkIRect::MakeWH(kSize, kSize),
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
Reason for revert: Landing with neuxs 7 and androind one fixes
Original change's description:
> Revert "Reland "Remove support for copyAsDraw in gpu copySurface.""
>
> This reverts commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > Reason for revert: seems to break things?
> > >
> > > Original change's description:
> > > > Remove support for copyAsDraw in gpu copySurface.
> > > >
> > > > The major changes on a higher lever are:
> > > > 1) The majority of all copies now go through GrSurfaceProxy::Copy which
> > > > takes in a proxy and returns a new one with the data copied to it. This
> > > > is the most common use case within Ganesh.
> > > >
> > > > 2) The backend copy calls no longer do draws, require origins to be the
> > > > same, and won't do any swizzling or adjustment of subrects. They are
> > > > all implemented to be dumb copy this data to this other spot.
> > > >
> > > > 3) The GrSurfaceContext copy call has now been moved to priv and renamed
> > > > copyNoDraw, and a new priv copyAsDraw was added to GrRenderTargetContext.
> > > >
> > > > 4) WritePixels and ReplaceRenderTarget both need to specifiy the destination
> > > > of copies. They are the only users (besides the GrSurfaceProxy::Copy) which
> > > > call the priv methods on GrSurfaceContext.
> > > >
> > > > Change-Id: Iaf1eb3a73ccaf39a75af77e281dae594f809186f
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217459
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: Id43aa8aa1451e794342e930441d9975b90e6b59f
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218549
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> >
> > Change-Id: I1a96f85ae2ff7622a6b57406755d478e7fbcf56e
> > No-Presubmit: true
> > No-Tree-Checks: true
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218797
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
>
> Change-Id: I310930a9df30535f45a065263a40239141e15562
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219384
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
Change-Id: I88df4f19aa26ed77b5af4e25d138387cbabd1934
No-Presubmit: true
No-Tree-Checks: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219386
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2019-06-07 15:43:30 +00:00
|
|
|
{0, 0});
|
2018-12-06 15:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpuCopyResult == (ioType == kRW_GrIOType));
|
|
|
|
|
|
|
|
// Mip regen should not work with a read only texture.
|
2020-08-11 16:02:22 +00:00
|
|
|
if (dContext->priv().caps()->mipmapSupport()) {
|
2020-10-13 00:45:06 +00:00
|
|
|
mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
kSize,
|
|
|
|
kSize,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
GrMipmapped::kYes,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
|
|
|
proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, ioType,
|
|
|
|
mbet->refCountedCallback());
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->flushAndSubmit();
|
2020-07-23 14:33:24 +00:00
|
|
|
proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu.
|
2018-12-06 15:00:03 +00:00
|
|
|
auto regenResult =
|
2020-08-11 16:02:22 +00:00
|
|
|
dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
|
2018-12-06 15:00:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|