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"
|
2015-11-10 19:54:56 +00:00
|
|
|
#include "GrGpu.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2017-03-04 13:12:46 +00:00
|
|
|
#include "GrResourceProvider.h"
|
2013-04-09 15:04:12 +00:00
|
|
|
#include "GrTexture.h"
|
2014-09-30 19:18:44 +00:00
|
|
|
#include "GrSurfacePriv.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;
|
2016-10-14 13:16:21 +00:00
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 256;
|
|
|
|
desc.fHeight = 256;
|
|
|
|
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-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
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
|
2016-10-14 13:16:21 +00:00
|
|
|
nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
|
2015-11-10 19:54:56 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrBackendTextureDesc backendDesc;
|
2016-10-14 13:16:21 +00:00
|
|
|
backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
2015-12-01 12:35:26 +00:00
|
|
|
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
|
|
|
|
backendDesc.fWidth = 256;
|
|
|
|
backendDesc.fHeight = 256;
|
|
|
|
backendDesc.fSampleCnt = 0;
|
|
|
|
backendDesc.fTextureHandle = backendTex;
|
2017-03-04 13:12:46 +00:00
|
|
|
sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture(
|
2015-12-01 12:35:26 +00:00
|
|
|
backendDesc, kBorrow_GrWrapOwnership);
|
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
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
|
2013-04-09 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|