skia2/tests/RenderTargetContextTest.cpp
Robert Phillips e94b4e1b49 Update more tests to use the GrDirectContext/GrRecordingContext pair
This should be the last batch of tests. All the remaining uses of
GrContext should be resolved when SkImage no longer requires a context.

Change-Id: I47eeb3b74c28f483c20d9bec4daecbdb6d2cb982
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305541
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-07-27 15:08:31 +00:00

74 lines
2.5 KiB
C++

/*
* 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.
#include "tests/Test.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrTextureProxy.h"
static const int kSize = 64;
static std::unique_ptr<GrRenderTargetContext> get_rtc(GrRecordingContext* rContext) {
return GrRenderTargetContext::Make(
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {kSize, kSize});
}
static void check_instantiation_status(skiatest::Reporter* reporter,
GrRenderTargetContext* rtCtx,
bool wrappedExpectation) {
REPORTER_ASSERT(reporter, rtCtx->testingOnly_IsInstantiated() == wrappedExpectation);
GrTextureProxy* tProxy = rtCtx->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext();
// Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
// GrRenderTargetContext
{
auto rtCtx = get_rtc(dContext);
check_instantiation_status(reporter, rtCtx.get(), false);
GrTextureProxy* tProxy = rtCtx->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->instantiate(dContext->priv().resourceProvider()));
check_instantiation_status(reporter, rtCtx.get(), true);
}
// readPixels switches a deferred rtCtx to wrapped
{
auto rtCtx = get_rtc(dContext);
check_instantiation_status(reporter, rtCtx.get(), false);
SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
static const size_t kRowBytes = sizeof(uint32_t) * kSize;
bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, {0, 0});
REPORTER_ASSERT(reporter, result);
check_instantiation_status(reporter, rtCtx.get(), true);
}
// TODO: in a future world we should be able to add a test that the majority of
// GrRenderTargetContext calls do not force the instantiation of a deferred
// GrRenderTargetContext
}