skia2/tests/GrSurfaceTest.cpp

473 lines
24 KiB
C++
Raw Normal View History

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkColorSpace.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkCompressedDataUtils.h"
#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"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/gpu/BackendTextureImageFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <set>
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
// and render targets to GrSurface all work as expected.
Reland "Remove the NullGL interface (and associated test context)" This reverts commit 215da624d11340b254b5d17116bf20262f4ed69f. Reason for revert: Blink issues ironed out. Original change's description: > Revert "Remove the NullGL interface (and associated test context)" > > This reverts commit de206c75c2c802f6f1e4ccb8a6b8a00765e9f085. > > Reason for revert: Chrome is having issues with the switch to Mock in blink tests. > > Original change's description: > > Remove the NullGL interface (and associated test context) > > > > Bug: skia: > > Change-Id: Ie3c9ee39fc1e0a4406de085c60d8433ffb4419df > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/203708 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Brian Osman <brianosman@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com > > Change-Id: Iff0cbf29dcea26957efc800a8c33d0ad8285de0a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/205343 > Reviewed-by: Brian Osman <brianosman@google.com> > Commit-Queue: Brian Osman <brianosman@google.com> TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: I1f4fbbcb00f302c5d830cb1392badd6ec7a33c69 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/205832 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2019-04-03 16:04:45 +00:00
DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto resourceProvider = context->priv().resourceProvider();
static constexpr SkISize kDesc = {256, 256};
auto format = context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kYes);
sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(kDesc,
format,
GrTextureType::k2D,
GrRenderable::kYes,
1,
GrMipmapped::kNo,
SkBudgeted::kNo,
GrProtected::kNo,
/*label=*/{});
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
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()));
sk_sp<GrTexture> tex1 = resourceProvider->createTexture(kDesc,
format,
GrTextureType::k2D,
GrRenderable::kNo,
1,
GrMipmapped::kNo,
SkBudgeted::kNo,
GrProtected::kNo,
/*label=*/{});
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
GrBackendTexture backendTex = context->createBackendTexture(
256, 256, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
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
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
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()));
context->deleteBackendTexture(backendTex);
}
// This test checks that the isFormatTexturable and isFormatRenderable are
// consistent with createTexture's result.
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
const GrCaps* caps = context->priv().caps();
// TODO: Should only need format here but need to determine compression type from format
// without config.
auto createTexture = [](SkISize dimensions, GrColorType colorType,
const GrBackendFormat& format, GrRenderable renderable,
GrResourceProvider* rp) -> sk_sp<GrTexture> {
SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);
if (compression != SkImage::CompressionType::kNone) {
if (renderable == GrRenderable::kYes) {
return nullptr;
}
auto size = SkCompressedDataSize(compression, dimensions, nullptr, false);
auto data = SkData::MakeUninitialized(size);
SkColor4f color = {0, 0, 0, 0};
GrFillInCompressedData(compression, dimensions, GrMipmapped::kNo,
(char*)data->writable_data(), color);
return rp->createCompressedTexture(dimensions,
format,
SkBudgeted::kNo,
GrMipmapped::kNo,
GrProtected::kNo,
data.get(),
/*label=*/{});
} else {
return rp->createTexture(dimensions,
format,
GrTextureType::k2D,
renderable,
1,
GrMipmapped::kNo,
SkBudgeted::kNo,
GrProtected::kNo,
/*label=*/{});
}
};
static constexpr SkISize kDims = {64, 64};
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
caps->getTestingCombinations();
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
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) {
continue;
}
// Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap
// support check is working
{
bool isCompressed = caps->isFormatCompressed(combo.fFormat);
Reland "Remove GrBackendFormat's textureType use from isFormatTexturable call." This reverts commit d90777ada391dffa9a19101fe7917d0c13a606b3. Reason for revert: relanding with fix to GrBackendTexture Original change's description: > Revert "Remove GrBackendFormat's textureType use from isFormatTexturable call." > > This reverts commit 832c817bc8a9567aa379181e71e7c602d2480de8. > > Reason for revert: uninitialized value in GrBackendTexture > > Original change's description: > > Remove GrBackendFormat's textureType use from isFormatTexturable call. > > > > The goal of this change was to remove the use of GrBackendFormat::textureType() > > from GrCaps::isFormatTexturable call. Instead we will always pass in a > > GrTextureType into this call. > > > > To do this a lot of plumbing of GrTextureType was added to various call > > sites. However, this CL halts the plubming up at the proxy level where we > > get it from the GrBackendFormat still. Future CLs will continue removing > > these call sites and others that use GrBackendFormat::textureType(). > > > > Bug: skia:12342 > > Change-Id: Ic0f02b9c7f7402405623b8aa31aa32a9a7c22297 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439277 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com > > Change-Id: I354bbbf00be7a86c480009f3e7b36a8777a6bf3a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:12342 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439338 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:12342 Change-Id: I151196f149f9e191d2975b8fe81334f4f8720744 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439339 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-08-13 20:20:18 +00:00
bool isTexturable = caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D);
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
bool expectedMipMapability = isTexturable && caps->mipmapSupport() && !isCompressed;
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
combo.fFormat, kDims, GrRenderable::kNo, 1, GrMipmapped::kYes,
Revert "Reland "Create updateResourceLabel method."" This reverts commit 35ef74b7a4c5ac23fecea00fa71076bc1be4d8ac. Reason for revert: causing chrome roll failure? Original change's description: > Reland "Create updateResourceLabel method." > > This is a reland of commit 605f92c7d7f97d6edf152f6e9d0fc88f8cd8c700 > > Original change's description: > > Create updateResourceLabel method. > > > > In this CL, the GrSurfaceProxy's and GrDrawOpAtlas's label strings > > are plumbed so that it can be stored in the label string of > > GrGpuResource. updateResourceLabel method, which is called from > > setLabel method, will add labels to Skia OpenGL backend using ANGLE's > > labeling API. > > > > Bug: chromium:1164111 > > Change-Id: I370715d186357e920d260d624d77586cdddd11e8 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541230 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Bug: chromium:1164111 > Change-Id: Ia20a81d22e320813cbc4ad1d41e06e47dc3827bb > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544058 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> Bug: chromium:1164111 Change-Id: Icacb3a0f2f2ee03afc09e03c2ee59b03d5bdd811 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544241 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tyler Denniston <tdenniston@google.com>
2022-05-26 15:24:19 +00:00
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
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);
}
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' (w/o MSAA)
{
bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1);
sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
combo.fFormat,
GrTextureType::k2D,
GrRenderable::kYes,
1,
GrMipmapped::kNo,
SkBudgeted::kNo,
GrProtected::kNo,
/*label=*/{});
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);
}
// Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' w/ MSAA
{
bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2);
sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
combo.fFormat,
GrTextureType::k2D,
GrRenderable::kYes,
2,
GrMipmapped::kNo,
SkBudgeted::kNo,
GrProtected::kNo,
/*label=*/{});
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);
}
}
}
#include "src/gpu/ganesh/GrDrawingManager.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
// 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
DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
GrContextOptions options = baseOptions;
options.fClearAllTextures = true;
static constexpr int kSize = 100;
static constexpr SkColor kClearColor = 0xABABABAB;
const SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
SkAutoPixmapStorage readback;
readback.alloc(imageInfo);
SkISize desc;
desc.fWidth = desc.fHeight = kSize;
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) {
continue;
}
2020-08-11 16:02:22 +00:00
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
const GrCaps* caps = dContext->priv().caps();
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
caps->getTestingCombinations();
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
SkASSERT(combo.fColorType != GrColorType::kUnknown);
SkASSERT(combo.fFormat.isValid());
Reland "Remove GrBackendFormat's textureType use from isFormatTexturable call." This reverts commit d90777ada391dffa9a19101fe7917d0c13a606b3. Reason for revert: relanding with fix to GrBackendTexture Original change's description: > Revert "Remove GrBackendFormat's textureType use from isFormatTexturable call." > > This reverts commit 832c817bc8a9567aa379181e71e7c602d2480de8. > > Reason for revert: uninitialized value in GrBackendTexture > > Original change's description: > > Remove GrBackendFormat's textureType use from isFormatTexturable call. > > > > The goal of this change was to remove the use of GrBackendFormat::textureType() > > from GrCaps::isFormatTexturable call. Instead we will always pass in a > > GrTextureType into this call. > > > > To do this a lot of plumbing of GrTextureType was added to various call > > sites. However, this CL halts the plubming up at the proxy level where we > > get it from the GrBackendFormat still. Future CLs will continue removing > > these call sites and others that use GrBackendFormat::textureType(). > > > > Bug: skia:12342 > > Change-Id: Ic0f02b9c7f7402405623b8aa31aa32a9a7c22297 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439277 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com > > Change-Id: I354bbbf00be7a86c480009f3e7b36a8777a6bf3a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:12342 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439338 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:12342 Change-Id: I151196f149f9e191d2975b8fe81334f4f8720744 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439339 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-08-13 20:20:18 +00:00
if (!caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D)) {
continue;
}
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.
uint32_t channels = GrColorTypeChannelFlags(combo.fColorType);
bool allowAlphaOne = !(channels & kAlpha_SkColorChannelFlag);
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;
};
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
if (renderable == GrRenderable::kYes &&
!caps->isFormatAsColorTypeRenderable(combo.fColorType, combo.fFormat)) {
continue;
}
for (auto fit : {SkBackingFit::kApprox, SkBackingFit::kExact}) {
// Does directly allocating a texture clear it?
{
auto proxy = proxyProvider->testingOnly_createInstantiatedProxy(
{kSize, kSize}, combo.fFormat, renderable, 1, fit, SkBudgeted::kYes,
GrProtected::kNo);
if (proxy) {
skgpu::Swizzle swizzle = caps->getReadSwizzle(combo.fFormat,
combo.fColorType);
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
swizzle);
GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr);
auto texCtx = dContext->priv().makeSC(std::move(view), info);
readback.erase(kClearColor);
if (texCtx->readPixels(dContext, readback, {0, 0})) {
for (int i = 0; i < kSize * kSize; ++i) {
if (!checkColor(combo, readback.addr32()[i])) {
break;
}
}
}
}
dContext->priv().getResourceCache()->purgeUnlockedResources();
}
// Try creating the texture as a deferred proxy.
{
GrImageInfo info(combo.fColorType,
GrColorTypeHasAlpha(combo.fColorType)
? kPremul_SkAlphaType
: kOpaque_SkAlphaType,
nullptr,
{desc.fHeight, desc.fHeight});
auto sc = dContext->priv().makeSC(info,
combo.fFormat,
fit,
kTopLeft_GrSurfaceOrigin,
renderable);
if (!sc) {
continue;
}
readback.erase(kClearColor);
if (sc->readPixels(dContext, readback, {0, 0})) {
for (int i = 0; i < kSize * kSize; ++i) {
if (!checkColor(combo, readback.addr32()[i])) {
break;
}
}
}
dContext->priv().getResourceCache()->purgeUnlockedResources();
}
}
}
}
}
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
auto fillPixels = [](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;
SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
SkAutoPixmapStorage srcPixmap;
srcPixmap.alloc(ii);
fillPixels(&srcPixmap,
[](int x, int y) {
return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t((x * y) & 0xFF);
});
2020-08-11 16:02:22 +00:00
auto dContext = context_info.directContext();
GrProxyProvider* proxyProvider = dContext->priv().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 mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(
dContext, srcPixmap, kTopLeft_GrSurfaceOrigin, GrRenderable::kNo, GrProtected::kNo);
if (!mbet) {
ERRORF(reporter, "Could not make texture.");
return;
}
auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType,
mbet->refCountedCallback());
skgpu::Swizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
auto surfContext = dContext->priv().makeSC(std::move(view), ii.colorInfo());
// Read pixels should work with a read-only texture.
{
SkAutoPixmapStorage read;
read.alloc(srcPixmap.info());
auto readResult = surfContext->readPixels(dContext, read, {0, 0});
REPORTER_ASSERT(reporter, readResult);
if (readResult) {
comparePixels(srcPixmap, read, reporter);
}
}
// Write pixels should not work with a read-only texture.
SkAutoPixmapStorage write;
write.alloc(srcPixmap.info());
fillPixels(&write, [&srcPixmap](int x, int y) { return ~*srcPixmap.addr32(); });
auto writeResult = surfContext->writePixels(dContext, write, {0, 0});
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(
proxy->peekTexture(),
SkIRect::MakeWH(kSize, kSize),
GrColorType::kRGBA_8888,
GrColorType::kRGBA_8888,
write.addr32(),
kSize*GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888));
REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType));
SkBitmap copySrcBitmap;
copySrcBitmap.installPixels(write);
copySrcBitmap.setImmutable();
auto copySrc = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, copySrcBitmap));
REPORTER_ASSERT(reporter, copySrc);
auto copyResult = surfContext->testCopy(copySrc.refProxy());
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(
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});
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()) {
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();
proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu.
auto regenResult =
2020-08-11 16:02:22 +00:00
dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
}
}
}