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 "GrTypes.h"
13 
14 class GrBaseContextPriv;
15 class GrContext;
16 class GrImageContext;
17 class GrRecordingContext;
18 
19 class SK_API GrContext_Base : public SkRefCnt {
20 public:
21     virtual ~GrContext_Base();
22 
23     /*
24      * The 3D API backing this context
25      */
backend()26     GrBackendApi backend() const { return fBackend; }
27 
28     // Provides access to functions that aren't part of the public API.
29     GrBaseContextPriv priv();
30     const GrBaseContextPriv priv() const;
31 
32 protected:
33     friend class GrBaseContextPriv; // for hidden functions
34 
35     GrContext_Base(GrBackendApi backend, uint32_t uniqueID);
36 
37     /**
38      * An identifier for this context. The id is used by all compatible contexts. For example,
39      * if SkImages are created on one thread using an image creation context, then fed into a
40      * DDL Recorder on second thread (which has a recording context) and finally replayed on
41      * a third thread with a direct context, then all three contexts will report the same id.
42      * It is an error for an image to be used with contexts that report different ids.
43      */
contextID()44     uint32_t contextID() const { return fContextID; }
45 
asBaseContext()46     GrContext_Base* asBaseContext() { return this; }
asImageContext()47     virtual GrImageContext* asImageContext() { return nullptr; }
asRecordingContext()48     virtual GrRecordingContext* asRecordingContext() { return nullptr; }
asDirectContext()49     virtual GrContext* asDirectContext() { return nullptr; }
50 
51 private:
52     const GrBackendApi fBackend;
53     const uint32_t     fContextID;
54 
55     typedef SkRefCnt INHERITED;
56 };
57 
58 #endif
59