blob: 616f7c448600586e813c9dc9bb4614319063a4ee [file] [log] [blame]
Robert Phillipsa3457b82018-03-08 11:30:12 -05001/*
2 * Copyright 2018 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrCaps.h"
10#include "src/gpu/GrContextPriv.h"
11#include "src/gpu/GrContextThreadSafeProxyPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrSkSLFPFactoryCache.h"
Robert Phillips7f11fb52019-12-03 13:35:19 -050013#include "src/gpu/effects/GrSkSLFP.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050014
15/**
16 * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
17 * cannot allocate any GPU resources.
18 */
Jim Van Verth861ac612019-11-27 09:41:43 -050019class GrDDLContext final : public GrContext {
Robert Phillipsa3457b82018-03-08 11:30:12 -050020public:
21 GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
Robert Phillipsc1541ae2019-02-04 12:05:37 -050022 : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050023 fThreadSafeProxy = std::move(proxy);
24 }
25
Brian Salomon161c8ed2019-11-27 09:12:47 -050026 ~GrDDLContext() override {}
Robert Phillipsa3457b82018-03-08 11:30:12 -050027
Brian Salomon161c8ed2019-11-27 09:12:47 -050028 void abandonContext() override {
Robert Phillipsa3457b82018-03-08 11:30:12 -050029 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
30 INHERITED::abandonContext();
31 }
32
Brian Salomon161c8ed2019-11-27 09:12:47 -050033 void releaseResourcesAndAbandonContext() override {
Robert Phillipsa3457b82018-03-08 11:30:12 -050034 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
35 INHERITED::releaseResourcesAndAbandonContext();
36 }
37
Brian Salomon161c8ed2019-11-27 09:12:47 -050038 void freeGpuResources() override {
Robert Phillipsa3457b82018-03-08 11:30:12 -050039 SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense
40 INHERITED::freeGpuResources();
41 }
42
Robert Phillips933484f2019-11-26 09:38:55 -050043private:
Robert Phillipsa41c6852019-02-07 10:44:10 -050044 // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
45 // GrRecordingContext!
Brian Salomon161c8ed2019-11-27 09:12:47 -050046 GrContext* asDirectContext() override { return nullptr; }
Robert Phillipsa41c6852019-02-07 10:44:10 -050047
Brian Salomon161c8ed2019-11-27 09:12:47 -050048 bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override {
Robert Phillipsbb606772019-02-04 17:50:57 -050049 SkASSERT(caps && FPFactoryCache);
Robert Phillipsa3457b82018-03-08 11:30:12 -050050 SkASSERT(fThreadSafeProxy); // should've been set in the ctor
51
Robert Phillipsbb606772019-02-04 17:50:57 -050052 if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050053 return false;
54 }
55
Greg Danielf41b2bd2019-08-22 16:19:24 -040056 // DDL contexts/drawing managers always sort the oplists and attempt to reduce opsTask
Robert Phillips6db27c22019-05-01 10:43:56 -040057 // splitting.
58 this->setupDrawingManager(true, true);
Robert Phillips56181ba2019-03-08 12:00:45 -050059
Robert Phillipsbb606772019-02-04 17:50:57 -050060 SkASSERT(this->caps());
61
Robert Phillipsa3457b82018-03-08 11:30:12 -050062 return true;
63 }
64
Brian Salomon161c8ed2019-11-27 09:12:47 -050065 GrAtlasManager* onGetAtlasManager() override {
Robert Phillipsa3457b82018-03-08 11:30:12 -050066 SkASSERT(0); // the DDL Recorders should never invoke this
67 return nullptr;
68 }
69
Robert Phillipsa3457b82018-03-08 11:30:12 -050070 typedef GrContext INHERITED;
71};
72
Kevin Lubickb5502b22018-03-12 10:17:06 -040073sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050074 sk_sp<GrContext> context(new GrDDLContext(proxy));
75
Robert Phillipsbb606772019-02-04 17:50:57 -050076 if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050077 return nullptr;
78 }
79 return context;
80}