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"
|
|
|
|
#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-04-05 19:59:06 +00:00
|
|
|
GrContext* context = ctxInfo.fGrContext;
|
2015-12-01 12:35:26 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 256;
|
|
|
|
desc.fHeight = 256;
|
|
|
|
desc.fSampleCnt = 0;
|
2016-02-25 16:33:02 +00:00
|
|
|
GrSurface* texRT1 = context->textureProvider()->createTexture(
|
|
|
|
desc, SkBudgeted::kNo, nullptr, 0);
|
2014-11-25 15:41:12 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget());
|
|
|
|
REPORTER_ASSERT(reporter, texRT1 == 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()));
|
2014-11-25 15:41:12 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
desc.fFlags = kNone_GrSurfaceFlags;
|
2016-02-25 16:33:02 +00:00
|
|
|
GrSurface* tex1 = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
|
|
|
|
REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
|
|
|
|
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
|
|
|
|
nullptr, 256, 256, kSkia8888_GrPixelConfig);
|
2015-11-10 19:54:56 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrBackendTextureDesc backendDesc;
|
|
|
|
backendDesc.fConfig = kSkia8888_GrPixelConfig;
|
|
|
|
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
|
|
|
|
backendDesc.fWidth = 256;
|
|
|
|
backendDesc.fHeight = 256;
|
|
|
|
backendDesc.fSampleCnt = 0;
|
|
|
|
backendDesc.fTextureHandle = backendTex;
|
|
|
|
GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(
|
|
|
|
backendDesc, kBorrow_GrWrapOwnership);
|
|
|
|
REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
|
|
|
|
REPORTER_ASSERT(reporter, texRT2 == 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()));
|
2013-04-09 15:04:12 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
texRT1->unref();
|
|
|
|
texRT2->unref();
|
|
|
|
tex1->unref();
|
|
|
|
context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
|
2013-04-09 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|