skia2/tests/GrSurfaceTest.cpp
Greg Daniel ef59d87ae8 Revert "Revert "Revert "Revert "Revert "Revert "Add private grpixelconfigs for alpha_8 and alpha_half""""""
This reverts commit b092cea5b1.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> Revert "Revert "Revert "Revert "Revert "Add private grpixelconfigs for alpha_8 and alpha_half"""""
>
> This reverts commit 68ab18611a.
>
> Reason for revert: Command Buffer bot
>
> Original change's description:
> > Revert "Revert "Revert "Revert "Add private grpixelconfigs for alpha_8 and alpha_half""""
> >
> > This reverts commit 3b2f5b60ff.
> >
> > Reason for revert: more attempts at a fixed version
> >
> > Original change's description:
> > > Revert "Revert "Revert "Add private grpixelconfigs for alpha_8 and alpha_half"""
> > >
> > > This reverts commit b5fb7cf016.
> > >
> > > Reason for revert: breaking more devices
> > >
> > > Original change's description:
> > > > Revert "Revert "Add private grpixelconfigs for alpha_8 and alpha_half""
> > > >
> > > > This reverts commit 0fb6db4be6.
> > > >
> > > > Reason for revert: fixed bug
> > > >
> > > > Original change's description:
> > > > > Revert "Add private grpixelconfigs for alpha_8 and alpha_half"
> > > > >
> > > > > This reverts commit 33d17cbb00.
> > > > >
> > > > > Reason for revert: broke intel bots
> > > > >
> > > > > Original change's description:
> > > > > > Add private grpixelconfigs for alpha_8 and alpha_half
> > > > > >
> > > > > > Bug: skia:
> > > > > > Change-Id: I5191b6e045aea2a5af2b305b5972ad1e638a7ace
> > > > > > Reviewed-on: https://skia-review.googlesource.com/71763
> > > > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > > >
> > > > > TBR=egdaniel@google.com,bsalomon@google.com
> > > > >
> > > > > Change-Id: I6fff9241f7878f1ec7fad2663df9922c9cd8f628
> > > > > No-Presubmit: true
> > > > > No-Tree-Checks: true
> > > > > No-Try: true
> > > > > Bug: skia:
> > > > > Reviewed-on: https://skia-review.googlesource.com/72180
> > > > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > >
> > > > TBR=egdaniel@google.com,bsalomon@google.com
> > > >
> > > > Change-Id: Ie028961ecbf5934c53cb859e019e548935b3af79
> > > > Reviewed-on: https://skia-review.googlesource.com/72241
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com
> > >
> > > Change-Id: Ieaac3eca2fc4919699c7de61a3c33348e92a7da0
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/72660
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com
> >
> > Change-Id: Ifcf1b97c2a9493ce9a77a8aa0f4e5a8fb393def3
> > Reviewed-on: https://skia-review.googlesource.com/72802
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com
>
> Change-Id: Ie2277f59f5a1294392b5d153ce2429c20b3e4182
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/73320
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>

TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com

Change-Id: Ibba9d2109f35ea710e313d604b3e5ee742916234
Reviewed-on: https://skia-review.googlesource.com/73360
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2017-11-18 13:36:27 +00:00

249 lines
12 KiB
C++

/*
* 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 "SkTypes.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrRenderTarget.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
#include "GrTexture.h"
#include "SkMipMap.h"
#include "Test.h"
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
// and render targets to GrSurface all work as expected.
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fWidth = 256;
desc.fHeight = 256;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = 0;
sk_sp<GrSurface> texRT1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
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()));
desc.fFlags = kNone_GrSurfaceFlags;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
sk_sp<GrTexture> tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture(
nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
256,
256,
kRGBA_8888_GrPixelConfig,
GrMipMapped::kNo,
backendTexHandle);
sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapRenderableBackendTexture(
backendTex, 0, kBorrow_GrWrapOwnership);
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->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
}
// 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();
GrResourceProvider* resourceProvider = context->resourceProvider();
const GrCaps* caps = context->caps();
GrPixelConfig configs[] = {
kUnknown_GrPixelConfig,
kAlpha_8_GrPixelConfig,
kAlpha_8_as_Alpha_GrPixelConfig,
kAlpha_8_as_Red_GrPixelConfig,
kGray_8_GrPixelConfig,
kRGB_565_GrPixelConfig,
kRGBA_4444_GrPixelConfig,
kRGBA_8888_GrPixelConfig,
kBGRA_8888_GrPixelConfig,
kSRGBA_8888_GrPixelConfig,
kSBGRA_8888_GrPixelConfig,
kRGBA_8888_sint_GrPixelConfig,
kRGBA_float_GrPixelConfig,
kRG_float_GrPixelConfig,
kAlpha_half_GrPixelConfig,
kAlpha_half_as_Red_GrPixelConfig,
kRGBA_half_GrPixelConfig,
};
SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));
GrSurfaceDesc desc;
desc.fWidth = 64;
desc.fHeight = 64;
// Enough space for the first mip of our largest pixel config
const size_t pixelBufferSize = desc.fWidth * desc.fHeight *
GrBytesPerPixel(kRGBA_float_GrPixelConfig);
std::unique_ptr<char[]> pixelData(new char[pixelBufferSize]);
memset(pixelData.get(), 0, pixelBufferSize);
// We re-use the same mip level objects (with updated pointers and rowBytes) for each config
const int levelCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[levelCount]);
for (GrPixelConfig config : configs) {
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
desc.fFlags = kNone_GrSurfaceFlags;
desc.fOrigin = origin;
desc.fConfig = config;
desc.fSampleCnt = 0;
sk_sp<GrSurface> tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigTexturable(desc.fConfig));
size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
for (int i = 0; i < levelCount; ++i) {
texels[i].fPixels = pixelData.get();
texels[i].fRowBytes = rowBytes >> i;
}
sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferredMipMap(resourceProvider,
desc, SkBudgeted::kNo,
texels.get(),
levelCount);
REPORTER_ASSERT(reporter, SkToBool(proxy.get()) ==
(caps->isConfigTexturable(desc.fConfig) &&
caps->mipMapSupport() &&
!GrPixelConfigIsSint(desc.fConfig)));
desc.fFlags = kRenderTarget_GrSurfaceFlag;
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, false));
desc.fSampleCnt = 4;
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, true));
}
}
}
#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]);
GrContext* context = context_info.grContext();
for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
desc.fConfig = static_cast<GrPixelConfig>(c);
if (!context_info.grContext()->caps()->isConfigTexturable(desc.fConfig)) {
continue;
}
desc.fFlags = kPerformInitialClear_GrSurfaceFlag;
for (bool rt : {false, true}) {
if (rt && !context->caps()->isConfigRenderable(desc.fConfig, false)) {
continue;
}
desc.fFlags |= rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
for (GrSurfaceOrigin origin :
{kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
desc.fOrigin = origin;
for (bool approx : {false, true}) {
auto resourceProvider = context->resourceProvider();
// 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) {
sk_sp<GrTexture> tex;
if (approx) {
tex = sk_sp<GrTexture>(
resourceProvider->createApproxTexture(desc, 0));
} else {
tex = resourceProvider->createTexture(desc, SkBudgeted::kYes);
}
if (!tex) {
continue;
}
auto proxy = GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
auto texCtx = context->contextPriv().makeWrappedSurfaceContext(
std::move(proxy), nullptr);
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;
}
}
}
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);
}
}
context->purgeAllUnlockedResources();
// Try creating the texture as a deferred proxy.
for (int i = 0; i < 2; ++i) {
auto surfCtx = context->contextPriv().makeDeferredSurfaceContext(
desc, GrMipMapped::kNo,
approx ? SkBackingFit::kApprox : SkBackingFit::kExact,
SkBudgeted::kYes);
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;
}
}
}
// 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);
}
}
context->purgeAllUnlockedResources();
}
}
}
}
}
#endif