2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrContext_DEFINED
|
|
|
|
#define GrContext_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPathEffect.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
|
|
|
#include "include/private/GrRecordingContext.h"
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2018-05-11 17:08:30 +00:00
|
|
|
// We shouldn't need this but currently Android is relying on this being include transitively.
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkUnPreMultiply.h"
|
2018-05-11 17:08:30 +00:00
|
|
|
|
2018-03-01 16:36:45 +00:00
|
|
|
class GrAtlasManager;
|
Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""
This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.
Reason for revert: Chrome change landed that should fix chrome roll
Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
>
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
>
> Reason for revert: the bots seem to be unhappily red with this CL
>
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> >
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> >
> > Reason for revert: Creating a test CL to see what happens on the bots
> >
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > >
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > >
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > >
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > >
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > >
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
>
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com
Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-08-02 15:10:09 +00:00
|
|
|
class GrBackendSemaphore;
|
2018-05-11 14:14:21 +00:00
|
|
|
class GrCaps;
|
2019-10-03 17:26:54 +00:00
|
|
|
class GrClientMappedBufferManager;
|
2016-08-03 21:26:53 +00:00
|
|
|
class GrContextPriv;
|
2016-03-11 14:46:33 +00:00
|
|
|
class GrContextThreadSafeProxy;
|
2020-02-18 19:34:38 +00:00
|
|
|
struct GrD3DBackendContext;
|
2014-09-23 16:50:21 +00:00
|
|
|
class GrFragmentProcessor;
|
2017-07-25 14:05:01 +00:00
|
|
|
struct GrGLInterface;
|
2011-05-02 21:14:59 +00:00
|
|
|
class GrGpu;
|
2017-07-25 14:05:01 +00:00
|
|
|
struct GrMockOptions;
|
2013-11-01 15:23:44 +00:00
|
|
|
class GrPath;
|
2017-07-25 14:05:01 +00:00
|
|
|
class GrRenderTargetContext;
|
2015-02-11 18:49:59 +00:00
|
|
|
class GrResourceCache;
|
2015-04-30 21:18:54 +00:00
|
|
|
class GrResourceProvider;
|
2020-04-09 12:58:52 +00:00
|
|
|
class GrStrikeCache;
|
2017-03-30 12:02:11 +00:00
|
|
|
class GrSurfaceProxy;
|
2018-02-13 22:03:00 +00:00
|
|
|
class GrSwizzle;
|
2017-03-09 03:21:00 +00:00
|
|
|
class GrTextureProxy;
|
2017-07-25 14:05:01 +00:00
|
|
|
struct GrVkBackendContext;
|
2011-07-26 20:45:30 +00:00
|
|
|
|
2017-03-09 03:21:00 +00:00
|
|
|
class SkImage;
|
2020-03-30 21:16:34 +00:00
|
|
|
class SkString;
|
2019-07-02 21:58:27 +00:00
|
|
|
class SkSurfaceCharacterization;
|
2017-03-09 03:21:00 +00:00
|
|
|
class SkSurfaceProps;
|
2017-08-23 14:12:00 +00:00
|
|
|
class SkTaskGroup;
|
2018-02-13 22:03:00 +00:00
|
|
|
class SkTraceMemoryDump;
|
2017-03-09 03:21:00 +00:00
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
class SK_API GrContext : public GrRecordingContext {
|
2011-02-22 20:59:41 +00:00
|
|
|
public:
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2018-04-06 13:18:00 +00:00
|
|
|
* Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of
|
|
|
|
* GrGLMakeNativeInterface() is used if it succeeds.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2017-12-07 17:33:05 +00:00
|
|
|
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
|
|
|
|
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
|
2018-04-06 13:18:00 +00:00
|
|
|
static sk_sp<GrContext> MakeGL(const GrContextOptions&);
|
|
|
|
static sk_sp<GrContext> MakeGL();
|
2020-03-19 19:54:28 +00:00
|
|
|
#endif
|
2018-04-06 13:18:00 +00:00
|
|
|
|
2019-12-04 20:17:54 +00:00
|
|
|
/**
|
2020-02-18 19:34:38 +00:00
|
|
|
* The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned
|
2020-06-18 19:59:17 +00:00
|
|
|
* GrContext is destroyed. This also means that any objects created with this GrContext (e.g.
|
|
|
|
* SkSurfaces, SkImages, etc.) must also be released as they may hold refs on the GrContext.
|
|
|
|
* Once all these objects and the GrContext are released, then it is safe to delete the vulkan
|
|
|
|
* objects.
|
2019-12-04 20:17:54 +00:00
|
|
|
*/
|
2018-06-14 13:31:11 +00:00
|
|
|
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
|
|
|
|
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
|
2017-07-25 14:05:01 +00:00
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
#ifdef SK_METAL
|
|
|
|
/**
|
|
|
|
* Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
|
2019-05-28 03:03:45 +00:00
|
|
|
* and queue is an MTLCommandQueue which should be used by the backend. These objects must
|
|
|
|
* have a ref on them which can be transferred to Ganesh which will release the ref when the
|
|
|
|
* GrContext is destroyed.
|
2017-07-13 19:07:54 +00:00
|
|
|
*/
|
|
|
|
static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
|
2017-07-25 14:05:01 +00:00
|
|
|
static sk_sp<GrContext> MakeMetal(void* device, void* queue);
|
2017-07-13 19:07:54 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-18 19:34:38 +00:00
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
/**
|
|
|
|
* Makes a GrContext which uses Direct3D as the backend. The Direct3D context
|
|
|
|
* must be kept alive until the returned GrContext is first destroyed or abandoned.
|
|
|
|
*/
|
|
|
|
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&,
|
|
|
|
const GrContextOptions& options);
|
|
|
|
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&);
|
|
|
|
#endif
|
|
|
|
|
2019-07-18 15:43:45 +00:00
|
|
|
#ifdef SK_DAWN
|
2019-10-30 13:56:23 +00:00
|
|
|
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device, const GrContextOptions& options);
|
|
|
|
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device);
|
2019-07-18 15:43:45 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
|
|
|
|
static sk_sp<GrContext> MakeMock(const GrMockOptions*);
|
|
|
|
|
2019-02-04 22:50:57 +00:00
|
|
|
~GrContext() override;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
// TODO: Remove this from public after migrating Chrome.
|
2016-10-27 16:30:08 +00:00
|
|
|
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
|
2016-03-11 14:46:33 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* The GrContext normally assumes that no outsider is setting state
|
|
|
|
* within the underlying 3D API's context/device/whatever. This call informs
|
|
|
|
* the context that the state was modified and it should resend. Shouldn't
|
|
|
|
* be called frequently for good performance.
|
2013-06-28 18:57:35 +00:00
|
|
|
* The flag bits, state, is dpendent on which backend is used by the
|
|
|
|
* context, either GL or D3D (possible in future).
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2013-06-28 18:57:35 +00:00
|
|
|
void resetContext(uint32_t state = kAll_GrBackendState);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2019-02-08 17:33:08 +00:00
|
|
|
/**
|
|
|
|
* If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which
|
|
|
|
* the GrContext has modified the bound texture will have texture id 0 bound. This does not
|
|
|
|
* flush the GrContext. Calling resetContext() does not change the set that will be bound
|
|
|
|
* to texture id 0 on the next call to resetGLTextureBindings(). After this is called
|
|
|
|
* all unit/target combinations are considered to have unmodified bindings until the GrContext
|
|
|
|
* subsequently modifies them (meaning if this is called twice in a row with no intervening
|
|
|
|
* GrContext usage then the second call is a no-op.)
|
|
|
|
*/
|
|
|
|
void resetGLTextureBindings();
|
|
|
|
|
2011-03-30 21:26:44 +00:00
|
|
|
/**
|
2018-01-19 17:56:09 +00:00
|
|
|
* Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
|
2016-04-01 18:54:31 +00:00
|
|
|
* usable. Call this if you have lost the associated GPU context, and thus internal texture,
|
|
|
|
* buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the
|
|
|
|
* GrContext and any of its created resource objects will not make backend 3D API calls. Content
|
|
|
|
* rendered but not previously flushed may be lost. After this function is called all subsequent
|
|
|
|
* calls on the GrContext will fail or be no-ops.
|
|
|
|
*
|
|
|
|
* The typical use case for this function is that the underlying 3D context was lost and further
|
|
|
|
* API calls may crash.
|
2019-12-04 20:17:54 +00:00
|
|
|
*
|
|
|
|
* For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to
|
2020-06-18 19:59:17 +00:00
|
|
|
* create the GrContext must be kept alive even after abandoning the context. Those objects must
|
|
|
|
* live for the lifetime of the GrContext object itself. The reason for this is so that
|
|
|
|
* we can continue to delete any outstanding GrBackendTextures/RenderTargets which must be
|
|
|
|
* cleaned up even in a device lost state.
|
2011-03-30 21:26:44 +00:00
|
|
|
*/
|
2019-02-11 19:12:03 +00:00
|
|
|
void abandonContext() override;
|
2011-06-08 22:55:10 +00:00
|
|
|
|
2018-06-26 21:38:34 +00:00
|
|
|
/**
|
2020-04-01 17:29:59 +00:00
|
|
|
* Returns true if the context was abandoned or if the if the backend specific context has
|
|
|
|
* gotten into an unrecoverarble, lost state (e.g. in Vulkan backend if we've gotten a
|
|
|
|
* VK_ERROR_DEVICE_LOST). If the backend context is lost, this call will also abandon the
|
|
|
|
* GrContext.
|
2018-06-26 21:38:34 +00:00
|
|
|
*/
|
2020-04-01 17:29:59 +00:00
|
|
|
bool abandoned() override;
|
2018-06-26 21:38:34 +00:00
|
|
|
|
2020-06-24 14:19:52 +00:00
|
|
|
/**
|
|
|
|
* Checks if the underlying 3D API reported an out-of-memory error. If this returns true it is
|
|
|
|
* reset and will return false until another out-of-memory error is reported by the 3D API. If
|
|
|
|
* the context is abandoned then this will report false.
|
|
|
|
*
|
|
|
|
* Currently this is implemented for:
|
|
|
|
*
|
|
|
|
* OpenGL [ES] - Note that client calls to glGetError() may swallow GL_OUT_OF_MEMORY errors and
|
|
|
|
* therefore hide the error from Skia. Also, it is not advised to use this in combination with
|
|
|
|
* enabling GrContextOptions::fSkipGLErrorChecks. That option may prevent GrContext from ever
|
|
|
|
* checking the GL context for OOM.
|
|
|
|
*
|
|
|
|
* Vulkan - Reports true if VK_ERROR_OUT_OF_HOST_MEMORY or VK_ERROR_OUT_OF_DEVICE_MEMORY has
|
|
|
|
* occurred.
|
|
|
|
*/
|
|
|
|
bool oomed();
|
|
|
|
|
2016-04-01 18:54:31 +00:00
|
|
|
/**
|
|
|
|
* This is similar to abandonContext() however the underlying 3D context is not yet lost and
|
|
|
|
* the GrContext will cleanup all allocated resources before returning. After returning it will
|
|
|
|
* assume that the underlying context may no longer be valid.
|
|
|
|
*
|
|
|
|
* The typical use case for this function is that the client is going to destroy the 3D context
|
|
|
|
* but can't guarantee that GrContext will be destroyed first (perhaps because it may be ref'ed
|
|
|
|
* elsewhere by either the client or Skia objects).
|
2019-12-04 20:17:54 +00:00
|
|
|
*
|
|
|
|
* For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to
|
|
|
|
* create the GrContext must be alive before calling releaseResourcesAndAbandonContext.
|
2016-04-01 18:54:31 +00:00
|
|
|
*/
|
2018-03-01 19:16:41 +00:00
|
|
|
virtual void releaseResourcesAndAbandonContext();
|
2016-04-01 18:54:31 +00:00
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Resource Cache
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
/** DEPRECATED
|
2014-05-09 14:29:32 +00:00
|
|
|
* Return the current GPU resource cache limits.
|
|
|
|
*
|
2019-09-03 14:29:20 +00:00
|
|
|
* @param maxResources If non-null, will be set to -1.
|
2014-05-09 14:29:32 +00:00
|
|
|
* @param maxResourceBytes If non-null, returns maximum number of bytes of
|
|
|
|
* video memory that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
/**
|
|
|
|
* Return the current GPU resource cache limit in bytes.
|
|
|
|
*/
|
|
|
|
size_t getResourceCacheLimit() const;
|
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
/**
|
|
|
|
* Gets the current GPU resource cache usage.
|
|
|
|
*
|
|
|
|
* @param resourceCount If non-null, returns the number of resources that are held in the
|
|
|
|
* cache.
|
|
|
|
* @param maxResourceBytes If non-null, returns the total number of bytes of video memory held
|
|
|
|
* in the cache.
|
|
|
|
*/
|
|
|
|
void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
|
|
|
|
|
2017-05-24 15:41:33 +00:00
|
|
|
/**
|
|
|
|
* Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources.
|
|
|
|
*/
|
|
|
|
size_t getResourceCachePurgeableBytes() const;
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
/** DEPRECATED
|
|
|
|
* Specify the GPU resource cache limits. If the current cache exceeds the maxResourceBytes
|
|
|
|
* limit, it will be purged (LRU) to keep the cache within the limit.
|
2014-05-09 14:29:32 +00:00
|
|
|
*
|
2019-09-03 14:29:20 +00:00
|
|
|
* @param maxResources Unused.
|
2014-05-09 14:29:32 +00:00
|
|
|
* @param maxResourceBytes The maximum number of bytes of video memory
|
|
|
|
* that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
/**
|
|
|
|
* Specify the GPU resource cache limit. If the cache currently exceeds this limit,
|
|
|
|
* it will be purged (LRU) to keep the cache within the limit.
|
|
|
|
*
|
|
|
|
* @param maxResourceBytes The maximum number of bytes of video memory
|
|
|
|
* that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void setResourceCacheLimit(size_t maxResourceBytes);
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2012-10-15 14:25:31 +00:00
|
|
|
* Frees GPU created by the context. Can be called to reduce GPU memory
|
2011-03-30 21:26:44 +00:00
|
|
|
* pressure.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2018-03-01 19:16:41 +00:00
|
|
|
virtual void freeGpuResources();
|
2011-03-30 21:26:44 +00:00
|
|
|
|
2017-03-22 18:53:13 +00:00
|
|
|
/**
|
2017-12-13 14:26:37 +00:00
|
|
|
* Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are
|
|
|
|
* otherwise marked for deletion, regardless of whether the context is under budget.
|
2017-03-22 18:53:13 +00:00
|
|
|
*/
|
2017-12-13 14:26:37 +00:00
|
|
|
void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
|
2017-03-22 18:53:13 +00:00
|
|
|
|
2017-12-14 12:46:55 +00:00
|
|
|
// Temporary compatibility API for Android.
|
|
|
|
void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
|
|
|
|
this->performDeferredCleanup(msNotUsed);
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:43:59 +00:00
|
|
|
/**
|
|
|
|
* Purge unlocked resources from the cache until the the provided byte count has been reached
|
|
|
|
* or we have purged all unlocked resources. The default policy is to purge in LRU order, but
|
|
|
|
* can be overridden to prefer purging scratch resources (in LRU order) prior to purging other
|
|
|
|
* resource types.
|
|
|
|
*
|
|
|
|
* @param maxBytesToPurge the desired number of bytes to be purged.
|
|
|
|
* @param preferScratchResources If true scratch resources will be purged prior to other
|
|
|
|
* resource types.
|
|
|
|
*/
|
|
|
|
void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
|
|
|
|
|
2018-03-28 16:25:42 +00:00
|
|
|
/**
|
|
|
|
* This entry point is intended for instances where an app has been backgrounded or
|
|
|
|
* suspended.
|
|
|
|
* If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the
|
|
|
|
* unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false
|
|
|
|
* then all unlocked resources will be purged.
|
|
|
|
* In either case, after the unlocked resources are purged a separate pass will be made to
|
|
|
|
* ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true
|
|
|
|
* some resources with persistent data may be purged to be under budget).
|
|
|
|
*
|
|
|
|
* @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior
|
|
|
|
* enforcing the budget requirements.
|
|
|
|
*/
|
|
|
|
void purgeUnlockedResources(bool scratchResourcesOnly);
|
|
|
|
|
2018-04-05 16:46:09 +00:00
|
|
|
/**
|
|
|
|
* Gets the maximum supported texture size.
|
|
|
|
*/
|
|
|
|
int maxTextureSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum supported render target size.
|
|
|
|
*/
|
|
|
|
int maxRenderTargetSize() const;
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
/**
|
|
|
|
* Can a SkImage be created with the given color type.
|
|
|
|
*/
|
|
|
|
bool colorTypeSupportedAsImage(SkColorType) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
|
|
|
|
* use maxSurfaceSampleCountForColorType().
|
|
|
|
*/
|
|
|
|
bool colorTypeSupportedAsSurface(SkColorType colorType) const {
|
2020-01-29 13:37:01 +00:00
|
|
|
if (kR16G16_unorm_SkColorType == colorType ||
|
2019-09-19 20:05:48 +00:00
|
|
|
kA16_unorm_SkColorType == colorType ||
|
|
|
|
kA16_float_SkColorType == colorType ||
|
|
|
|
kR16G16_float_SkColorType == colorType ||
|
|
|
|
kR16G16B16A16_unorm_SkColorType == colorType ||
|
2019-09-11 21:03:28 +00:00
|
|
|
kGray_8_SkColorType == colorType) {
|
2019-09-04 19:05:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
return this->maxSurfaceSampleCountForColorType(colorType) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
|
|
|
|
* rendering is supported for the color type. 0 is returned if rendering to this color type
|
|
|
|
* is not supported at all.
|
|
|
|
*/
|
|
|
|
int maxSurfaceSampleCountForColorType(SkColorType) const;
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Misc.
|
|
|
|
|
2019-04-22 19:53:23 +00:00
|
|
|
/**
|
|
|
|
* Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
|
|
|
|
* executing any more commands on the GPU. Skia will take ownership of the underlying semaphores
|
|
|
|
* and delete them once they have been signaled and waited on. If this call returns false, then
|
|
|
|
* the GPU back-end will not wait on any passed in semaphores, and the client will still own the
|
|
|
|
* semaphores.
|
|
|
|
*/
|
|
|
|
bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2020-05-20 17:16:00 +00:00
|
|
|
* Call to ensure all drawing to the context has been flushed and submitted to the underlying 3D
|
|
|
|
* API. This is equivalent to calling GrContext::flush with a default GrFlushInfo followed by
|
|
|
|
* GrContext::submit.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2020-05-20 17:16:00 +00:00
|
|
|
void flushAndSubmit() {
|
2020-06-10 14:04:48 +00:00
|
|
|
this->flush(GrFlushInfo());
|
2020-05-20 17:16:00 +00:00
|
|
|
this->submit();
|
|
|
|
}
|
2020-05-13 18:07:40 +00:00
|
|
|
|
Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""
This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.
Reason for revert: Chrome change landed that should fix chrome roll
Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
>
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
>
> Reason for revert: the bots seem to be unhappily red with this CL
>
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> >
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> >
> > Reason for revert: Creating a test CL to see what happens on the bots
> >
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > >
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > >
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > >
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > >
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > >
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
>
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com
Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-08-02 15:10:09 +00:00
|
|
|
/**
|
2020-05-20 17:16:00 +00:00
|
|
|
* Call to ensure all drawing to the context has been flushed to underlying 3D API specific
|
|
|
|
* objects. A call to GrContext::submit is always required to ensure work is actually sent to
|
|
|
|
* the gpu. Some specific API details:
|
|
|
|
* GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
|
|
|
|
* sync objects from the flush will not be valid until a submission occurs.
|
|
|
|
*
|
|
|
|
* Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
|
|
|
|
* buffer or encoder objects. However, these objects are not sent to the gpu until a
|
|
|
|
* submission occurs.
|
Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""
This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.
Reason for revert: Chrome change landed that should fix chrome roll
Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
>
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
>
> Reason for revert: the bots seem to be unhappily red with this CL
>
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> >
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> >
> > Reason for revert: Creating a test CL to see what happens on the bots
> >
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > >
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > >
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > >
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > >
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > >
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
>
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com
Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-08-02 15:10:09 +00:00
|
|
|
*
|
2020-05-20 17:16:00 +00:00
|
|
|
* If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
|
|
|
|
* submitted to the gpu during the next submit call (it is possible Skia failed to create a
|
|
|
|
* subset of the semaphores). The client should not wait on these semaphores until after submit
|
2020-05-28 16:25:09 +00:00
|
|
|
* has been called, and must keep them alive until then. If this call returns
|
2020-05-20 17:16:00 +00:00
|
|
|
* GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
|
|
|
|
* the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with
|
|
|
|
* the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
|
|
|
|
* client is still responsible for deleting any initialized semaphores.
|
2020-04-08 16:52:51 +00:00
|
|
|
* Regardleess of semaphore submission the context will still be flushed. It should be
|
|
|
|
* emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
|
|
|
|
* happen. It simply means there were no semaphores submitted to the GPU. A caller should only
|
|
|
|
* take this as a failure if they passed in semaphores to be submitted.
|
Revert "Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush""""
This reverts commit cc8eb60c486eaf397685c60b28998682025fee1a.
Reason for revert: Chrome change landed that should fix chrome roll
Original change's description:
> Revert "Revert "Revert "Add support for semaphores to be inserted on GrContext flush"""
>
> This reverts commit 876aed8758b7109574999ffac43b1ea47f359bd7.
>
> Reason for revert: the bots seem to be unhappily red with this CL
>
> Original change's description:
> > Revert "Revert "Add support for semaphores to be inserted on GrContext flush""
> >
> > This reverts commit 8724b4609996eb6369b454611e31b065f3d8d2cf.
> >
> > Reason for revert: Creating a test CL to see what happens on the bots
> >
> > Original change's description:
> > > Revert "Add support for semaphores to be inserted on GrContext flush"
> > >
> > > This reverts commit cd1416efbc7af6f115dbaa09dce48e075d1d96ca.
> > >
> > > Reason for revert: speculative, to try to fix roll see gpu_tests.pixel_integration_test.PixelIntegrationTest.Pixel_GpuRasterization_ConcavePaths
> > >
> > > Original change's description:
> > > > Add support for semaphores to be inserted on GrContext flush
> > > >
> > > > This also moves the logic of inserting semaphores down into GrDrawingManager
> > > > and finishFlush on GrGpu. With it being on finishFlush, there should be no
> > > > issues when the DrawingManager starts respecting the proxy passed in assuming
> > > > it always calls finishFlush at the end (which it should).
> > > >
> > > > Bug: skia:
> > > > Change-Id: I925c2a289dcbbb9159b9120878af1d34f21a2dc7
> > > > Reviewed-on: https://skia-review.googlesource.com/25641
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: I9c5b9cf8c060193e1861dbb8f0c10fb11dfb5249
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/25980
> > > Reviewed-by: Mike Reed <reed@google.com>
> > > Commit-Queue: Mike Reed <reed@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: skia:
> > Change-Id: I5edbeaa0769670ee58f362f0ccaa78319410aa6c
> > Reviewed-on: https://skia-review.googlesource.com/26160
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reed@google.com
>
> Change-Id: I22fd6febafe70489a5fdb695c6f4263368eb423d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/29422
> Reviewed-by: Yuqian Li <liyuqian@google.com>
> Commit-Queue: Yuqian Li <liyuqian@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,liyuqian@google.com,reed@google.com
Change-Id: Ie3eae818b02599a70f714ef6b6635ce7d171bde6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/30000
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-08-02 15:10:09 +00:00
|
|
|
*/
|
2020-06-10 14:04:48 +00:00
|
|
|
GrSemaphoresSubmitted flush(const GrFlushInfo& info);
|
2019-04-10 20:28:52 +00:00
|
|
|
|
2020-06-26 01:00:17 +00:00
|
|
|
void flush() { this->flush({}); }
|
|
|
|
|
2020-05-13 18:07:40 +00:00
|
|
|
/**
|
2020-05-20 17:16:00 +00:00
|
|
|
* Submit outstanding work to the gpu from all previously un-submitted flushes. The return
|
|
|
|
* value of the submit will indicate whether or not the submission to the GPU was successful.
|
|
|
|
*
|
|
|
|
* If the call returns true, all previously passed in semaphores in flush calls will have been
|
|
|
|
* submitted to the GPU and they can safely be waited on. The caller should wait on those
|
|
|
|
* semaphores or perform some other global synchronization before deleting the semaphores.
|
|
|
|
*
|
|
|
|
* If it returns false, then those same semaphores will not have been submitted and we will not
|
|
|
|
* try to submit them again. The caller is free to delete the semaphores at any time.
|
|
|
|
*
|
|
|
|
* If the syncCpu flag is true this function will return once the gpu has finished with all
|
|
|
|
* submitted work.
|
2020-05-13 18:07:40 +00:00
|
|
|
*/
|
2020-05-20 17:16:00 +00:00
|
|
|
bool submit(bool syncCpu = false);
|
2020-05-13 18:07:40 +00:00
|
|
|
|
2019-05-06 20:58:22 +00:00
|
|
|
/**
|
|
|
|
* Checks whether any asynchronous work is complete and if so calls related callbacks.
|
|
|
|
*/
|
|
|
|
void checkAsyncWorkCompletion();
|
|
|
|
|
2016-08-03 21:26:53 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
2019-02-04 18:26:26 +00:00
|
|
|
GrContextPriv priv();
|
|
|
|
const GrContextPriv priv() const;
|
2016-08-03 21:26:53 +00:00
|
|
|
|
2018-03-06 13:20:37 +00:00
|
|
|
/** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
|
|
|
|
// Chrome is using this!
|
|
|
|
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
|
|
|
|
2018-05-23 22:45:01 +00:00
|
|
|
bool supportsDistanceFieldText() const;
|
|
|
|
|
2019-01-08 20:49:46 +00:00
|
|
|
void storeVkPipelineCacheData();
|
|
|
|
|
2019-10-09 16:38:22 +00:00
|
|
|
// Returns the gpu memory size of the the texture that backs the passed in SkImage. Returns 0 if
|
2019-11-26 14:55:20 +00:00
|
|
|
// the SkImage is not texture backed. For external format textures this will also return 0 as we
|
|
|
|
// cannot determine the correct size.
|
2019-10-09 16:38:22 +00:00
|
|
|
static size_t ComputeImageSize(sk_sp<SkImage> image, GrMipMapped, bool useNextPow2 = false);
|
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
2019-07-29 18:11:35 +00:00
|
|
|
* Retrieve the default GrBackendFormat for a given SkColorType and renderability.
|
|
|
|
* It is guaranteed that this backend format will be the one used by the following
|
|
|
|
* SkColorType and SkSurfaceCharacterization-based createBackendTexture methods.
|
|
|
|
*
|
|
|
|
* The caller should check that the returned format is valid.
|
|
|
|
*/
|
2019-08-13 20:16:42 +00:00
|
|
|
GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
|
|
|
|
return INHERITED::defaultBackendFormat(ct, renderable);
|
|
|
|
}
|
2019-07-29 18:11:35 +00:00
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
2019-05-20 12:38:07 +00:00
|
|
|
* The explicitly allocated backend texture API allows clients to use Skia to create backend
|
|
|
|
* objects outside of Skia proper (i.e., Skia's caching system will not know about them.)
|
|
|
|
*
|
|
|
|
* It is the client's responsibility to delete all these objects (using deleteBackendTexture)
|
2019-12-04 20:17:54 +00:00
|
|
|
* before deleting the GrContext used to create them. If the backend is Vulkan, the textures must
|
|
|
|
* be deleted before abandoning the GrContext as well. Additionally, clients should only delete
|
|
|
|
* these objects on the thread for which that GrContext is active.
|
2019-05-20 12:38:07 +00:00
|
|
|
*
|
2019-06-04 15:03:06 +00:00
|
|
|
* The client is responsible for ensuring synchronization between different uses
|
|
|
|
* of the backend object (i.e., wrapping it in a surface, rendering to it, deleting the
|
|
|
|
* surface, rewrapping it in a image and drawing the image will require explicit
|
|
|
|
* sychronization on the client's part).
|
2019-05-20 12:38:07 +00:00
|
|
|
*/
|
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create an uninitialized backend texture. The client should ensure that the
|
|
|
|
* returned backend texture is valid.
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_UNDEFINED.
|
|
|
|
*/
|
2019-05-20 12:38:07 +00:00
|
|
|
GrBackendTexture createBackendTexture(int width, int height,
|
2019-06-18 13:58:02 +00:00
|
|
|
const GrBackendFormat&,
|
2019-05-20 12:38:07 +00:00
|
|
|
GrMipMapped,
|
2019-06-24 14:53:09 +00:00
|
|
|
GrRenderable,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrProtected = GrProtected::kNo);
|
2019-05-20 12:38:07 +00:00
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create an uninitialized backend texture. The client should ensure that the
|
|
|
|
* returned backend texture is valid.
|
|
|
|
* If successful, the created backend texture will be compatible with the provided
|
|
|
|
* SkColorType.
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_UNDEFINED.
|
|
|
|
*/
|
2019-05-20 12:38:07 +00:00
|
|
|
GrBackendTexture createBackendTexture(int width, int height,
|
|
|
|
SkColorType,
|
|
|
|
GrMipMapped,
|
2019-06-24 14:53:09 +00:00
|
|
|
GrRenderable,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrProtected = GrProtected::kNo);
|
2019-05-20 12:38:07 +00:00
|
|
|
|
2019-07-02 21:58:27 +00:00
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create an uninitialized backend texture that is compatible with the
|
|
|
|
* provided characterization. The client should ensure that the returned backend texture
|
|
|
|
* is valid.
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_UNDEFINED.
|
|
|
|
*/
|
2019-07-02 21:58:27 +00:00
|
|
|
GrBackendTexture createBackendTexture(const SkSurfaceCharacterization& characterization);
|
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create a backend texture initialized to a particular color. The client should
|
|
|
|
* ensure that the returned backend texture is valid. The client can pass in a finishedProc
|
|
|
|
* to be notified when the data has been uploaded by the gpu and the texture can be deleted. The
|
2020-06-05 14:22:26 +00:00
|
|
|
* client is required to call GrContext::submit to send the upload work to the gpu. The
|
|
|
|
* finishedProc will always get called even if we failed to create the GrBackendTexture.
|
2020-05-06 15:40:03 +00:00
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
2020-05-06 15:52:37 +00:00
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
2020-05-06 15:40:03 +00:00
|
|
|
*/
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture createBackendTexture(int width, int height,
|
2019-07-02 21:58:27 +00:00
|
|
|
const GrBackendFormat&,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipMapped,
|
|
|
|
GrRenderable,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-06-04 15:03:06 +00:00
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create a backend texture initialized to a particular color. The client should
|
|
|
|
* ensure that the returned backend texture is valid. The client can pass in a finishedProc
|
|
|
|
* to be notified when the data has been uploaded by the gpu and the texture can be deleted. The
|
2020-06-05 14:22:26 +00:00
|
|
|
* client is required to call GrContext::submit to send the upload work to the gpu. The
|
|
|
|
* finishedProc will always get called even if we failed to create the GrBackendTexture.
|
2020-05-06 15:40:03 +00:00
|
|
|
* If successful, the created backend texture will be compatible with the provided
|
|
|
|
* SkColorType.
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
2020-05-06 15:52:37 +00:00
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
2020-05-06 15:40:03 +00:00
|
|
|
*/
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture createBackendTexture(int width, int height,
|
2019-07-02 21:58:27 +00:00
|
|
|
SkColorType,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipMapped,
|
|
|
|
GrRenderable,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-06-04 15:03:06 +00:00
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
* If possible, create a backend texture initialized to a particular color that is
|
|
|
|
* compatible with the provided characterization. The client should ensure that the
|
|
|
|
* returned backend texture is valid. The client can pass in a finishedProc to be notified when
|
2020-06-05 14:22:26 +00:00
|
|
|
* the data has been uploaded by the gpu and the texture can be deleted. The client is required
|
|
|
|
* to call GrContext::submit to send the upload work to the gpu. The finishedProc will always
|
|
|
|
* get called even if we failed to create the GrBackendTexture.
|
2020-05-06 15:40:03 +00:00
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
2020-05-06 15:52:37 +00:00
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if texturaeble
|
|
|
|
* VK_IMAGE_LAYOUT_UNDEFINED if not textureable
|
2020-05-06 15:40:03 +00:00
|
|
|
*/
|
2019-07-02 21:58:27 +00:00
|
|
|
GrBackendTexture createBackendTexture(const SkSurfaceCharacterization& characterization,
|
2020-05-06 15:40:03 +00:00
|
|
|
const SkColor4f& color,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If possible, create a backend texture initialized with the provided pixmap data. The client
|
|
|
|
* should ensure that the returned backend texture is valid. The client can pass in a
|
|
|
|
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
|
2020-06-05 14:22:26 +00:00
|
|
|
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
|
|
|
|
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
|
2020-05-06 15:40:03 +00:00
|
|
|
* If successful, the created backend texture will be compatible with the provided
|
|
|
|
* pixmap(s). Compatible, in this case, means that the backend format will be the result
|
2020-06-05 14:22:26 +00:00
|
|
|
* of calling defaultBackendFormat on the base pixmap's colortype. The src data can be deleted
|
|
|
|
* when this call returns.
|
2020-05-06 15:40:03 +00:00
|
|
|
* If numLevels is 1 a non-mipMapped texture will result. If a mipMapped texture is desired
|
|
|
|
* the data for all the mipmap levels must be provided. In the mipmapped case all the
|
|
|
|
* colortypes of the provided pixmaps must be the same. Additionally, all the miplevels
|
|
|
|
* must be sized correctly (please see SkMipMap::ComputeLevelSize and ComputeLevelCount).
|
|
|
|
* Note: the pixmap's alphatypes and colorspaces are ignored.
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
*/
|
2019-09-30 17:21:25 +00:00
|
|
|
GrBackendTexture createBackendTexture(const SkPixmap srcData[], int numLevels,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrRenderable, GrProtected,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-09-30 17:21:25 +00:00
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
// Helper version of above for a single level.
|
|
|
|
GrBackendTexture createBackendTexture(const SkPixmap& srcData,
|
|
|
|
GrRenderable renderable,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected isProtected,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr) {
|
|
|
|
return this->createBackendTexture(&srcData, 1, renderable, isProtected, finishedProc,
|
|
|
|
finishedContext);
|
2019-10-03 17:26:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 19:32:04 +00:00
|
|
|
/**
|
|
|
|
* If possible, updates a backend texture to be filled to a particular color. The client should
|
|
|
|
* check the return value to see if the update was successful. The client can pass in a
|
|
|
|
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
|
2020-06-05 14:22:26 +00:00
|
|
|
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
|
|
|
|
* The finishedProc will always get called even if we failed to update the GrBackendTexture.
|
2020-05-13 19:32:04 +00:00
|
|
|
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
*/
|
|
|
|
bool updateBackendTexture(const GrBackendTexture&,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrGpuFinishedProc finishedProc,
|
|
|
|
GrGpuFinishedContext finishedContext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If possible, updates a backend texture filled with the provided pixmap data. The client
|
|
|
|
* should check the return value to see if the update was successful. The client can pass in a
|
|
|
|
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
|
2020-06-05 14:22:26 +00:00
|
|
|
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
|
|
|
|
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
|
2020-05-13 19:32:04 +00:00
|
|
|
* The backend texture must be compatible with the provided pixmap(s). Compatible, in this case,
|
2020-06-05 14:22:26 +00:00
|
|
|
* means that the backend format is compatible with the base pixmap's colortype. The src data
|
|
|
|
* can be deleted when this call returns.
|
2020-05-13 19:32:04 +00:00
|
|
|
* If the backend texture is mip mapped, the data for all the mipmap levels must be provided.
|
|
|
|
* In the mipmapped case all the colortypes of the provided pixmaps must be the same.
|
|
|
|
* Additionally, all the miplevels must be sized correctly (please see
|
|
|
|
* SkMipMap::ComputeLevelSize and ComputeLevelCount).
|
|
|
|
* Note: the pixmap's alphatypes and colorspaces are ignored.
|
|
|
|
* For the Vulkan backend after a successful update the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
*/
|
|
|
|
bool updateBackendTexture(const GrBackendTexture&,
|
|
|
|
const SkPixmap srcData[],
|
|
|
|
int numLevels,
|
|
|
|
GrGpuFinishedProc finishedProc,
|
|
|
|
GrGpuFinishedContext finishedContext);
|
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
2019-12-17 19:44:37 +00:00
|
|
|
* Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is
|
|
|
|
* guaranteed to match the backend format used by the following
|
|
|
|
* createCompressedsBackendTexture methods that take a CompressionType.
|
|
|
|
* The caller should check that the returned format is valid.
|
|
|
|
*/
|
|
|
|
GrBackendFormat compressedBackendFormat(SkImage::CompressionType compression) const {
|
|
|
|
return INHERITED::compressedBackendFormat(compression);
|
|
|
|
}
|
|
|
|
|
2020-05-06 15:40:03 +00:00
|
|
|
/**
|
|
|
|
*If possible, create a compressed backend texture initialized to a particular color. The
|
|
|
|
* client should ensure that the returned backend texture is valid. The client can pass in a
|
|
|
|
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
|
2020-06-05 14:22:26 +00:00
|
|
|
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
|
|
|
|
* The finishedProc will always get called even if we failed to create the GrBackendTexture.
|
2020-05-06 15:40:03 +00:00
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
*/
|
2019-12-17 19:44:37 +00:00
|
|
|
GrBackendTexture createCompressedBackendTexture(int width, int height,
|
|
|
|
const GrBackendFormat&,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipMapped,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-12-17 19:44:37 +00:00
|
|
|
|
|
|
|
GrBackendTexture createCompressedBackendTexture(int width, int height,
|
|
|
|
SkImage::CompressionType,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipMapped,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If possible, create a backend texture initialized with the provided raw data. The client
|
|
|
|
* should ensure that the returned backend texture is valid. The client can pass in a
|
|
|
|
* finishedProc to be notified when the data has been uploaded by the gpu and the texture can be
|
2020-06-05 14:22:26 +00:00
|
|
|
* deleted. The client is required to call GrContext::submit to send the upload work to the gpu.
|
|
|
|
* The finishedProc will always get called even if we failed to create the GrBackendTexture
|
2020-05-06 15:40:03 +00:00
|
|
|
* If numLevels is 1 a non-mipMapped texture will result. If a mipMapped texture is desired
|
|
|
|
* the data for all the mipmap levels must be provided. Additionally, all the miplevels
|
|
|
|
* must be sized correctly (please see SkMipMap::ComputeLevelSize and ComputeLevelCount).
|
|
|
|
* For the Vulkan backend the layout of the created VkImage will be:
|
|
|
|
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
*/
|
2019-12-17 19:44:37 +00:00
|
|
|
GrBackendTexture createCompressedBackendTexture(int width, int height,
|
|
|
|
const GrBackendFormat&,
|
|
|
|
const void* data, size_t dataSize,
|
|
|
|
GrMipMapped,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-12-17 19:44:37 +00:00
|
|
|
|
|
|
|
GrBackendTexture createCompressedBackendTexture(int width, int height,
|
|
|
|
SkImage::CompressionType,
|
|
|
|
const void* data, size_t dataSize,
|
|
|
|
GrMipMapped,
|
2020-05-06 15:40:03 +00:00
|
|
|
GrProtected = GrProtected::kNo,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
2019-12-17 19:44:37 +00:00
|
|
|
|
2020-06-09 21:29:32 +00:00
|
|
|
/**
|
|
|
|
* Updates the state of the GrBackendTexture/RenderTarget to have the passed in
|
|
|
|
* GrBackendSurfaceMutableState. All objects that wrap the backend surface (i.e. SkSurfaces and
|
|
|
|
* SkImages) will also be aware of this state change. This call does not submit the state change
|
|
|
|
* to the gpu, but requires the client to call GrContext::submit to send it to the GPU. The work
|
|
|
|
* for this call is ordered linearly with all other calls that require GrContext::submit to be
|
|
|
|
* called (e.g updateBackendTexture and flush). If finishedProc is not null then it will be
|
|
|
|
* called with finishedContext after the state transition is known to have occurred on the GPU.
|
|
|
|
*
|
|
|
|
* See GrBackendSurfaceMutableState to see what state can be set via this call.
|
|
|
|
*/
|
|
|
|
bool setBackendTextureState(const GrBackendTexture&,
|
|
|
|
const GrBackendSurfaceMutableState&,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
|
|
|
bool setBackendRenderTargetState(const GrBackendRenderTarget&,
|
|
|
|
const GrBackendSurfaceMutableState&,
|
|
|
|
GrGpuFinishedProc finishedProc = nullptr,
|
|
|
|
GrGpuFinishedContext finishedContext = nullptr);
|
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
void deleteBackendTexture(GrBackendTexture);
|
|
|
|
|
2019-09-06 18:42:43 +00:00
|
|
|
// This interface allows clients to pre-compile shaders and populate the runtime program cache.
|
|
|
|
// The key and data blobs should be the ones passed to the PersistentCache, in SkSL format.
|
|
|
|
//
|
|
|
|
// Steps to use this API:
|
|
|
|
//
|
|
|
|
// 1) Create a GrContext as normal, but set fPersistentCache on GrContextOptions to something
|
|
|
|
// that will save the cached shader blobs. Set fShaderCacheStrategy to kSkSL. This will
|
|
|
|
// ensure that the blobs are SkSL, and are suitable for pre-compilation.
|
|
|
|
// 2) Run your application, and save all of the key/data pairs that are fed to the cache.
|
|
|
|
//
|
|
|
|
// 3) Switch over to shipping your application. Include the key/data pairs from above.
|
|
|
|
// 4) At startup (or any convenient time), call precompileShader for each key/data pair.
|
|
|
|
// This will compile the SkSL to create a GL program, and populate the runtime cache.
|
|
|
|
//
|
|
|
|
// This is only guaranteed to work if the context/device used in step #2 are created in the
|
|
|
|
// same way as the one used in step #4, and the same GrContextOptions are specified.
|
|
|
|
// Using cached shader blobs on a different device or driver are undefined.
|
|
|
|
bool precompileShader(const SkData& key, const SkData& data);
|
|
|
|
|
2019-08-09 13:41:48 +00:00
|
|
|
#ifdef SK_ENABLE_DUMP_GPU
|
|
|
|
/** Returns a string with detailed information about the context & GPU, in JSON format. */
|
|
|
|
SkString dump() const;
|
|
|
|
#endif
|
|
|
|
|
2018-01-19 17:56:09 +00:00
|
|
|
protected:
|
2020-06-02 15:23:16 +00:00
|
|
|
GrContext(sk_sp<GrContextThreadSafeProxy>);
|
2019-02-07 15:44:10 +00:00
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
bool init() override;
|
2018-03-01 19:16:41 +00:00
|
|
|
|
2019-02-14 19:49:02 +00:00
|
|
|
GrContext* asDirectContext() override { return this; }
|
|
|
|
|
2018-03-07 20:13:18 +00:00
|
|
|
virtual GrAtlasManager* onGetAtlasManager() = 0;
|
2018-03-01 19:16:41 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
private:
|
2018-12-12 21:22:40 +00:00
|
|
|
// fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed
|
|
|
|
// after all of its users. Clients of fTaskGroup will generally want to ensure that they call
|
|
|
|
// wait() on it as they are being destroyed, to avoid the possibility of pending tasks being
|
|
|
|
// invoked after objects they depend upon have already been destroyed.
|
|
|
|
std::unique_ptr<SkTaskGroup> fTaskGroup;
|
2020-04-09 12:58:52 +00:00
|
|
|
std::unique_ptr<GrStrikeCache> fStrikeCache;
|
2017-12-07 17:33:05 +00:00
|
|
|
sk_sp<GrGpu> fGpu;
|
2016-03-11 14:46:33 +00:00
|
|
|
GrResourceCache* fResourceCache;
|
2017-03-04 13:12:46 +00:00
|
|
|
GrResourceProvider* fResourceProvider;
|
2015-04-30 21:18:54 +00:00
|
|
|
|
2016-03-11 14:46:33 +00:00
|
|
|
bool fDidTestPMConversions;
|
2017-04-20 14:24:36 +00:00
|
|
|
// true if the PM/UPM conversion succeeded; false otherwise
|
|
|
|
bool fPMUPMConversionsRoundTrip;
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2017-11-01 19:45:43 +00:00
|
|
|
GrContextOptions::PersistentCache* fPersistentCache;
|
2019-05-03 17:13:35 +00:00
|
|
|
GrContextOptions::ShaderErrorHandler* fShaderErrorHandler;
|
2017-11-01 19:45:43 +00:00
|
|
|
|
2019-10-03 17:26:54 +00:00
|
|
|
std::unique_ptr<GrClientMappedBufferManager> fMappedBufferManager;
|
|
|
|
|
2016-10-27 18:47:55 +00:00
|
|
|
// TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
|
2016-08-03 21:26:53 +00:00
|
|
|
friend class GrContextPriv;
|
2016-08-06 05:32:12 +00:00
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
typedef GrRecordingContext INHERITED;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|