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
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.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;
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static std::unique_ptr<GrRenderTargetContext> get_rtc(GrRecordingContext* rContext) {
|
2020-01-08 16:52:34 +00:00
|
|
|
return GrRenderTargetContext::Make(
|
2020-07-23 17:54:35 +00:00
|
|
|
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {kSize, kSize});
|
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) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2016-11-08 13:49:39 +00:00
|
|
|
|
|
|
|
// Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
|
|
|
|
// GrRenderTargetContext
|
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
auto rtCtx = get_rtc(dContext);
|
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);
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->instantiate(dContext->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
|
|
|
|
{
|
2020-07-23 17:54:35 +00:00
|
|
|
auto rtCtx = get_rtc(dContext);
|
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;
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
bool result = rtCtx->readPixels(dContext, 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
|
|
|
|
}
|