• 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 "include/gpu/GrContext.h"
9 #include "src/gpu/GrCaps.h"
10 #include "src/gpu/GrContextPriv.h"
11 #include "src/gpu/GrContextThreadSafeProxyPriv.h"
12 #include "src/gpu/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 and attempt to reduce opList
56         // splitting.
57         this->setupDrawingManager(true, true);
58 
59         SkASSERT(this->caps());
60 
61         return true;
62     }
63 
onGetAtlasManager()64     GrAtlasManager* onGetAtlasManager() override {
65         SkASSERT(0);   // the DDL Recorders should never invoke this
66         return nullptr;
67     }
68 
69 private:
70     typedef GrContext INHERITED;
71 };
72 
MakeDDL(const sk_sp<GrContextThreadSafeProxy> & proxy)73 sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
74     sk_sp<GrContext> context(new GrDDLContext(proxy));
75 
76     if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) {
77         return nullptr;
78     }
79     return context;
80 }
81