Skia
2D Graphics Library
GrDirectContext.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 GrDirectContext_DEFINED
9 #define GrDirectContext_DEFINED
10 
11 #include "include/core/SkColor.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkTypes.h"
14 #include "include/gpu/GpuTypes.h"
17 #include "include/gpu/GrTypes.h"
18 
19 #include <chrono>
20 #include <cstddef>
21 #include <cstdint>
22 #include <memory>
23 #include <string_view>
24 
25 class GrAtlasManager;
26 class GrBackendSemaphore;
27 class GrBackendFormat;
28 class GrBackendTexture;
30 class GrClientMappedBufferManager;
32 class GrDirectContextPriv;
33 class GrGpu;
34 class GrResourceCache;
35 class GrResourceProvider;
36 class SkData;
37 class SkImage;
38 class SkPixmap;
39 class SkSurface;
40 class SkTaskGroup;
41 class SkTraceMemoryDump;
42 enum SkColorType : int;
43 enum class SkTextureCompressionType;
44 struct GrMockOptions;
45 struct GrVkBackendContext; // IWYU pragma: keep
46 struct GrD3DBackendContext; // IWYU pragma: keep
47 struct GrMtlBackendContext; // IWYU pragma: keep
48 
49 namespace skgpu {
50  class MutableTextureState;
51 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
52  namespace ganesh { class SmallPathAtlasMgr; }
53 #endif
54 }
55 namespace sktext { namespace gpu { class StrikeCache; } }
56 namespace wgpu { class Device; } // IWYU pragma: keep
57 
58 namespace SkSurfaces {
59 enum class BackendSurfaceAccess;
60 }
61 
62 class SK_API GrDirectContext : public GrRecordingContext {
63 public:
64 #if defined(SK_VULKAN) && !defined(SK_DISABLE_LEGACY_VK_GRDIRECTCONTEXT_FACTORIES)
72  static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
73  static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&);
74 #endif
75 
76 #ifdef SK_METAL
84  static sk_sp<GrDirectContext> MakeMetal(const GrMtlBackendContext&, const GrContextOptions&);
85  static sk_sp<GrDirectContext> MakeMetal(const GrMtlBackendContext&);
94  static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue, const GrContextOptions&);
95  static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue);
96 #endif
97 
98 #ifdef SK_DIRECT3D
103  static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&, const GrContextOptions&);
104  static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&);
105 #endif
106 
107  static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
108  static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*);
109 
110  ~GrDirectContext() override;
111 
120  void resetContext(uint32_t state = kAll_GrBackendState);
121 
132 
153  void abandonContext() override;
154 
161  bool abandoned() override;
162 
168  bool isDeviceLost();
169 
170  // TODO: Remove this from public after migrating Chrome.
172 
188  bool oomed();
189 
203 
205  // Resource Cache
206 
214  void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
215 
219  size_t getResourceCacheLimit() const;
220 
229  void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
230 
235 
244  void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
245 
253  void setResourceCacheLimit(size_t maxResourceBytes);
254 
260 
275  std::chrono::milliseconds msNotUsed,
277 
278  // Temporary compatibility API for Android.
279  void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
280  this->performDeferredCleanup(msNotUsed);
281  }
282 
293  void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
294 
309 
314 
319 
324 
329 
335 
342 
344  // Misc.
345 
360  bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
361  bool deleteSemaphoresAfterWait = true);
362 
369  this->flush(GrFlushInfo());
370  this->submit(sync);
371  }
372 
398 
399  void flush() { this->flush(GrFlushInfo()); }
400 
411  void flush(const sk_sp<const SkImage>& image);
412 
417 
465  const GrFlushInfo& info);
466 
487  const GrFlushInfo& info,
488  const skgpu::MutableTextureState* newState = nullptr);
489 
499 
505  void flush(SkSurface* surface);
506 
522 
527 
529  // Chrome is using this!
530  void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
531 
533 
535 
543  using GrRecordingContext::defaultBackendFormat;
544 
567  int height,
568  const GrBackendFormat&,
570  GrRenderable,
572  std::string_view label = {});
573 
583  int height,
584  SkColorType,
586  GrRenderable,
588  std::string_view label = {});
589 
600  int height,
601  const GrBackendFormat&,
602  const SkColor4f& color,
604  GrRenderable,
606  GrGpuFinishedProc finishedProc = nullptr,
607  GrGpuFinishedContext finishedContext = nullptr,
608  std::string_view label = {});
609 
622  int height,
623  SkColorType,
624  const SkColor4f& color,
626  GrRenderable,
628  GrGpuFinishedProc finishedProc = nullptr,
629  GrGpuFinishedContext finishedContext = nullptr,
630  std::string_view label = {});
631 
652  int numLevels,
654  GrRenderable,
655  GrProtected,
656  GrGpuFinishedProc finishedProc = nullptr,
657  GrGpuFinishedContext finishedContext = nullptr,
658  std::string_view label = {});
659 
664  GrSurfaceOrigin textureOrigin,
665  GrRenderable renderable,
666  GrProtected isProtected,
667  GrGpuFinishedProc finishedProc = nullptr,
668  GrGpuFinishedContext finishedContext = nullptr,
669  std::string_view label = {});
670 
671  // Deprecated versions that do not take origin and assume top-left.
673  int numLevels,
674  GrRenderable renderable,
675  GrProtected isProtected,
676  GrGpuFinishedProc finishedProc = nullptr,
677  GrGpuFinishedContext finishedContext = nullptr,
678  std::string_view label = {});
679 
681  GrRenderable renderable,
682  GrProtected isProtected,
683  GrGpuFinishedProc finishedProc = nullptr,
684  GrGpuFinishedContext finishedContext = nullptr,
685  std::string_view label = {});
686 
697  const SkColor4f& color,
698  GrGpuFinishedProc finishedProc,
699  GrGpuFinishedContext finishedContext);
700 
713  SkColorType skColorType,
714  const SkColor4f& color,
715  GrGpuFinishedProc finishedProc,
716  GrGpuFinishedContext finishedContext);
717 
737  const SkPixmap srcData[],
738  int numLevels,
740  GrGpuFinishedProc finishedProc = nullptr,
741  GrGpuFinishedContext finishedContext = nullptr);
742 
747  const SkPixmap& srcData,
749  GrGpuFinishedProc finishedProc = nullptr,
750  GrGpuFinishedContext finishedContext = nullptr) {
751  return this->updateBackendTexture(texture,
752  &srcData,
753  1,
754  textureOrigin,
755  finishedProc,
756  finishedContext);
757  }
758 
759  // Deprecated version that does not take origin and assumes top-left.
761  const SkPixmap srcData[],
762  int numLevels,
763  GrGpuFinishedProc finishedProc,
764  GrGpuFinishedContext finishedContext);
765 
773  using GrRecordingContext::compressedBackendFormat;
774 
785  int height,
786  const GrBackendFormat&,
787  const SkColor4f& color,
790  GrGpuFinishedProc finishedProc = nullptr,
791  GrGpuFinishedContext finishedContext = nullptr);
792 
794  int height,
796  const SkColor4f& color,
799  GrGpuFinishedProc finishedProc = nullptr,
800  GrGpuFinishedContext finishedContext = nullptr);
801 
815  int height,
816  const GrBackendFormat&,
817  const void* data,
818  size_t dataSize,
821  GrGpuFinishedProc finishedProc = nullptr,
822  GrGpuFinishedContext finishedContext = nullptr);
823 
825  int height,
827  const void* data,
828  size_t dataSize,
831  GrGpuFinishedProc finishedProc = nullptr,
832  GrGpuFinishedContext finishedContext = nullptr);
833 
845  const SkColor4f& color,
846  GrGpuFinishedProc finishedProc,
847  GrGpuFinishedContext finishedContext);
848 
862  const void* data,
863  size_t dataSize,
864  GrGpuFinishedProc finishedProc,
865  GrGpuFinishedContext finishedContext);
866 
887  skgpu::MutableTextureState* previousState = nullptr,
888  GrGpuFinishedProc finishedProc = nullptr,
889  GrGpuFinishedContext finishedContext = nullptr);
892  skgpu::MutableTextureState* previousState = nullptr,
893  GrGpuFinishedProc finishedProc = nullptr,
894  GrGpuFinishedContext finishedContext = nullptr);
895 
897 
898  // This interface allows clients to pre-compile shaders and populate the runtime program cache.
899  // The key and data blobs should be the ones passed to the PersistentCache, in SkSL format.
900  //
901  // Steps to use this API:
902  //
903  // 1) Create a GrDirectContext as normal, but set fPersistentCache on GrContextOptions to
904  // something that will save the cached shader blobs. Set fShaderCacheStrategy to kSkSL. This
905  // will ensure that the blobs are SkSL, and are suitable for pre-compilation.
906  // 2) Run your application, and save all of the key/data pairs that are fed to the cache.
907  //
908  // 3) Switch over to shipping your application. Include the key/data pairs from above.
909  // 4) At startup (or any convenient time), call precompileShader for each key/data pair.
910  // This will compile the SkSL to create a GL program, and populate the runtime cache.
911  //
912  // This is only guaranteed to work if the context/device used in step #2 are created in the
913  // same way as the one used in step #4, and the same GrContextOptions are specified.
914  // Using cached shader blobs on a different device or driver are undefined.
915  bool precompileShader(const SkData& key, const SkData& data);
916 
917 #ifdef SK_ENABLE_DUMP_GPU
919  SkString dump() const;
920 #endif
921 
923  public:
925 
927 
928  bool operator==(const DirectContextID& that) const { return fID == that.fID; }
929  bool operator!=(const DirectContextID& that) const { return !(*this == that); }
930 
931  void makeInvalid() { fID = SK_InvalidUniqueID; }
932  bool isValid() const { return fID != SK_InvalidUniqueID; }
933 
934  private:
935  constexpr DirectContextID(uint32_t id) : fID(id) {}
936  uint32_t fID;
937  };
938 
939  DirectContextID directContextID() const { return fDirectContextID; }
940 
941  // Provides access to functions that aren't part of the public API.
942  GrDirectContextPriv priv();
943  const GrDirectContextPriv priv() const; // NOLINT(readability-const-return-type)
944 
945 protected:
947 
948  bool init() override;
949 
950  GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); }
951 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
952  skgpu::ganesh::SmallPathAtlasMgr* onGetSmallPathAtlasMgr();
953 #endif
954 
955  GrDirectContext* asDirectContext() override { return this; }
956 
957 private:
958  // This call will make sure out work on the GPU is finished and will execute any outstanding
959  // asynchronous work (e.g. calling finished procs, freeing resources, etc.) related to the
960  // outstanding work on the gpu. The main use currently for this function is when tearing down or
961  // abandoning the context.
962  //
963  // When we finish up work on the GPU it could trigger callbacks to the client. In the case we
964  // are abandoning the context we don't want the client to be able to use the GrDirectContext to
965  // issue more commands during the callback. Thus before calling this function we set the
966  // GrDirectContext's state to be abandoned. However, we need to be able to get by the abaonded
967  // check in the call to know that it is safe to execute this. The shouldExecuteWhileAbandoned
968  // bool is used for this signal.
969  void syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned);
970 
971  // This delete callback needs to be the first thing on the GrDirectContext so that it is the
972  // last thing destroyed. The callback may signal the client to clean up things that may need
973  // to survive the lifetime of some of the other objects on the GrDirectCotnext. So make sure
974  // we don't call it until all else has been destroyed.
975  class DeleteCallbackHelper {
976  public:
977  DeleteCallbackHelper(GrDirectContextDestroyedContext context,
979  : fContext(context), fProc(proc) {}
980 
981  ~DeleteCallbackHelper() {
982  if (fProc) {
983  fProc(fContext);
984  }
985  }
986 
987  private:
990  };
991  std::unique_ptr<DeleteCallbackHelper> fDeleteCallbackHelper;
992 
993  const DirectContextID fDirectContextID;
994  // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed
995  // after all of its users. Clients of fTaskGroup will generally want to ensure that they call
996  // wait() on it as they are being destroyed, to avoid the possibility of pending tasks being
997  // invoked after objects they depend upon have already been destroyed.
998  std::unique_ptr<SkTaskGroup> fTaskGroup;
999  std::unique_ptr<sktext::gpu::StrikeCache> fStrikeCache;
1000  std::unique_ptr<GrGpu> fGpu;
1001  std::unique_ptr<GrResourceCache> fResourceCache;
1002  std::unique_ptr<GrResourceProvider> fResourceProvider;
1003 
1004  // This is incremented before we start calling ReleaseProcs from GrSurfaces and decremented
1005  // after. A ReleaseProc may trigger code causing another resource to get freed so we to track
1006  // the count to know if we in a ReleaseProc at any level. When this is set to a value greated
1007  // than zero we will not allow abandonContext calls to be made on the context.
1008  int fInsideReleaseProcCnt = 0;
1009 
1010  bool fDidTestPMConversions;
1011  // true if the PM/UPM conversion succeeded; false otherwise
1012  bool fPMUPMConversionsRoundTrip;
1013 
1014  GrContextOptions::PersistentCache* fPersistentCache;
1015 
1016  std::unique_ptr<GrClientMappedBufferManager> fMappedBufferManager;
1017  std::unique_ptr<GrAtlasManager> fAtlasManager;
1018 
1019 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
1020  std::unique_ptr<skgpu::ganesh::SmallPathAtlasMgr> fSmallPathAtlasMgr;
1021 #endif
1022 
1023  friend class GrDirectContextPriv;
1024 };
1025 
1026 
1027 #endif
GrPurgeResourceOptions
Definition: GrTypes.h:243
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:156
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:157
static const uint32_t kAll_GrBackendState
This value translates to reseting all the context state for any backend.
Definition: GrTypes.h:185
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:96
void * GrDirectContextDestroyedContext
Definition: GrTypes.h:193
GrSemaphoresSubmitted
Enum used as return value when flush with semaphores so the client knows whether the valid semaphores...
Definition: GrTypes.h:238
void * GrGpuFinishedContext
Definition: GrTypes.h:187
void(* GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext)
Definition: GrTypes.h:194
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
Definition: GrTypes.h:188
GrSyncCpu
Definition: GrTypes.h:248
SkColorType
Describes how pixel bits encode color.
Definition: SkColorType.h:19
Types, consts, functions, and macros for colors.
SkTextureCompressionType
Definition: SkTextureCompressionType.h:20
static constexpr uint32_t SK_InvalidUniqueID
The unique IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:188
Definition: GrBackendSurface.h:49
Definition: GrBackendSurface.h:329
Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
Definition: GrBackendSemaphore.h:34
Definition: GrBackendSurface.h:176
Definition: GrContextThreadSafeProxy.h:166
Definition: GrDirectContext.h:922
DirectContextID()
Definition: GrDirectContext.h:926
bool operator!=(const DirectContextID &that) const
Definition: GrDirectContext.h:929
void makeInvalid()
Definition: GrDirectContext.h:931
bool operator==(const DirectContextID &that) const
Definition: GrDirectContext.h:928
static GrDirectContext::DirectContextID Next()
bool isValid() const
Definition: GrDirectContext.h:932
Definition: GrDirectContext.h:62
void setResourceCacheLimits(int maxResources, size_t maxResourceBytes)
DEPRECATED Specify the GPU resource cache limits.
bool updateCompressedBackendTexture(const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
If possible, updates a backend texture filled with the provided color.
GrBackendTexture createCompressedBackendTexture(int width, int height, const GrBackendFormat &, const SkColor4f &color, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
If possible, create a compressed backend texture initialized to a particular color.
GrDirectContext * asDirectContext() override
Definition: GrDirectContext.h:955
void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed)
Definition: GrDirectContext.h:279
size_t getResourceCachePurgeableBytes() const
Gets the number of bytes in the cache consumed by purgeable (e.g.
GrAtlasManager * onGetAtlasManager()
Definition: GrDirectContext.h:950
void checkAsyncWorkCompletion()
Checks whether any asynchronous work is complete and if so calls related callbacks.
void freeGpuResources()
Frees GPU created by the context.
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
Submit outstanding work to the gpu from all previously un-submitted flushes.
size_t getResourceCacheLimit() const
Return the current GPU resource cache limit in bytes.
bool oomed()
Checks if the underlying 3D API reported an out-of-memory error.
bool precompileShader(const SkData &key, const SkData &data)
void flushAndSubmit(const sk_sp< const SkImage > &image)
Version of flush() that uses a default GrFlushInfo.
void resetContext(uint32_t state=kAll_GrBackendState)
The context normally assumes that no outsider is setting state within the underlying 3D API's context...
void releaseResourcesAndAbandonContext()
This is similar to abandonContext() however the underlying 3D context is not yet lost and the context...
GrDirectContext(GrBackendApi backend, const GrContextOptions &options)
bool abandoned() override
Returns true if the context was abandoned or if the backend specific context has gotten into an unrec...
skgpu::ganesh::SmallPathAtlasMgr * onGetSmallPathAtlasMgr()
void flush(SkSurface *surface)
Flushes the given surface with the default GrFlushInfo.
GrSemaphoresSubmitted flush(SkSurface *surface, const GrFlushInfo &info, const skgpu::MutableTextureState *newState=nullptr)
Same as above except:
bool setBackendTextureState(const GrBackendTexture &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState=nullptr, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
Updates the state of the GrBackendTexture/RenderTarget to have the passed in skgpu::MutableTextureSta...
GrSemaphoresSubmitted flush(const sk_sp< const SkImage > &image, const GrFlushInfo &info)
Flushes any pending uses of texture-backed images in the GPU backend.
bool updateBackendTexture(const GrBackendTexture &, SkColorType skColorType, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
If possible, updates a backend texture to be filled to a particular color.
GrBackendTexture createBackendTexture(const SkPixmap &srcData, GrSurfaceOrigin textureOrigin, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
Convenience version createBackendTexture() that takes just a base level pixmap.
GrSemaphoresSubmitted flush(SkSurface *surface, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo &info)
Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA.
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, const SkColor4f &color, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
If possible, create a backend texture initialized to a particular color.
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
Call to ensure all drawing to the context has been flushed and submitted to the underlying 3D API.
Definition: GrDirectContext.h:368
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
~GrDirectContext() override
void flushAndSubmit(SkSurface *surface, GrSyncCpu sync=GrSyncCpu::kNo)
Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
Call to ensure all drawing to the context has been flushed to underlying 3D API specific objects.
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()
bool updateBackendTexture(const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
If possible, updates a backend texture to be filled to a particular color.
bool updateBackendTexture(const GrBackendTexture &texture, const SkPixmap &srcData, GrSurfaceOrigin textureOrigin=kTopLeft_GrSurfaceOrigin, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
Convenience version of updateBackendTexture that takes just a base level pixmap.
Definition: GrDirectContext.h:746
GrBackendTexture createCompressedBackendTexture(int width, int height, SkTextureCompressionType, const SkColor4f &color, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
bool setBackendRenderTargetState(const GrBackendRenderTarget &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState=nullptr, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
void deleteBackendTexture(const GrBackendTexture &)
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
The explicitly allocated backend texture API allows clients to use Skia to create backend objects out...
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *)
void storeVkPipelineCacheData()
GrBackendTexture createBackendTexture(const SkPixmap srcData[], int numLevels, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
GrBackendTexture createCompressedBackendTexture(int width, int height, SkTextureCompressionType, const void *data, size_t dataSize, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
bool wait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait=true)
Inserts a list of GPU semaphores that the current GPU-backed API must wait on before executing any mo...
void flush(const sk_sp< const SkImage > &image)
GrBackendTexture createBackendTexture(const SkPixmap &srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
void getResourceCacheUsage(int *resourceCount, size_t *resourceBytes) const
Gets the current GPU resource cache usage.
void flush()
Definition: GrDirectContext.h:399
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
Enumerates all cached GPU resources and dumps their memory to traceMemoryDump.
void resetGLTextureBindings()
If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which the cont...
void getResourceCacheLimits(int *maxResources, size_t *maxResourceBytes) const
DEPRECATED Return the current GPU resource cache limits.
bool init() override
DirectContextID directContextID() const
Definition: GrDirectContext.h:939
const GrDirectContextPriv priv() const
bool updateBackendTexture(const GrBackendTexture &texture, const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
GrDirectContextPriv priv()
void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources)
Purge unlocked resources from the cache until the the provided byte count has been reached or we have...
GrBackendTexture createBackendTexture(const SkPixmap srcData[], int numLevels, GrSurfaceOrigin, GrRenderable, GrProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
If possible, create a backend texture initialized with the provided pixmap data.
bool supportsDistanceFieldText() const
void purgeUnlockedResources(GrPurgeResourceOptions opts)
This entry point is intended for instances where an app has been backgrounded or suspended.
GrBackendTexture createBackendTexture(int width, int height, SkColorType, const SkColor4f &color, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
If possible, create a backend texture initialized to a particular color.
GrBackendTexture createCompressedBackendTexture(int width, int height, const GrBackendFormat &, const void *data, size_t dataSize, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
If possible, create a backend texture initialized with the provided raw data.
void performDeferredCleanup(std::chrono::milliseconds msNotUsed, GrPurgeResourceOptions opts=GrPurgeResourceOptions::kAllResources)
Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are otherwise mark...
void abandonContext() override
Abandons all GPU resources and assumes the underlying backend 3D API context is no longer usable.
GrBackendTexture createBackendTexture(int width, int height, SkColorType, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
If possible, create an uninitialized backend texture.
bool updateCompressedBackendTexture(const GrBackendTexture &, const void *data, size_t dataSize, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
If possible, updates a backend texture filled with the provided raw data.
void setResourceCacheLimit(size_t maxResourceBytes)
Specify the GPU resource cache limit.
bool updateBackendTexture(const GrBackendTexture &, const SkPixmap srcData[], int numLevels, GrSurfaceOrigin=kTopLeft_GrSurfaceOrigin, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
If possible, updates a backend texture filled with the provided pixmap data.
bool isDeviceLost()
Returns true if the backend specific context has gotten into an unrecoverarble, lost state (e....
Definition: GrRecordingContext.h:42
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const
Definition: GrRecordingContext.h:58
SK_API bool supportsProtectedContent() const
Does this context support protected content?
SK_API int maxRenderTargetSize() const
Gets the maximum supported render target size.
SK_API int maxSurfaceSampleCountForColorType(SkColorType colorType) const
Gets the maximum supported sample count for a color type.
Definition: GrRecordingContext.h:96
SK_API int maxTextureSize() const
Gets the maximum supported texture size.
SK_API bool colorTypeSupportedAsImage(SkColorType) const
Can a SkImage be created with the given color type.
SkData holds an immutable data buffer.
Definition: SkData.h:25
SkImage describes a two dimensional array of pixels to draw.
Definition: SkImage.h:270
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Definition: SkPixmap.h:40
Light weight class for managing strings.
Definition: SkString.h:118
SkSurface is responsible for managing the pixels that a canvas draws into.
Definition: SkSurface.h:161
Interface for memory tracing.
Definition: SkTraceMemoryDump.h:20
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Since Skia and clients can both modify gpu textures and their connected state, Skia needs a way for c...
Definition: MutableTextureState.h:37
Definition: SkSurface.h:42
BackendSurfaceAccess
Definition: SkSurface.h:44
This file includes numerous public types that are used by all of our gpu backends.
Definition: SkCanvas.h:73
Renderable
Is a texture renderable or not.
Definition: GpuTypes.h:69
Mipmapped
Is the texture mipmapped or not.
Definition: GpuTypes.h:53
Protected
Is the data protected on the GPU or not.
Definition: GpuTypes.h:61
Definition: SkCanvas.h:42
Definition: GrDirectContext.h:56
Definition: GrContextOptions.h:376
Definition: GrContextOptions.h:375
Struct to supply options to flush calls.
Definition: GrTypes.h:225
RGBA color value, holding four floating point components.