• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 #ifndef GrContext_Base_DEFINED
9 #define GrContext_Base_DEFINED
10 
11 #include "SkRefCnt.h"
12 #include "GrContextOptions.h"
13 #include "GrTypes.h"
14 
15 class GrBaseContextPriv;
16 class GrCaps;
17 class GrContext;
18 class GrImageContext;
19 class GrRecordingContext;
20 class GrSkSLFPFactoryCache;
21 
22 class SK_API GrContext_Base : public SkRefCnt {
23 public:
24     virtual ~GrContext_Base();
25 
26     /*
27      * The 3D API backing this context
28      */
backend()29     GrBackendApi backend() const { return fBackend; }
30 
31     // Provides access to functions that aren't part of the public API.
32     GrBaseContextPriv priv();
33     const GrBaseContextPriv priv() const;
34 
35 protected:
36     friend class GrBaseContextPriv; // for hidden functions
37 
38     GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t contextID);
39 
40     virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>);
41 
42     /**
43      * An identifier for this context. The id is used by all compatible contexts. For example,
44      * if SkImages are created on one thread using an image creation context, then fed into a
45      * DDL Recorder on second thread (which has a recording context) and finally replayed on
46      * a third thread with a direct context, then all three contexts will report the same id.
47      * It is an error for an image to be used with contexts that report different ids.
48      */
contextID()49     uint32_t contextID() const { return fContextID; }
50 
matches(GrContext_Base * candidate)51     bool matches(GrContext_Base* candidate) const {
52         return candidate->contextID() == this->contextID();
53     }
54 
55     /*
56      * The options in effect for this context
57      */
options()58     const GrContextOptions& options() const { return fOptions; }
59 
60     bool explicitlyAllocateGPUResources() const;
61 
62     const GrCaps* caps() const;
63     sk_sp<const GrCaps> refCaps() const;
64 
65     sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
66 
asImageContext()67     virtual GrImageContext* asImageContext() { return nullptr; }
asRecordingContext()68     virtual GrRecordingContext* asRecordingContext() { return nullptr; }
asDirectContext()69     virtual GrContext* asDirectContext() { return nullptr; }
70 
71 private:
72     const GrBackendApi          fBackend;
73     const GrContextOptions      fOptions;
74     const uint32_t              fContextID;
75     sk_sp<const GrCaps>         fCaps;
76     sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
77 
78     typedef SkRefCnt INHERITED;
79 };
80 
81 #endif
82