• 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 "include/core/SkRefCnt.h"
12 #include "include/gpu/ganesh/GrTypes.h"
13 #include "include/private/base/SkAPI.h"
14 
15 #include <cstdint>
16 
17 class GrBaseContextPriv;
18 class GrCaps;
19 class GrContextThreadSafeProxy;
20 class GrDirectContext;
21 class GrImageContext;
22 class GrRecordingContext;
23 enum SkColorType : int;
24 enum class SkTextureCompressionType;
25 struct GrContextOptions;
26 class GrBackendFormat;
27 
28 class SK_API GrContext_Base : public SkRefCnt {
29 public:
30     ~GrContext_Base() override;
31 
32     /*
33      * Safely downcast to a GrDirectContext.
34      */
asDirectContext()35     virtual GrDirectContext* asDirectContext() { return nullptr; }
36 
37     /*
38      * The 3D API backing this context
39      */
40     SK_API GrBackendApi backend() const;
41 
42     /*
43      * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
44      * It is guaranteed that this backend format will be the one used by the GrContext
45      * SkColorType and GrSurfaceCharacterization-based createBackendTexture methods.
46      *
47      * The caller should check that the returned format is valid.
48      */
49     SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const;
50 
51     SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const;
52 
53     /**
54      * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
55      * rendering is supported for the color type. 0 is returned if rendering to this color type
56      * is not supported at all.
57      */
58     SK_API int maxSurfaceSampleCountForColorType(SkColorType colorType) const;
59 
60     // TODO: When the public version is gone, rename to refThreadSafeProxy and add raw ptr ver.
61     sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
62 
63     // Provides access to functions that aren't part of the public API.
64     GrBaseContextPriv priv();
65     const GrBaseContextPriv priv() const;  // NOLINT(readability-const-return-type)
66 
67     // Advanced Filter: Record process name, so that we can get it in other places easily.
68     const std::string& getProcessName() const;
69 
70 protected:
71     friend class GrBaseContextPriv; // for hidden functions
72 
73     GrContext_Base(sk_sp<GrContextThreadSafeProxy>);
74 
75     virtual bool init();
76 
77     /**
78      * An identifier for this context. The id is used by all compatible contexts. For example,
79      * if SkImages are created on one thread using an image creation context, then fed into a
80      * DDL Recorder on second thread (which has a recording context) and finally replayed on
81      * a third thread with a direct context, then all three contexts will report the same id.
82      * It is an error for an image to be used with contexts that report different ids.
83      */
84     uint32_t contextID() const;
85 
matches(GrContext_Base * candidate)86     bool matches(GrContext_Base* candidate) const {
87         return candidate && candidate->contextID() == this->contextID();
88     }
89 
90     /*
91      * The options in effect for this context
92      */
93     const GrContextOptions& options() const;
94 
95     const GrCaps* caps() const;
96     sk_sp<const GrCaps> refCaps() const;
97 
asImageContext()98     virtual GrImageContext* asImageContext() { return nullptr; }
asRecordingContext()99     virtual GrRecordingContext* asRecordingContext() { return nullptr; }
100 
101     sk_sp<GrContextThreadSafeProxy>         fThreadSafeProxy;
102 
103 private:
104     using INHERITED = SkRefCnt;
105 };
106 
107 #endif
108