• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
9 #include "GrCaps.h"
10 #include "GrContextPriv.h"
11 #include "GrContextThreadSafeProxyPriv.h"
12 #include "GrSkSLFPFactoryCache.h"
13 
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  */
18 class SK_API GrDDLContext : public GrContext {
19 public:
GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)20     GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
21             : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) {
22         fThreadSafeProxy = std::move(proxy);
23     }
24 
~GrDDLContext()25     ~GrDDLContext() override { }
26 
abandonContext()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 
releaseResourcesAndAbandonContext()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 
freeGpuResources()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 
42 protected:
43     // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
44     // GrRecordingContext!
asDirectContext()45     GrContext* asDirectContext() override { return nullptr; }
46 
init(sk_sp<const GrCaps> caps,sk_sp<GrSkSLFPFactoryCache> FPFactoryCache)47     bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override {
48         SkASSERT(caps && FPFactoryCache);
49         SkASSERT(fThreadSafeProxy); // should've been set in the ctor
50 
51         if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
52             return false;
53         }
54 
55         // DDL contexts/drawing managers always sort the oplists. This, in turn, implies that
56         // explicit resource allocation is always on (regardless of whatever the client specified
57         // in their context options).
58         this->setupDrawingManager(true, true);
59 
60         SkASSERT(this->caps());
61 
62         return true;
63     }
64 
onGetAtlasManager()65     GrAtlasManager* onGetAtlasManager() override {
66         SkASSERT(0);   // the DDL Recorders should never invoke this
67         return nullptr;
68     }
69 
70 private:
71     typedef GrContext INHERITED;
72 };
73 
MakeDDL(const sk_sp<GrContextThreadSafeProxy> & proxy)74 sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
75     sk_sp<GrContext> context(new GrDDLContext(proxy));
76 
77     if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) {
78         return nullptr;
79     }
80     return context;
81 }
82