Make GM::onGpuSetup take a GrDirectContext
This should, hopefully, clarify the role of onGpuSetup vis a vis onDraw. The remaining tools are updated in: https://skia-review.googlesource.com/c/skia/+/300220/ (Update remaining tools to GrDirectContext) Change-Id: I19d6eec4d16cb9ebad8924763a18225cc871f0f2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300172 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
c61e35dbc6
commit
b87b39b7a2
@ -7,6 +7,9 @@
|
||||
|
||||
#include "bench/GMBench.h"
|
||||
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "src/gpu/GrRecordingContextPriv.h"
|
||||
|
||||
GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
|
||||
fGM->setMode(skiagm::GM::kBench_Mode);
|
||||
|
||||
@ -22,7 +25,10 @@ bool GMBench::isSuitableFor(Backend backend) {
|
||||
}
|
||||
|
||||
void GMBench::onPerCanvasPreDraw(SkCanvas* canvas) {
|
||||
if (fGM->gpuSetup(canvas->getGrContext(), canvas) != skiagm::DrawResult::kOk) {
|
||||
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
|
||||
: nullptr;
|
||||
|
||||
if (fGM->gpuSetup(direct, canvas) != skiagm::DrawResult::kOk) {
|
||||
fGpuSetupFailed = true;
|
||||
}
|
||||
|
||||
|
@ -910,7 +910,7 @@ static void push_sink(const SkCommandLineConfig& config, Sink* s) {
|
||||
|
||||
// Try a simple Src as a canary. If it fails, skip this sink.
|
||||
struct : public Src {
|
||||
Result draw(GrContext*, SkCanvas* c) const override {
|
||||
Result draw(GrDirectContext*, SkCanvas* c) const override {
|
||||
c->drawRect(SkRect::MakeWH(1,1), SkPaint());
|
||||
return Result::Ok();
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "tests/Test.h"
|
||||
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
|
||||
using sk_gpu_test::GrContextFactory;
|
||||
using sk_gpu_test::GLTestContext;
|
||||
using sk_gpu_test::ContextInfo;
|
||||
@ -65,12 +67,12 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
|
||||
}
|
||||
|
||||
ReporterContext ctx(reporter, SkString(GrContextFactory::ContextTypeName(contextType)));
|
||||
if (ctxInfo.grContext()) {
|
||||
if (ctxInfo.directContext()) {
|
||||
(*test)(reporter, ctxInfo);
|
||||
// In case the test changed the current context make sure we move it back before
|
||||
// calling flush.
|
||||
ctxInfo.testContext()->makeCurrent();
|
||||
ctxInfo.grContext()->flushAndSubmit();
|
||||
ctxInfo.directContext()->flushAndSubmit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "include/core/SkSurfaceCharacterization.h"
|
||||
#include "include/docs/SkPDFDocument.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/ports/SkImageGeneratorCG.h"
|
||||
#include "include/ports/SkImageGeneratorWIC.h"
|
||||
#include "include/private/SkImageInfoPriv.h"
|
||||
@ -94,7 +95,7 @@ namespace DM {
|
||||
|
||||
GMSrc::GMSrc(skiagm::GMFactory factory) : fFactory(factory) {}
|
||||
|
||||
Result GMSrc::draw(GrContext* context, SkCanvas* canvas) const {
|
||||
Result GMSrc::draw(GrDirectContext* context, SkCanvas* canvas) const {
|
||||
std::unique_ptr<skiagm::GM> gm(fFactory());
|
||||
SkString msg;
|
||||
|
||||
@ -173,7 +174,7 @@ static inline void alpha8_to_gray8(SkBitmap* bitmap) {
|
||||
}
|
||||
}
|
||||
|
||||
Result BRDSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result BRDSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
SkColorType colorType = canvas->imageInfo().colorType();
|
||||
if (kRGB_565_SkColorType == colorType &&
|
||||
CodecSrc::kGetFromCanvas_DstColorType != fDstColorType)
|
||||
@ -414,7 +415,7 @@ static void set_bitmap_color_space(SkImageInfo* info) {
|
||||
*info = info->makeColorSpace(SkColorSpace::MakeSRGB());
|
||||
}
|
||||
|
||||
Result CodecSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result CodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
||||
if (!encoded) {
|
||||
return Result::Fatal("Couldn't read %s.", fPath.c_str());
|
||||
@ -799,7 +800,7 @@ bool AndroidCodecSrc::veto(SinkFlags flags) const {
|
||||
|| flags.approach != SinkFlags::kDirect;
|
||||
}
|
||||
|
||||
Result AndroidCodecSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result AndroidCodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
||||
if (!encoded) {
|
||||
return Result::Fatal("Couldn't read %s.", fPath.c_str());
|
||||
@ -891,7 +892,7 @@ bool ImageGenSrc::veto(SinkFlags flags) const {
|
||||
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
||||
}
|
||||
|
||||
Result ImageGenSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result ImageGenSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
|
||||
return Result::Skip("Uninteresting to test image generator to 565.");
|
||||
}
|
||||
@ -989,7 +990,7 @@ bool ColorCodecSrc::veto(SinkFlags flags) const {
|
||||
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
||||
}
|
||||
|
||||
Result ColorCodecSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result ColorCodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
||||
if (!encoded) {
|
||||
return Result::Fatal("Couldn't read %s.", fPath.c_str());
|
||||
@ -1054,7 +1055,7 @@ static DEFINE_int(skpViewportSize, 1000,
|
||||
|
||||
SKPSrc::SKPSrc(Path path) : fPath(path) { }
|
||||
|
||||
Result SKPSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result SKPSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
|
||||
if (!stream) {
|
||||
return Result::Fatal("Couldn't read %s.", fPath.c_str());
|
||||
@ -1096,7 +1097,7 @@ Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
|
||||
|
||||
BisectSrc::BisectSrc(Path path, const char* trail) : INHERITED(path), fTrail(trail) {}
|
||||
|
||||
Result BisectSrc::draw(GrContext* context, SkCanvas* canvas) const {
|
||||
Result BisectSrc::draw(GrDirectContext* context, SkCanvas* canvas) const {
|
||||
struct FoundPath {
|
||||
SkPath fPath;
|
||||
SkPaint fPaint;
|
||||
@ -1152,7 +1153,7 @@ static DEFINE_bool(useLottieGlyphPaths, false,
|
||||
|
||||
SkottieSrc::SkottieSrc(Path path) : fPath(std::move(path)) {}
|
||||
|
||||
Result SkottieSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result SkottieSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
auto resource_provider =
|
||||
skresources::DataURIResourceProviderProxy::Make(
|
||||
skresources::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str()),
|
||||
@ -1229,7 +1230,7 @@ bool SkottieSrc::veto(SinkFlags flags) const {
|
||||
#if defined(SK_ENABLE_SKRIVE)
|
||||
SkRiveSrc::SkRiveSrc(Path path) : fPath(std::move(path)) {}
|
||||
|
||||
Result SkRiveSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result SkRiveSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
auto fileStream = SkFILEStream::Make(fPath.c_str());
|
||||
if (!fileStream) {
|
||||
return Result::Fatal("Unable to open file: %s", fPath.c_str());
|
||||
@ -1314,7 +1315,7 @@ SVGSrc::SVGSrc(Path path)
|
||||
}
|
||||
}
|
||||
|
||||
Result SVGSrc::draw(GrContext*, SkCanvas* canvas) const {
|
||||
Result SVGSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
|
||||
if (!fDom) {
|
||||
return Result::Fatal("Unable to parse file: %s", fName.c_str());
|
||||
}
|
||||
@ -1365,10 +1366,10 @@ SkISize MSKPSrc::size(int i) const {
|
||||
return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
|
||||
}
|
||||
|
||||
Result MSKPSrc::draw(GrContext* context, SkCanvas* c) const {
|
||||
Result MSKPSrc::draw(GrDirectContext* context, SkCanvas* c) const {
|
||||
return this->draw(0, context, c);
|
||||
}
|
||||
Result MSKPSrc::draw(int i, GrContext*, SkCanvas* canvas) const {
|
||||
Result MSKPSrc::draw(int i, GrDirectContext*, SkCanvas* canvas) const {
|
||||
if (this->pageCount() == 0) {
|
||||
return Result::Fatal("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
|
||||
}
|
||||
@ -1463,7 +1464,7 @@ Result GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream* dstStream, SkStri
|
||||
return this->onDraw(src, dst, dstStream, log, fBaseContextOptions);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> GPUSink::createDstSurface(GrContext* context, SkISize size,
|
||||
sk_sp<SkSurface> GPUSink::createDstSurface(GrDirectContext* context, SkISize size,
|
||||
GrBackendTexture* backendTexture,
|
||||
GrBackendRenderTarget* backendRT) const {
|
||||
sk_sp<SkSurface> surface;
|
||||
@ -1522,19 +1523,19 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
|
||||
SkASSERT(exec == grOptions.fExecutor);
|
||||
|
||||
GrContextFactory factory(grOptions);
|
||||
GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext();
|
||||
auto direct = factory.getContextInfo(fContextType, fContextOverrides).directContext();
|
||||
if (initContext) {
|
||||
initContext(context);
|
||||
initContext(direct);
|
||||
}
|
||||
|
||||
const int maxDimension = context->priv().caps()->maxTextureSize();
|
||||
const int maxDimension = direct->priv().caps()->maxTextureSize();
|
||||
if (maxDimension < std::max(src.size().width(), src.size().height())) {
|
||||
return Result::Skip("Src too large to create a texture.\n");
|
||||
}
|
||||
|
||||
GrBackendTexture backendTexture;
|
||||
GrBackendRenderTarget backendRT;
|
||||
sk_sp<SkSurface> surface = this->createDstSurface(context, src.size(),
|
||||
sk_sp<SkSurface> surface = this->createDstSurface(direct, src.size(),
|
||||
&backendTexture, &backendRT);
|
||||
if (!surface) {
|
||||
return Result::Fatal("Could not create a surface.");
|
||||
@ -1543,15 +1544,15 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
|
||||
factory.abandonContexts();
|
||||
}
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
Result result = src.draw(context, canvas);
|
||||
Result result = src.draw(direct, canvas);
|
||||
if (!result.isOk()) {
|
||||
return result;
|
||||
}
|
||||
surface->flushAndSubmit();
|
||||
if (FLAGS_gpuStats) {
|
||||
context->priv().dumpCacheStats(log);
|
||||
context->priv().dumpGpuStats(log);
|
||||
context->priv().dumpContextStats(log);
|
||||
direct->priv().dumpCacheStats(log);
|
||||
direct->priv().dumpGpuStats(log);
|
||||
direct->priv().dumpContextStats(log);
|
||||
}
|
||||
|
||||
this->readBack(surface.get(), dst);
|
||||
@ -1561,17 +1562,17 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
|
||||
} else if (FLAGS_releaseAndAbandonGpuContext) {
|
||||
factory.releaseResourcesAndAbandonContexts();
|
||||
}
|
||||
if (!context->abandoned()) {
|
||||
if (!direct->abandoned()) {
|
||||
surface.reset();
|
||||
if (backendTexture.isValid()) {
|
||||
context->deleteBackendTexture(backendTexture);
|
||||
direct->deleteBackendTexture(backendTexture);
|
||||
}
|
||||
if (backendRT.isValid()) {
|
||||
context->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
|
||||
direct->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
|
||||
}
|
||||
}
|
||||
if (grOptions.fPersistentCache) {
|
||||
context->storeVkPipelineCacheData();
|
||||
direct->storeVkPipelineCacheData();
|
||||
}
|
||||
return Result::Ok();
|
||||
}
|
||||
@ -1703,7 +1704,7 @@ GPUOOPRSink::GPUOOPRSink(const SkCommandLineConfigGpu* config, const GrContextOp
|
||||
|
||||
Result GPUOOPRSink::ooprDraw(const Src& src,
|
||||
sk_sp<SkSurface> dstSurface,
|
||||
GrContext* context) const {
|
||||
GrDirectContext* context) const {
|
||||
SkSurfaceCharacterization dstCharacterization;
|
||||
SkAssertResult(dstSurface->characterize(&dstCharacterization));
|
||||
|
||||
@ -1735,7 +1736,7 @@ Result GPUOOPRSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* lo
|
||||
GrContextFactory factory(contextOptions);
|
||||
|
||||
ContextInfo ctxInfo = factory.getContextInfo(this->contextType(), this->contextOverrides());
|
||||
GrContext* context = ctxInfo.grContext();
|
||||
auto context = ctxInfo.directContext();
|
||||
if (!context) {
|
||||
return Result::Fatal("Could not create context.");
|
||||
}
|
||||
@ -1788,7 +1789,7 @@ Result GPUDDLSink::ddlDraw(const Src& src,
|
||||
SkTaskGroup* recordingTaskGroup,
|
||||
SkTaskGroup* gpuTaskGroup,
|
||||
sk_gpu_test::TestContext* gpuTestCtx,
|
||||
GrContext* gpuThreadCtx) const {
|
||||
GrDirectContext* gpuThreadCtx) const {
|
||||
|
||||
// We have to do this here bc characterization can hit the SkGpuDevice's thread guard (i.e.,
|
||||
// leaving it until the DDLTileHelper ctor will result in multiple threads trying to use the
|
||||
@ -1894,7 +1895,7 @@ Result GPUDDLSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log
|
||||
// This captures the context destined to be the main gpu context
|
||||
ContextInfo mainCtxInfo = factory.getContextInfo(this->contextType(), this->contextOverrides());
|
||||
sk_gpu_test::TestContext* mainTestCtx = mainCtxInfo.testContext();
|
||||
GrContext* mainCtx = mainCtxInfo.grContext();
|
||||
auto mainCtx = mainCtxInfo.directContext();
|
||||
if (!mainCtx) {
|
||||
return Result::Fatal("Could not create context.");
|
||||
}
|
||||
@ -2127,11 +2128,11 @@ Result RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) co
|
||||
|
||||
template <typename Fn>
|
||||
static Result draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
|
||||
SkISize size, const Fn& draw) {
|
||||
SkISize size, const Fn& draw) {
|
||||
class ProxySrc : public Src {
|
||||
public:
|
||||
ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {}
|
||||
Result draw(GrContext*, SkCanvas* canvas) const override { return fDraw(canvas); }
|
||||
Result draw(GrDirectContext*, SkCanvas* canvas) const override { return fDraw(canvas); }
|
||||
Name name() const override { return "ProxySrc"; }
|
||||
SkISize size() const override { return fSize; }
|
||||
private:
|
||||
|
@ -86,14 +86,15 @@ struct SinkFlags {
|
||||
|
||||
struct Src {
|
||||
virtual ~Src() {}
|
||||
virtual Result SK_WARN_UNUSED_RESULT draw(GrContext*, SkCanvas*) const = 0;
|
||||
virtual Result SK_WARN_UNUSED_RESULT draw(GrDirectContext*, SkCanvas*) const = 0;
|
||||
virtual SkISize size() const = 0;
|
||||
virtual Name name() const = 0;
|
||||
virtual void modifyGrContextOptions(GrContextOptions* options) const {}
|
||||
virtual bool veto(SinkFlags) const { return false; }
|
||||
|
||||
virtual int pageCount() const { return 1; }
|
||||
virtual Result SK_WARN_UNUSED_RESULT draw(int, GrContext* context, SkCanvas* canvas) const {
|
||||
virtual Result SK_WARN_UNUSED_RESULT draw(int, GrDirectContext* context,
|
||||
SkCanvas* canvas) const {
|
||||
return this->draw(context, canvas);
|
||||
}
|
||||
virtual SkISize size(int) const { return this->size(); }
|
||||
@ -130,7 +131,7 @@ class GMSrc : public Src {
|
||||
public:
|
||||
explicit GMSrc(skiagm::GMFactory);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
void modifyGrContextOptions(GrContextOptions* options) const override;
|
||||
@ -162,7 +163,7 @@ public:
|
||||
};
|
||||
CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -180,7 +181,7 @@ class AndroidCodecSrc : public Src {
|
||||
public:
|
||||
AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -209,7 +210,7 @@ public:
|
||||
|
||||
BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -229,7 +230,7 @@ public:
|
||||
};
|
||||
ImageGenSrc(Path, Mode, SkAlphaType, bool);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -246,7 +247,7 @@ class ColorCodecSrc : public Src {
|
||||
public:
|
||||
ColorCodecSrc(Path, bool decode_to_dst);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -259,7 +260,7 @@ class SKPSrc : public Src {
|
||||
public:
|
||||
explicit SKPSrc(Path path);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
private:
|
||||
@ -273,7 +274,7 @@ class BisectSrc : public SKPSrc {
|
||||
public:
|
||||
explicit BisectSrc(Path path, const char* trail);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
|
||||
private:
|
||||
SkString fTrail;
|
||||
@ -286,7 +287,7 @@ class SkottieSrc final : public Src {
|
||||
public:
|
||||
explicit SkottieSrc(Path path);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -308,7 +309,7 @@ class SkRiveSrc final : public Src {
|
||||
public:
|
||||
explicit SkRiveSrc(Path path);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -336,7 +337,7 @@ class SVGSrc : public Src {
|
||||
public:
|
||||
explicit SVGSrc(Path path);
|
||||
|
||||
Result draw(GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
Name name() const override;
|
||||
bool veto(SinkFlags) const override;
|
||||
@ -356,8 +357,8 @@ public:
|
||||
explicit MSKPSrc(Path path);
|
||||
|
||||
int pageCount() const override;
|
||||
Result draw(GrContext*, SkCanvas* c) const override;
|
||||
Result draw(int, GrContext*, SkCanvas*) const override;
|
||||
Result draw(GrDirectContext*, SkCanvas* c) const override;
|
||||
Result draw(int, GrDirectContext*, SkCanvas*) const override;
|
||||
SkISize size() const override;
|
||||
SkISize size(int) const override;
|
||||
Name name() const override;
|
||||
@ -406,7 +407,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
sk_sp<SkSurface> createDstSurface(GrContext*, SkISize size, GrBackendTexture*,
|
||||
sk_sp<SkSurface> createDstSurface(GrDirectContext*, SkISize size, GrBackendTexture*,
|
||||
GrBackendRenderTarget*) const;
|
||||
bool readBack(SkSurface*, SkBitmap* dst) const;
|
||||
|
||||
@ -482,7 +483,7 @@ public:
|
||||
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
|
||||
|
||||
private:
|
||||
Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrContext*) const;
|
||||
Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrDirectContext*) const;
|
||||
|
||||
typedef GPUSink INHERITED;
|
||||
};
|
||||
@ -507,7 +508,7 @@ private:
|
||||
SkTaskGroup* recordingTaskGroup,
|
||||
SkTaskGroup* gpuTaskGroup,
|
||||
sk_gpu_test::TestContext* gpuTestCtx,
|
||||
GrContext* gpuThreadCtx) const;
|
||||
GrDirectContext* gpuThreadCtx) const;
|
||||
|
||||
std::unique_ptr<SkExecutor> fRecordingExecutor;
|
||||
std::unique_ptr<SkExecutor> fGPUExecutor;
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "include/private/SkTArray.h"
|
||||
@ -112,7 +112,7 @@ static sk_sp<SkImage> make_text_image(GrContext* context, const char* text, SkCo
|
||||
|
||||
// Create an image with each corner marked w/ "LL", "LR", etc., with the origin either bottom-left
|
||||
// or top-left.
|
||||
static sk_sp<SkImage> make_reference_image(GrContext* context,
|
||||
static sk_sp<SkImage> make_reference_image(GrDirectContext* context,
|
||||
const SkTArray<sk_sp<SkImage>>& labels,
|
||||
bool bottomLeftOrigin) {
|
||||
SkASSERT(kNumLabels == labels.count());
|
||||
@ -231,7 +231,7 @@ private:
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void makeLabels(GrContext* context) {
|
||||
void makeLabels(GrDirectContext* context) {
|
||||
if (fLabels.count()) {
|
||||
return;
|
||||
}
|
||||
@ -251,13 +251,11 @@ private:
|
||||
SkASSERT(kNumLabels == fLabels.count());
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
if (!context || context->abandoned()) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
|
||||
SkASSERT(context->asDirectContext());
|
||||
|
||||
this->makeLabels(context);
|
||||
fReferenceImages[0] = make_reference_image(context, fLabels, false);
|
||||
fReferenceImages[1] = make_reference_image(context, fLabels, true);
|
||||
|
@ -81,7 +81,7 @@ GM::GM(SkColor bgColor) {
|
||||
|
||||
GM::~GM() {}
|
||||
|
||||
DrawResult GM::gpuSetup(GrContext* context, SkCanvas* canvas, SkString* errorMsg) {
|
||||
DrawResult GM::gpuSetup(GrDirectContext* context, SkCanvas* canvas, SkString* errorMsg) {
|
||||
TRACE_EVENT1("GM", TRACE_FUNC, "name", TRACE_STR_COPY(this->getName()));
|
||||
if (!fGpuSetup) {
|
||||
// When drawn in viewer, gpuSetup will be called multiple times with the same
|
||||
|
8
gm/gm.h
8
gm/gm.h
@ -19,7 +19,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GrContext;
|
||||
class GrDirectContext;
|
||||
class GrRecordingContext;
|
||||
class GrRenderTargetContext;
|
||||
class SkCanvas;
|
||||
@ -113,11 +113,11 @@ namespace skiagm {
|
||||
|
||||
static constexpr char kErrorMsg_DrawSkippedGpuOnly[] = "This test is for GPU configs only.";
|
||||
|
||||
DrawResult gpuSetup(GrContext* context, SkCanvas* canvas) {
|
||||
DrawResult gpuSetup(GrDirectContext* context, SkCanvas* canvas) {
|
||||
SkString errorMsg;
|
||||
return this->gpuSetup(context, canvas, &errorMsg);
|
||||
}
|
||||
DrawResult gpuSetup(GrContext*, SkCanvas*, SkString* errorMsg);
|
||||
DrawResult gpuSetup(GrDirectContext*, SkCanvas*, SkString* errorMsg);
|
||||
void gpuTeardown();
|
||||
|
||||
void onceBeforeDraw() {
|
||||
@ -170,7 +170,7 @@ namespace skiagm {
|
||||
|
||||
protected:
|
||||
// onGpuSetup is called once before any other processing with a direct context.
|
||||
virtual DrawResult onGpuSetup(GrContext*, SkString*) { return DrawResult::kOk; }
|
||||
virtual DrawResult onGpuSetup(GrDirectContext*, SkString*) { return DrawResult::kOk; }
|
||||
virtual void onGpuTeardown() {}
|
||||
virtual void onOnceBeforeDraw();
|
||||
virtual DrawResult onDraw(SkCanvas*, SkString* errorMsg);
|
||||
|
@ -23,12 +23,11 @@
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/core/SkYUVAIndex.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "include/private/SkTo.h"
|
||||
#include "src/core/SkMathPriv.h"
|
||||
#include "src/core/SkYUVMath.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/gpu/YUVUtils.h"
|
||||
|
||||
@ -120,7 +119,7 @@ protected:
|
||||
return rgbaBmp;
|
||||
}
|
||||
|
||||
static bool CreateYUVBackendTextures(GrContext* context, SkBitmap bmps[4],
|
||||
static bool CreateYUVBackendTextures(GrDirectContext* context, SkBitmap bmps[4],
|
||||
SkYUVAIndex indices[4],
|
||||
YUVABackendReleaseContext* beContext) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@ -150,7 +149,7 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
sk_sp<SkImage> makeYUVAImage(GrContext* context) {
|
||||
sk_sp<SkImage> makeYUVAImage(GrDirectContext* context) {
|
||||
auto releaseContext = new YUVABackendReleaseContext(context);
|
||||
SkYUVAIndex indices[4];
|
||||
|
||||
@ -170,7 +169,7 @@ protected:
|
||||
releaseContext);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> createReferenceImage(GrContext* context) {
|
||||
sk_sp<SkImage> createReferenceImage(GrDirectContext* context) {
|
||||
auto planeReleaseContext = new YUVABackendReleaseContext(context);
|
||||
SkYUVAIndex indices[4];
|
||||
|
||||
@ -210,13 +209,11 @@ protected:
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
if (!context || context->abandoned()) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
|
||||
SkASSERT(context->asDirectContext());
|
||||
|
||||
fRGBABmp = CreateBmpAndPlanes("images/mandrill_32.png", fYUVABmps);
|
||||
|
||||
// We make a version of this image for each draw because, if any draw flattens it to
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "src/core/SkAutoPixmapStorage.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
@ -94,7 +94,7 @@ private:
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
sk_sp<SkImage> createRectangleTextureImg(GrContext* context, GrSurfaceOrigin origin,
|
||||
sk_sp<SkImage> createRectangleTextureImg(GrDirectContext* context, GrSurfaceOrigin origin,
|
||||
const SkBitmap content) {
|
||||
SkASSERT(content.colorType() == kRGBA_8888_SkColorType);
|
||||
auto format = GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_RECTANGLE);
|
||||
@ -122,7 +122,7 @@ private:
|
||||
return SkImage::MakeFromAdoptedTexture(context, bet, origin, kRGBA_8888_SkColorType);
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
if (!context || context->abandoned()) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "include/core/SkYUVASizeInfo.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrConfig.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "include/private/GrTypesPriv.h"
|
||||
@ -46,7 +46,6 @@
|
||||
#include "include/utils/SkTextUtils.h"
|
||||
#include "src/core/SkYUVMath.h"
|
||||
#include "src/gpu/GrCaps.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/gpu/GrRecordingContextPriv.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
#include "tools/gpu/YUVUtils.h"
|
||||
@ -1012,7 +1011,7 @@ static void draw_row_label(SkCanvas* canvas, int y, int yuvFormat) {
|
||||
canvas->drawString(rowLabel, 0, y, font, paint);
|
||||
}
|
||||
|
||||
static GrBackendTexture create_yuva_texture(GrContext* context, const SkBitmap& bm, int index,
|
||||
static GrBackendTexture create_yuva_texture(GrDirectContext* context, const SkBitmap& bm, int index,
|
||||
YUVABackendReleaseContext* releaseContext) {
|
||||
return context->createBackendTexture(bm.pixmap(), GrRenderable::kNo, GrProtected::kNo,
|
||||
YUVABackendReleaseContext::CreationCompleteProc(index),
|
||||
@ -1238,7 +1237,7 @@ protected:
|
||||
releaseContext);
|
||||
}
|
||||
|
||||
bool createImages(GrContext* context) {
|
||||
bool createImages(GrDirectContext* context) {
|
||||
int counter = 0;
|
||||
for (bool opaque : { false, true }) {
|
||||
for (int cs = kJPEG_SkYUVColorSpace; cs <= kLastEnum_SkYUVColorSpace; ++cs) {
|
||||
@ -1372,7 +1371,7 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
this->createBitmaps();
|
||||
|
||||
if (context && context->abandoned()) {
|
||||
@ -1530,7 +1529,7 @@ protected:
|
||||
fTargetColorSpace = SkColorSpace::MakeSRGB()->makeColorSpin();
|
||||
}
|
||||
|
||||
bool createImages(GrContext* context) {
|
||||
bool createImages(GrDirectContext* context) {
|
||||
for (bool opaque : { false, true }) {
|
||||
PlaneData planes;
|
||||
extract_planes(fOriginalBMs[opaque], kJPEG_SkYUVColorSpace, &planes);
|
||||
@ -1598,13 +1597,11 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
if (!context || context->abandoned()) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
|
||||
SkASSERT(context->asDirectContext());
|
||||
|
||||
this->createBitmaps();
|
||||
if (!this->createImages(context)) {
|
||||
*errorMsg = "Failed to create YUV images";
|
||||
|
@ -15,8 +15,7 @@
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "tools/gpu/vk/VkYcbcrSamplerHelper.h"
|
||||
|
||||
static void release_ycbcrhelper(void* releaseContext) {
|
||||
@ -70,13 +69,11 @@ protected:
|
||||
return DrawResult::kOk;
|
||||
}
|
||||
|
||||
DrawResult onGpuSetup(GrContext* context, SkString* errorMsg) override {
|
||||
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
||||
if (!context || context->abandoned()) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
|
||||
SkASSERT(context->asDirectContext());
|
||||
|
||||
if (context->backend() != GrBackendApi::kVulkan) {
|
||||
*errorMsg = "This GM requires a Vulkan context.";
|
||||
return DrawResult::kSkip;
|
||||
|
@ -131,8 +131,11 @@ static void init(Source* source, std::shared_ptr<skiagm::GM> gm) {
|
||||
source->size = gm->getISize();
|
||||
source->tweak = [gm](GrContextOptions* options) { gm->modifyGrContextOptions(options); };
|
||||
source->draw = [gm](SkCanvas* canvas) {
|
||||
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
|
||||
: nullptr;
|
||||
|
||||
SkString err;
|
||||
switch (gm->gpuSetup(canvas->getGrContext(), canvas, &err)) {
|
||||
switch (gm->gpuSetup(direct, canvas, &err)) {
|
||||
case skiagm::DrawResult::kOk : break;
|
||||
case skiagm::DrawResult::kSkip: return skip;
|
||||
case skiagm::DrawResult::kFail: return fail(err.c_str());
|
||||
|
@ -172,7 +172,11 @@ public:
|
||||
GrContextFactory::ContextType type() const { return fType; }
|
||||
GrBackendApi backend() const { return GrContextFactory::ContextTypeBackend(fType); }
|
||||
|
||||
// TODO: remove 'grContext' - replacing all instances w/ 'directContext'
|
||||
GrContext* grContext() const { return fGrContext; }
|
||||
GrDirectContext* directContext() const {
|
||||
return fGrContext ? fGrContext->asDirectContext() : nullptr;
|
||||
}
|
||||
|
||||
TestContext* testContext() const { return fTestContext; }
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "include/gpu/GrRecordingContext.h"
|
||||
#include "tools/viewer/GMSlide.h"
|
||||
|
||||
GMSlide::GMSlide(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
|
||||
@ -29,7 +31,10 @@ void GMSlide::gpuTeardown() {
|
||||
void GMSlide::draw(SkCanvas* canvas) {
|
||||
SkString msg;
|
||||
|
||||
auto result = fGM->gpuSetup(canvas->getGrContext(), canvas, &msg);
|
||||
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
|
||||
: nullptr;
|
||||
|
||||
auto result = fGM->gpuSetup(direct, canvas, &msg);
|
||||
if (result != skiagm::GM::DrawResult::kOk) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user