blob: 6836e4634fdcf192e146ffc8e4eb5a5a43dc5c38 [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 Phillips60dd62b2019-03-12 16:28:59 +000055 // DDL contexts/drawing managers always sort the oplists. This, in turn, implies that
56 // explicit resource allocation is always on (regardless of how Skia is compiled).
57 this->setupDrawingManager(true, true);
Robert Phillips56181ba2019-03-08 12:00:45 -050058
Robert Phillipsbb606772019-02-04 17:50:57 -050059 SkASSERT(this->caps());
60
Robert Phillipsa3457b82018-03-08 11:30:12 -050061 return true;
62 }
63
64 GrAtlasManager* onGetAtlasManager() override {
65 SkASSERT(0); // the DDL Recorders should never invoke this
66 return nullptr;
67 }
68
69private:
70 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}