blob: 1373e4341bd1a4942c1a4daa50a04730d716b529 [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
8#include "GrContext.h"
Brian Salomonc7fe0f72018-05-11 10:14:21 -04009#include "GrCaps.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050010#include "GrContextPriv.h"
Brian Salomon52aacd62018-05-10 12:57:17 -040011#include "GrContextThreadSafeProxyPriv.h"
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050012#include "GrSkSLFPFactoryCache.h"
Robert Phillipsa3457b82018-03-08 11:30:12 -050013
14/**
15 * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
16 * cannot allocate any GPU resources.
17 */
18class SK_API GrDDLContext : public GrContext {
19public:
20 GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
Robert Phillipsc1541ae2019-02-04 12:05:37 -050021 : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050022 fThreadSafeProxy = std::move(proxy);
23 }
24
Robert Phillipsc1541ae2019-02-04 12:05:37 -050025 ~GrDDLContext() override { }
Robert Phillipsa3457b82018-03-08 11:30:12 -050026
27 void abandonContext() override {
28 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
29 INHERITED::abandonContext();
30 }
31
32 void releaseResourcesAndAbandonContext() override {
33 SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
34 INHERITED::releaseResourcesAndAbandonContext();
35 }
36
37 void freeGpuResources() override {
38 SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense
39 INHERITED::freeGpuResources();
40 }
41
42protected:
Robert Phillipsa41c6852019-02-07 10:44:10 -050043 // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
44 // GrRecordingContext!
45 GrContext* asDirectContext() override { return nullptr; }
46
Robert Phillipsbb606772019-02-04 17:50:57 -050047 bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override {
48 SkASSERT(caps && FPFactoryCache);
Robert Phillipsa3457b82018-03-08 11:30:12 -050049 SkASSERT(fThreadSafeProxy); // should've been set in the ctor
50
Robert Phillipsbb606772019-02-04 17:50:57 -050051 if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050052 return false;
53 }
54
Robert Phillipsbb606772019-02-04 17:50:57 -050055 SkASSERT(this->caps());
56
Robert Phillipsa3457b82018-03-08 11:30:12 -050057 return true;
58 }
59
60 GrAtlasManager* onGetAtlasManager() override {
61 SkASSERT(0); // the DDL Recorders should never invoke this
62 return nullptr;
63 }
64
65private:
66 typedef GrContext INHERITED;
67};
68
Kevin Lubickb5502b22018-03-12 10:17:06 -040069sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050070 sk_sp<GrContext> context(new GrDDLContext(proxy));
71
Robert Phillipsbb606772019-02-04 17:50:57 -050072 if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) {
Robert Phillipsa3457b82018-03-08 11:30:12 -050073 return nullptr;
74 }
75 return context;
76}