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
|
|
|
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrImageInfo.h"
|
|
|
|
#include "src/gpu/ganesh/GrTextureProxy.h"
|
|
|
|
#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
|
2016-11-08 13:49:39 +00:00
|
|
|
|
|
|
|
static const int kSize = 64;
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
static std::unique_ptr<skgpu::v1::SurfaceDrawContext> get_sdc(GrRecordingContext* rContext) {
|
|
|
|
return skgpu::v1::SurfaceDrawContext::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,
|
2021-07-28 19:13:20 +00:00
|
|
|
skgpu::v1::SurfaceDrawContext* sdc,
|
2019-06-19 18:12:13 +00:00
|
|
|
bool wrappedExpectation) {
|
2021-07-28 19:13:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, sdc->asRenderTargetProxy()->isInstantiated() == wrappedExpectation);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
GrTextureProxy* tProxy = sdc->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
|
|
|
}
|
|
|
|
|
2021-06-04 18:40:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceDrawContextTest, reporter, ctxInfo) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
// Calling instantiate on a SurfaceDrawContext's textureProxy also instantiates the
|
|
|
|
// SurfaceDrawContext
|
2016-11-08 13:49:39 +00:00
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = get_sdc(dContext);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
check_instantiation_status(reporter, sdc.get(), false);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
GrTextureProxy* tProxy = sdc->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
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
check_instantiation_status(reporter, sdc.get(), true);
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 18:40:57 +00:00
|
|
|
// readPixels switches a deferred sdCtx to wrapped
|
2016-11-08 13:49:39 +00:00
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = get_sdc(dContext);
|
2016-11-08 13:49:39 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
check_instantiation_status(reporter, sdc.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
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
bool result = sdc->readPixels(dContext, dstPM, {0, 0});
|
2016-11-08 13:49:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
check_instantiation_status(reporter, sdc.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
|
2021-07-28 19:13:20 +00:00
|
|
|
// SurfaceDrawContext calls do not force the instantiation of a deferred
|
|
|
|
// SurfaceDrawContext
|
2016-11-08 13:49:39 +00:00
|
|
|
}
|