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"
|
2020-12-09 21:37:04 +00:00
|
|
|
#include "src/gpu/GrSurfaceDrawContext.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-12-09 21:37:04 +00:00
|
|
|
static std::unique_ptr<GrSurfaceDrawContext> get_rtc(GrRecordingContext* rContext) {
|
2021-04-19 23:27:09 +00:00
|
|
|
return GrSurfaceDrawContext::Make(rContext, GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kExact, {kSize, kSize}, SkSurfaceProps());
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 18:12:13 +00:00
|
|
|
static void check_instantiation_status(skiatest::Reporter* reporter,
|
2020-12-09 21:37:04 +00:00
|
|
|
GrSurfaceDrawContext* rtCtx,
|
2019-06-19 18:12:13 +00:00
|
|
|
bool wrappedExpectation) {
|
2020-11-30 19:33:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtCtx->asRenderTargetProxy()->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
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
// Calling instantiate on a GrSurfaceDrawContext's textureProxy also instantiates the
|
|
|
|
// GrSurfaceDrawContext
|
2016-11-08 13:49:39 +00:00
|
|
|
{
|
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);
|
2021-01-26 18:29:30 +00:00
|
|
|
GrPixmap dstPM = GrPixmap::Allocate(dstInfo);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
bool result = rtCtx->readPixels(dContext, dstPM, {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
|
2020-12-09 21:37:04 +00:00
|
|
|
// GrSurfaceDrawContext calls do not force the instantiation of a deferred
|
|
|
|
// GrSurfaceDrawContext
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|