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/GrTypes.h"
13#include "include/private/base/SkAPI.h"
14
15#include <cstdint>
16
17class GrBaseContextPriv;
18class GrCaps;
19class GrContextThreadSafeProxy;
20class GrDirectContext;
21class GrImageContext;
22class GrRecordingContext;
23enum SkColorType : int;
24enum class SkTextureCompressionType;
25struct GrContextOptions;
26class GrBackendFormat;
27
28class GrContext_Base : public SkRefCnt {
29public:
30 ~GrContext_Base() override;
31
32 /*
33 * Safely downcast to a GrDirectContext.
34 */
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
67protected:
68 friend class GrBaseContextPriv; // for hidden functions
69
70 GrContext_Base(sk_sp<GrContextThreadSafeProxy>);
71
72 virtual bool init();
73
74 /**
75 * An identifier for this context. The id is used by all compatible contexts. For example,
76 * if SkImages are created on one thread using an image creation context, then fed into a
77 * DDL Recorder on second thread (which has a recording context) and finally replayed on
78 * a third thread with a direct context, then all three contexts will report the same id.
79 * It is an error for an image to be used with contexts that report different ids.
80 */
81 uint32_t contextID() const;
82
83 bool matches(GrContext_Base* candidate) const {
84 return candidate && candidate->contextID() == this->contextID();
85 }
86
87 /*
88 * The options in effect for this context
89 */
90 const GrContextOptions& options() const;
91
92 const GrCaps* caps() const;
93 sk_sp<const GrCaps> refCaps() const;
94
95 virtual GrImageContext* asImageContext() { return nullptr; }
96 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
97
98 sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
99
100private:
101 using INHERITED = SkRefCnt;
102};
103
104#endif
105

source code of flutter_engine/third_party/skia/include/private/gpu/ganesh/GrContext_Base.h