2016-11-08 13:49:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2016-11-08 13:49:39 +00:00
|
|
|
|
|
|
|
static const int kSize = 64;
|
|
|
|
|
2019-08-21 13:38:10 +00:00
|
|
|
static std::unique_ptr<GrRenderTargetContext> get_rtc(GrContext* ctx) {
|
2019-07-03 15:27:44 +00:00
|
|
|
return ctx->priv().makeDeferredRenderTargetContext(SkBackingFit::kExact, kSize, kSize,
|
2019-06-24 19:50:07 +00:00
|
|
|
GrColorType::kRGBA_8888, nullptr);
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
static void check_instantiation_status(skiatest::Reporter* reporter,
|
|
|
|
GrRenderTargetContext* rtCtx,
|
|
|
|
bool wrappedExpectation) {
|
|
|
|
REPORTER_ASSERT(reporter, rtCtx->testingOnly_IsInstantiated() == wrappedExpectation);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2017-01-30 18:27:37 +00:00
|
|
|
GrTextureProxy* tProxy = rtCtx->asTextureProxy();
|
2016-11-08 13:49:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
|
|
|
|
GrContext* ctx = ctxInfo.grContext();
|
|
|
|
|
|
|
|
// Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
|
|
|
|
// GrRenderTargetContext
|
|
|
|
{
|
2019-08-21 13:38:10 +00:00
|
|
|
auto rtCtx = get_rtc(ctx);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
check_instantiation_status(reporter, rtCtx.get(), false);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2017-01-30 18:27:37 +00:00
|
|
|
GrTextureProxy* tProxy = rtCtx->asTextureProxy();
|
2016-11-08 13:49:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->priv().resourceProvider()));
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
check_instantiation_status(reporter, rtCtx.get(), true);
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// readPixels switches a deferred rtCtx to wrapped
|
|
|
|
{
|
2019-08-21 13:38:10 +00:00
|
|
|
auto rtCtx = get_rtc(ctx);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
check_instantiation_status(reporter, rtCtx.get(), false);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
|
|
|
SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
|
|
|
|
SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
|
|
|
|
static const size_t kRowBytes = sizeof(uint32_t) * kSize;
|
|
|
|
|
2019-07-01 17:05:28 +00:00
|
|
|
bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, {0, 0});
|
2016-11-08 13:49:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
check_instantiation_status(reporter, rtCtx.get(), true);
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: in a future world we should be able to add a test that the majority of
|
2017-10-09 19:45:33 +00:00
|
|
|
// GrRenderTargetContext calls do not force the instantiation of a deferred
|
2016-11-08 13:49:39 +00:00
|
|
|
// GrRenderTargetContext
|
|
|
|
}
|