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
|
|
|
|
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "SkMatrix.h"
|
2014-06-12 17:24:21 +00:00
|
|
|
#include "SkPathEffect.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "SkTypes.h"
|
2016-01-08 15:19:47 +00:00
|
|
|
#include "../private/GrAuditTrail.h"
|
2016-01-06 16:26:09 +00:00
|
|
|
#include "../private/GrSingleOwner.h"
|
2018-07-31 13:44:36 +00:00
|
|
|
#include "../private/GrSkSLFPFactoryCache.h"
|
2017-11-01 19:45:43 +00:00
|
|
|
#include "GrContextOptions.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.
|
|
|
|
#include "SkUnPreMultiply.h"
|
|
|
|
|
2018-03-01 16:36:45 +00:00
|
|
|
class GrAtlasManager;
|
2018-02-13 22:03:00 +00:00
|
|
|
class GrBackendFormat;
|
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;
|
2016-08-03 21:26:53 +00:00
|
|
|
class GrContextPriv;
|
2016-03-11 14:46:33 +00:00
|
|
|
class GrContextThreadSafeProxy;
|
2018-05-10 16:57:17 +00:00
|
|
|
class GrContextThreadSafeProxyPriv;
|
2015-10-17 14:43:27 +00:00
|
|
|
class GrDrawingManager;
|
2018-09-10 20:28:05 +00:00
|
|
|
struct GrDrawOpAtlasConfig;
|
2014-09-23 16:50:21 +00:00
|
|
|
class GrFragmentProcessor;
|
2017-07-25 14:05:01 +00:00
|
|
|
struct GrGLInterface;
|
2018-03-01 16:36:45 +00:00
|
|
|
class GrGlyphCache;
|
2011-05-02 21:14:59 +00:00
|
|
|
class GrGpu;
|
2018-09-10 20:28:05 +00:00
|
|
|
class GrIndexBuffer;
|
2017-07-25 14:05:01 +00:00
|
|
|
struct GrMockOptions;
|
2018-06-19 17:09:54 +00:00
|
|
|
class GrOpMemoryPool;
|
2018-09-10 20:28:05 +00:00
|
|
|
class GrOvalRenderer;
|
2013-11-01 15:23:44 +00:00
|
|
|
class GrPath;
|
2018-01-08 18:40:32 +00:00
|
|
|
class GrProxyProvider;
|
2017-07-25 14:05:01 +00:00
|
|
|
class GrRenderTargetContext;
|
2018-09-10 20:28:05 +00:00
|
|
|
class GrResourceEntry;
|
2015-02-11 18:49:59 +00:00
|
|
|
class GrResourceCache;
|
2015-04-30 21:18:54 +00:00
|
|
|
class GrResourceProvider;
|
2017-09-07 16:36:34 +00:00
|
|
|
class GrSamplerState;
|
2017-03-30 12:02:11 +00:00
|
|
|
class GrSurfaceProxy;
|
2018-02-13 22:03:00 +00:00
|
|
|
class GrSwizzle;
|
2015-04-08 16:08:31 +00:00
|
|
|
class GrTextBlobCache;
|
2014-06-24 07:12:27 +00:00
|
|
|
class GrTextContext;
|
2017-03-09 03:21:00 +00:00
|
|
|
class GrTextureProxy;
|
2018-09-10 20:28:05 +00:00
|
|
|
class GrVertexBuffer;
|
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;
|
2018-02-13 22:03:00 +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
|
|
|
|
2013-09-09 13:38:37 +00:00
|
|
|
class SK_API GrContext : public SkRefCnt {
|
2011-02-22 20:59:41 +00:00
|
|
|
public:
|
|
|
|
/**
|
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();
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
#ifdef SK_VULKAN
|
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
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
|
|
|
|
static sk_sp<GrContext> MakeMock(const GrMockOptions*);
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
virtual ~GrContext();
|
|
|
|
|
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
|
|
|
|
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.
|
2011-03-30 21:26:44 +00:00
|
|
|
*/
|
2018-03-01 19:16:41 +00:00
|
|
|
virtual void abandonContext();
|
2011-06-08 22:55:10 +00:00
|
|
|
|
2018-06-26 21:38:34 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the context was abandoned.
|
|
|
|
*/
|
|
|
|
bool abandoned() const;
|
|
|
|
|
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).
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current GPU resource cache limits.
|
|
|
|
*
|
|
|
|
* @param maxResources If non-null, returns maximum number of resources that
|
|
|
|
* can be held in the cache.
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
/**
|
|
|
|
* Specify the GPU resource cache limits. If the current cache exceeds either
|
|
|
|
* of these, it will be purged (LRU) to keep the cache within these limits.
|
|
|
|
*
|
|
|
|
* @param maxResources The maximum number of resources that can be held in
|
|
|
|
* the cache.
|
|
|
|
* @param maxResourceBytes The maximum number of bytes of video memory
|
|
|
|
* that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void setResourceCacheLimits(int maxResources, 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 {
|
|
|
|
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.
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
* Call to ensure all drawing to the context has been issued to the underlying 3D API.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2016-09-07 17:02:04 +00:00
|
|
|
void flush();
|
2015-05-26 18:38:03 +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
|
|
|
/**
|
|
|
|
* Call to ensure all drawing to the context has been issued to the underlying 3D API. After
|
|
|
|
* issuing all commands, numSemaphore semaphores will be signaled by the gpu. The client passes
|
|
|
|
* in an array of numSemaphores GrBackendSemaphores. In general these GrBackendSemaphore's can
|
|
|
|
* be either initialized or not. If they are initialized, the backend uses the passed in
|
|
|
|
* semaphore. If it is not initialized, a new semaphore is created and the GrBackendSemaphore
|
|
|
|
* object is initialized with that semaphore.
|
|
|
|
*
|
|
|
|
* The client will own and be responsible for deleting the underlying semaphores that are stored
|
|
|
|
* and returned in initialized GrBackendSemaphore objects. The GrBackendSemaphore objects
|
|
|
|
* themselves can be deleted as soon as this function returns.
|
|
|
|
*
|
|
|
|
* If the backend API is OpenGL only uninitialized GrBackendSemaphores are supported.
|
|
|
|
* If the backend API is Vulkan either initialized or unitialized semaphores are supported.
|
|
|
|
* If unitialized, the semaphores which are created will be valid for use only with the VkDevice
|
|
|
|
* with which they were created.
|
|
|
|
*
|
|
|
|
* If this call returns GrSemaphoresSubmited::kNo, the GPU backend will not have created or
|
|
|
|
* added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on
|
|
|
|
* any of the semaphores. However, any pending commands to the context will still be flushed.
|
|
|
|
*/
|
|
|
|
GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores,
|
|
|
|
GrBackendSemaphore signalSemaphores[]);
|
|
|
|
|
2015-05-07 15:23:19 +00:00
|
|
|
/**
|
|
|
|
* An ID associated with this context, guaranteed to be unique.
|
|
|
|
*/
|
|
|
|
uint32_t uniqueID() { return fUniqueID; }
|
|
|
|
|
2016-08-03 21:26:53 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
GrContextPriv contextPriv();
|
|
|
|
const GrContextPriv contextPriv() const;
|
|
|
|
|
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;
|
|
|
|
|
2018-01-19 17:56:09 +00:00
|
|
|
protected:
|
2018-03-02 13:53:14 +00:00
|
|
|
GrContext(GrBackend, int32_t id = SK_InvalidGenID);
|
2018-01-19 17:56:09 +00:00
|
|
|
|
2018-03-02 13:53:14 +00:00
|
|
|
bool initCommon(const GrContextOptions&);
|
|
|
|
virtual bool init(const GrContextOptions&) = 0; // must be called after the ctor!
|
2018-03-01 19:16:41 +00:00
|
|
|
|
2018-03-07 20:13:18 +00:00
|
|
|
virtual GrAtlasManager* onGetAtlasManager() = 0;
|
2018-03-01 19:16:41 +00:00
|
|
|
|
2018-03-02 13:53:14 +00:00
|
|
|
const GrBackend fBackend;
|
2018-03-01 19:16:41 +00:00
|
|
|
sk_sp<const GrCaps> fCaps;
|
2018-03-02 13:53:14 +00:00
|
|
|
sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
|
2018-07-31 13:44:36 +00:00
|
|
|
sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
|
2018-03-01 19:16:41 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
private:
|
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;
|
2018-01-08 18:40:32 +00:00
|
|
|
GrProxyProvider* fProxyProvider;
|
2015-04-30 21:18:54 +00:00
|
|
|
|
2018-06-19 17:09:54 +00:00
|
|
|
// All the GrOp-derived classes use this pool.
|
|
|
|
sk_sp<GrOpMemoryPool> fOpMemoryPool;
|
2016-03-11 14:46:33 +00:00
|
|
|
|
2018-03-01 16:36:45 +00:00
|
|
|
GrGlyphCache* fGlyphCache;
|
2016-10-27 16:30:08 +00:00
|
|
|
std::unique_ptr<GrTextBlobCache> fTextBlobCache;
|
2011-03-25 12:31:16 +00:00
|
|
|
|
2017-02-14 19:15:48 +00:00
|
|
|
bool fDisableGpuYUVConversion;
|
2018-02-12 19:32:17 +00:00
|
|
|
bool fSharpenMipmappedTextures;
|
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
|
|
|
|
2016-01-06 16:26:09 +00:00
|
|
|
// In debug builds we guard against improper thread handling
|
2016-01-08 18:09:13 +00:00
|
|
|
// This guard is passed to the GrDrawingManager and, from there to all the
|
2017-03-04 13:12:46 +00:00
|
|
|
// GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice.
|
2016-03-11 14:46:33 +00:00
|
|
|
mutable GrSingleOwner fSingleOwner;
|
2016-01-06 16:26:09 +00:00
|
|
|
|
2017-08-23 14:12:00 +00:00
|
|
|
std::unique_ptr<SkTaskGroup> fTaskGroup;
|
|
|
|
|
2016-03-11 14:46:33 +00:00
|
|
|
const uint32_t fUniqueID;
|
2014-08-12 14:26:25 +00:00
|
|
|
|
2016-10-27 16:30:08 +00:00
|
|
|
std::unique_ptr<GrDrawingManager> fDrawingManager;
|
2015-10-17 14:43:27 +00:00
|
|
|
|
2016-03-11 14:46:33 +00:00
|
|
|
GrAuditTrail fAuditTrail;
|
2016-01-08 15:19:47 +00:00
|
|
|
|
2017-11-01 19:45:43 +00:00
|
|
|
GrContextOptions::PersistentCache* fPersistentCache;
|
|
|
|
|
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
|
|
|
|
2013-01-29 07:05:52 +00:00
|
|
|
/**
|
2017-04-17 15:48:28 +00:00
|
|
|
* These functions create premul <-> unpremul effects. If the second argument is 'true', they
|
|
|
|
* use the specialized round-trip effects from GrConfigConversionEffect, otherwise they
|
|
|
|
* create effects that do naive multiply or divide.
|
2013-01-28 14:26:09 +00:00
|
|
|
*/
|
2017-08-11 13:40:37 +00:00
|
|
|
std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>,
|
|
|
|
bool useConfigConversionEffect);
|
|
|
|
std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>,
|
|
|
|
bool useConfigConversionEffect);
|
2017-04-17 15:48:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if createPMtoUPMEffect and createUPMToPMEffect will succeed for non-sRGB 8888
|
|
|
|
* configs. In other words, did we find a pair of round-trip preserving conversion effects?
|
|
|
|
*/
|
|
|
|
bool validPMUPMConversionExists();
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2015-04-10 14:01:30 +00:00
|
|
|
/**
|
|
|
|
* A callback similar to the above for use by the TextBlobCache
|
|
|
|
* TODO move textblob draw calls below context so we can use the call above.
|
|
|
|
*/
|
|
|
|
static void TextBlobCacheOverBudgetCB(void* data);
|
|
|
|
|
2013-09-09 13:38:37 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
2016-03-11 14:46:33 +00:00
|
|
|
/**
|
|
|
|
* Can be used to perform actions related to the generating GrContext in a thread safe manner. The
|
|
|
|
* proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
|
|
|
|
*/
|
2018-03-29 21:20:46 +00:00
|
|
|
class SK_API GrContextThreadSafeProxy : public SkRefCnt {
|
2017-11-30 13:46:03 +00:00
|
|
|
public:
|
2018-05-11 15:19:22 +00:00
|
|
|
~GrContextThreadSafeProxy();
|
|
|
|
|
2017-11-30 13:46:03 +00:00
|
|
|
bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; }
|
|
|
|
|
2018-02-13 22:03:00 +00:00
|
|
|
/**
|
|
|
|
* Create a surface characterization for a DDL that will be replayed into the GrContext
|
|
|
|
* that created this proxy. On failure the resulting characterization will be invalid (i.e.,
|
|
|
|
* "!c.isValid()").
|
|
|
|
*
|
|
|
|
* @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the
|
|
|
|
* DDL created with this characterization is replayed.
|
|
|
|
* Note: the contract here is that the DDL will be created as
|
|
|
|
* if it had a full 'cacheMaxResourceBytes' to use. If replayed
|
|
|
|
* into a GrContext that already has locked GPU memory, the
|
|
|
|
* replay can exceed the budget. To rephrase, all resource
|
|
|
|
* allocation decisions are made at record time and at playback
|
|
|
|
* time the budget limits will be ignored.
|
|
|
|
* @param ii The image info specifying properties of the SkSurface that
|
|
|
|
* the DDL created with this characterization will be replayed
|
|
|
|
* into.
|
|
|
|
* Note: Ganesh doesn't make use of the SkImageInfo's alphaType
|
|
|
|
* @param backendFormat Information about the format of the GPU surface that will
|
|
|
|
* back the SkSurface upon replay
|
|
|
|
* @param sampleCount The sample count of the SkSurface that the DDL created with
|
|
|
|
* this characterization will be replayed into
|
|
|
|
* @param origin The origin of the SkSurface that the DDL created with this
|
|
|
|
* characterization will be replayed into
|
|
|
|
* @param surfaceProps The surface properties of the SkSurface that the DDL created
|
|
|
|
* with this characterization will be replayed into
|
|
|
|
* @param isMipMapped Will the surface the DDL will be replayed into have space
|
|
|
|
* allocated for mipmaps?
|
2018-04-26 20:31:38 +00:00
|
|
|
* @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL
|
|
|
|
* FBO 0. This flag is only valid if using an GL backend.
|
2018-02-13 22:03:00 +00:00
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createCharacterization(
|
|
|
|
size_t cacheMaxResourceBytes,
|
|
|
|
const SkImageInfo& ii, const GrBackendFormat& backendFormat,
|
|
|
|
int sampleCount, GrSurfaceOrigin origin,
|
|
|
|
const SkSurfaceProps& surfaceProps,
|
2018-04-26 20:31:38 +00:00
|
|
|
bool isMipMapped, bool willUseGLFBO0 = false);
|
2018-02-13 22:03:00 +00:00
|
|
|
|
2018-05-10 16:57:17 +00:00
|
|
|
bool operator==(const GrContextThreadSafeProxy& that) const {
|
|
|
|
// Each GrContext should only ever have a single thread-safe proxy.
|
|
|
|
SkASSERT((this == &that) == (fContextUniqueID == that.fContextUniqueID));
|
|
|
|
return this == &that;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
|
|
|
|
|
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
GrContextThreadSafeProxyPriv priv();
|
|
|
|
const GrContextThreadSafeProxyPriv priv() const;
|
2018-03-06 18:41:51 +00:00
|
|
|
|
2016-03-11 14:46:33 +00:00
|
|
|
private:
|
2017-12-13 16:50:22 +00:00
|
|
|
// DDL TODO: need to add unit tests for backend & maybe options
|
|
|
|
GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
|
|
|
|
uint32_t uniqueID,
|
|
|
|
GrBackend backend,
|
2018-07-31 13:44:36 +00:00
|
|
|
const GrContextOptions& options,
|
|
|
|
sk_sp<GrSkSLFPFactoryCache> cache);
|
|
|
|
|
|
|
|
sk_sp<const GrCaps> fCaps;
|
|
|
|
const uint32_t fContextUniqueID;
|
|
|
|
const GrBackend fBackend;
|
|
|
|
const GrContextOptions fOptions;
|
|
|
|
sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
|
2016-03-11 14:46:33 +00:00
|
|
|
|
2018-03-02 13:53:14 +00:00
|
|
|
friend class GrDirectContext; // To construct this object
|
2018-05-10 16:57:17 +00:00
|
|
|
friend class GrContextThreadSafeProxyPriv;
|
2016-03-11 14:46:33 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
#endif
|