Flutter Engine
The Flutter Engine
SurfaceDrawContextTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This is a GPU-backend specific test.
9
23#include "tests/Test.h"
24
25#include <memory>
26
28struct GrContextOptions;
29
30static const int kSize = 64;
31
32static std::unique_ptr<skgpu::ganesh::SurfaceDrawContext> get_sdc(GrRecordingContext* rContext) {
35 nullptr,
37 {kSize, kSize},
39 /*label=*/{});
40}
41
44 bool wrappedExpectation) {
45 REPORTER_ASSERT(reporter, sdc->asRenderTargetProxy()->isInstantiated() == wrappedExpectation);
46
47 GrTextureProxy* tProxy = sdc->asTextureProxy();
49
50 REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
51}
52
55 ctxInfo,
57 auto dContext = ctxInfo.directContext();
58
59 // Calling instantiate on a SurfaceDrawContext's textureProxy also instantiates the
60 // SurfaceDrawContext
61 {
62 auto sdc = get_sdc(dContext);
63
64 check_instantiation_status(reporter, sdc.get(), false);
65
66 GrTextureProxy* tProxy = sdc->asTextureProxy();
68
69 REPORTER_ASSERT(reporter, tProxy->instantiate(dContext->priv().resourceProvider()));
70
71 check_instantiation_status(reporter, sdc.get(), true);
72 }
73
74 // readPixels switches a deferred sdCtx to wrapped
75 {
76 auto sdc = get_sdc(dContext);
77
78 check_instantiation_status(reporter, sdc.get(), false);
79
81 GrPixmap dstPM = GrPixmap::Allocate(dstInfo);
82
83 bool result = sdc->readPixels(dContext, dstPM, {0, 0});
85
86 check_instantiation_status(reporter, sdc.get(), true);
87 }
88
89 // TODO: in a future world we should be able to add a test that the majority of
90 // SurfaceDrawContext calls do not force the instantiation of a deferred
91 // SurfaceDrawContext
92}
reporter
Definition: FontMgrTest.cpp:39
static void check_instantiation_status(skiatest::Reporter *reporter, skgpu::ganesh::SurfaceDrawContext *sdc, bool wrappedExpectation)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SurfaceDrawContextTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
static const int kSize
static std::unique_ptr< skgpu::ganesh::SurfaceDrawContext > get_sdc(GrRecordingContext *rContext)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static GrPixmap Allocate(const GrImageInfo &info)
Definition: GrPixmap.h:101
bool isInstantiated() const
bool instantiate(GrResourceProvider *) override
GrTextureProxy * asTextureProxy() override
GrRenderTargetProxy * asRenderTargetProxy()
GrTextureProxy * asTextureProxy()
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
GAsyncResult * result
static SkImageInfo MakeN32Premul(int width, int height)