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.
|
|
|
|
*/
|
|
|
|
|
2014-11-25 15:41:12 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2013-04-09 15:04:12 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#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"
|
2017-07-26 19:48:41 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrResourceProvider.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 "GrTest.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrTexture.h"
|
2017-06-02 12:45:06 +00:00
|
|
|
#include "SkMipMap.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();
|
2015-12-01 12:35:26 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fWidth = 256;
|
|
|
|
desc.fHeight = 256;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fSampleCnt = 0;
|
2017-04-06 11:59:41 +00:00
|
|
|
sk_sp<GrSurface> texRT1 = context->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;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
|
2017-04-06 11:59:41 +00:00
|
|
|
sk_sp<GrTexture> tex1 = context->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
|
|
|
|
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
|
|
|
GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture(
|
2016-10-14 13:16:21 +00:00
|
|
|
nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
|
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
|
|
|
GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
|
|
|
|
256,
|
|
|
|
256,
|
|
|
|
kRGBA_8888_GrPixelConfig,
|
2017-10-12 16:27:11 +00:00
|
|
|
GrMipMapped::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
|
|
|
backendTexHandle);
|
2015-11-10 19:54:56 +00:00
|
|
|
|
2017-07-19 22:28:58 +00:00
|
|
|
sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapRenderableBackendTexture(
|
2017-08-29 12:26:54 +00:00
|
|
|
backendTex, 0, kBorrow_GrWrapOwnership);
|
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
|
|
|
|
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
|
|
|
context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
|
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();
|
2017-05-24 11:44:02 +00:00
|
|
|
GrResourceProvider* resourceProvider = context->resourceProvider();
|
2017-05-22 17:23:19 +00:00
|
|
|
const GrCaps* caps = context->caps();
|
|
|
|
|
|
|
|
GrPixelConfig configs[] = {
|
|
|
|
kUnknown_GrPixelConfig,
|
|
|
|
kAlpha_8_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,
|
|
|
|
kRGBA_half_GrPixelConfig,
|
|
|
|
};
|
|
|
|
SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));
|
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
|
2017-06-02 12:45:06 +00:00
|
|
|
// 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]);
|
|
|
|
|
2017-05-22 17:23:19 +00:00
|
|
|
for (GrPixelConfig config : configs) {
|
|
|
|
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags;
|
|
|
|
desc.fOrigin = origin;
|
|
|
|
desc.fConfig = config;
|
2017-07-27 20:16:25 +00:00
|
|
|
desc.fSampleCnt = 0;
|
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);
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigTexturable(desc.fConfig));
|
2017-05-22 17:23:19 +00:00
|
|
|
|
2017-06-02 12:45:06 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-07-10 16:06:05 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferredMipMap(resourceProvider,
|
|
|
|
desc, SkBudgeted::kNo,
|
|
|
|
texels.get(),
|
|
|
|
levelCount);
|
2017-06-02 12:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(proxy.get()) ==
|
|
|
|
(caps->isConfigTexturable(desc.fConfig) &&
|
|
|
|
caps->mipMapSupport() &&
|
|
|
|
!GrPixelConfigIsSint(desc.fConfig)));
|
|
|
|
|
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);
|
2017-05-22 17:23:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, false));
|
|
|
|
|
|
|
|
desc.fSampleCnt = 4;
|
2017-05-24 11:44:02 +00:00
|
|
|
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
2017-05-22 17:23:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
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;
|
2017-09-25 16:26:58 +00:00
|
|
|
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;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context->purgeAllUnlockedResources();
|
|
|
|
|
|
|
|
// Try creating the texture as a deferred proxy.
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
auto surfCtx = context->contextPriv().makeDeferredSurfaceContext(
|
2017-10-30 17:39:09 +00:00
|
|
|
desc, GrMipMapped::kNo,
|
|
|
|
approx ? SkBackingFit::kApprox : SkBackingFit::kExact,
|
2017-09-25 16:26:58 +00:00
|
|
|
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;
|
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
|
|
|
}
|
2017-09-25 16:26:58 +00:00
|
|
|
context->purgeAllUnlockedResources();
|
2017-05-23 20:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 15:04:12 +00:00
|
|
|
#endif
|