Skia
2D Graphics Library
GrContextThreadSafeProxy.h
Go to the documentation of this file.
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 GrContextThreadSafeProxy_DEFINED
9 #define GrContextThreadSafeProxy_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 
13 #if defined(SK_GANESH)
14 
16 #include "include/gpu/GpuTypes.h"
18 #include "include/gpu/GrTypes.h"
19 
20 #include <atomic>
21 
22 class GrBackendFormat;
23 class GrCaps;
24 class GrContextThreadSafeProxyPriv;
25 class GrSurfaceCharacterization;
26 class GrThreadSafeCache;
27 class GrThreadSafePipelineBuilder;
28 class SkSurfaceProps;
29 enum class SkTextureCompressionType;
30 
31 namespace sktext::gpu { class TextBlobRedrawCoordinator; }
32 
37 class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt<GrContextThreadSafeProxy> {
38 public:
40 
88  GrSurfaceCharacterization createCharacterization(
89  size_t cacheMaxResourceBytes,
90  const SkImageInfo& ii,
91  const GrBackendFormat& backendFormat,
92  int sampleCount,
93  GrSurfaceOrigin origin,
94  const SkSurfaceProps& surfaceProps,
95  bool isMipMapped,
96  bool willUseGLFBO0 = false,
97  bool isTextureable = true,
98  GrProtected isProtected = GrProtected::kNo,
99  bool vkRTSupportsInputAttachment = false,
100  bool forVulkanSecondaryCommandBuffer = false);
101 
102  /*
103  * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
104  * It is guaranteed that this backend format will be the one used by the following
105  * SkColorType and GrSurfaceCharacterization-based createBackendTexture methods.
106  *
107  * The caller should check that the returned format is valid.
108  */
109  GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const;
110 
118  GrBackendFormat compressedBackendFormat(SkTextureCompressionType c) const;
119 
125  int maxSurfaceSampleCountForColorType(SkColorType colorType) const;
126 
127  bool isValid() const { return nullptr != fCaps; }
128 
129  bool operator==(const GrContextThreadSafeProxy& that) const {
130  // Each GrContext should only ever have a single thread-safe proxy.
131  SkASSERT((this == &that) == (this->fContextID == that.fContextID));
132  return this == &that;
133  }
134 
135  bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
136 
137  // Provides access to functions that aren't part of the public API.
138  GrContextThreadSafeProxyPriv priv();
139  const GrContextThreadSafeProxyPriv priv() const; // NOLINT(readability-const-return-type)
140 
141 private:
142  friend class GrContextThreadSafeProxyPriv; // for ctor and hidden methods
143 
144  // DDL TODO: need to add unit tests for backend & maybe options
146 
147  void abandonContext();
148  bool abandoned() const;
149 
150  // TODO: This should be part of the constructor but right now we have a chicken-and-egg problem
151  // with GrContext where we get the caps by creating a GPU which requires a context (see the
152  // `init` method on GrContext_Base).
154 
155  const GrBackendApi fBackend;
156  const GrContextOptions fOptions;
157  const uint32_t fContextID;
158  sk_sp<const GrCaps> fCaps;
159  std::unique_ptr<sktext::gpu::TextBlobRedrawCoordinator> fTextBlobRedrawCoordinator;
160  std::unique_ptr<GrThreadSafeCache> fThreadSafeCache;
161  sk_sp<GrThreadSafePipelineBuilder> fPipelineBuilder;
162  std::atomic<bool> fAbandoned{false};
163 };
164 
165 #else // !defined(SK_GANESH)
166 class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt<GrContextThreadSafeProxy> {};
167 #endif
168 
169 #endif
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:156
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:96
SkColorType
Describes how pixel bits encode color.
Definition: SkColorType.h:19
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:355
bool operator==(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:345
SkTextureCompressionType
Definition: SkTextureCompressionType.h:20
Definition: GrBackendSurface.h:49
Definition: GrContextThreadSafeProxy.h:166
Definition: SkRefCnt.h:160
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:52
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Renderable
Is a texture renderable or not.
Definition: GpuTypes.h:69
Protected
Is the data protected on the GPU or not.
Definition: GpuTypes.h:61
Definition: SkCanvas.h:74
Definition: GrContextOptions.h:375
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:194