skia2/include/gpu/GrContext.h

462 lines
19 KiB
C
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
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.
*/
#ifndef GrContext_DEFINED
#define GrContext_DEFINED
#include "GrCaps.h"
#include "SkMatrix.h"
#include "SkPathEffect.h"
#include "SkTypes.h"
#include "../private/GrAuditTrail.h"
#include "../private/GrSingleOwner.h"
#include "GrContextOptions.h"
class GrAtlasGlyphCache;
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;
class GrContextPriv;
class GrContextThreadSafeProxy;
class GrDrawingManager;
struct GrDrawOpAtlasConfig;
class GrFragmentProcessor;
struct GrGLInterface;
class GrGpu;
class GrIndexBuffer;
struct GrMockOptions;
class GrOvalRenderer;
class GrPath;
class GrProxyProvider;
class GrRenderTargetContext;
class GrResourceEntry;
class GrResourceCache;
class GrResourceProvider;
class GrSamplerState;
class GrSurfaceProxy;
class GrTextBlobCache;
class GrTextContext;
class GrTextureProxy;
class GrVertexBuffer;
struct GrVkBackendContext;
class GrSwizzle;
class SkTraceMemoryDump;
class SkImage;
class SkSurfaceProps;
class SkTaskGroup;
class SK_API GrContext : public SkRefCnt {
public:
/**
* Creates a GrContext for a backend context.
*/
static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
static GrContext* Create(GrBackend, GrBackendContext);
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
// Deprecated
static sk_sp<GrContext> MakeGL(const GrGLInterface*);
static sk_sp<GrContext> MakeGL(const GrGLInterface*, const GrContextOptions&);
#ifdef SK_VULKAN
static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>, const GrContextOptions&);
static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>);
#endif
#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);
static sk_sp<GrContext> MakeMetal(void* device, void* queue);
#endif
static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
static sk_sp<GrContext> MakeMock(const GrMockOptions*);
virtual ~GrContext();
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
/**
* 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.
* The flag bits, state, is dpendent on which backend is used by the
* context, either GL or D3D (possible in future).
*/
void resetContext(uint32_t state = kAll_GrBackendState);
/**
* Callback function to allow classes to cleanup on GrContext destruction.
* The 'info' field is filled in with the 'info' passed to addCleanUp.
*/
typedef void (*PFCleanUpFunc)(const GrContext* context, void* info);
/**
* Add a function to be called from within GrContext's destructor.
* This gives classes a chance to free resources held on a per context basis.
* The 'info' parameter will be stored and passed to the callback function.
*/
void addCleanUp(PFCleanUpFunc cleanUp, void* info) {
CleanUpData* entry = fCleanUpData.push();
entry->fFunc = cleanUp;
entry->fInfo = info;
}
/**
* Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
* 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.
*/
void abandonContext();
/**
* 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).
*/
void releaseResourcesAndAbandonContext();
///////////////////////////////////////////////////////////////////////////
// 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;
/**
* Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources.
*/
size_t getResourceCachePurgeableBytes() const;
/**
* 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);
/**
* Frees GPU created by the context. Can be called to reduce GPU memory
* pressure.
*/
void freeGpuResources();
/**
* Purge all the unlocked resources from the cache.
* This entry point is mainly meant for timing texture uploads
* and is not defined in normal builds of Skia.
*/
void purgeAllUnlockedResources();
/**
* 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.
*/
void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
// Temporary compatibility API for Android.
void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
this->performDeferredCleanup(msNotUsed);
}
/**
* 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);
/** Access the context capabilities */
const GrCaps* caps() const { return fCaps.get(); }
/**
* 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;
/*
* Create a new render target context backed by a deferred-style
* GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
* renderTargetContexts created via this entry point.
*/
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt = 1,
GrMipMapped = GrMipMapped::kNo,
GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
const SkSurfaceProps* surfaceProps = nullptr,
SkBudgeted = SkBudgeted::kYes);
/*
* This method will attempt to create a renderTargetContext that has, at least, the number of
* channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
* converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
* SRGB-ness will be preserved.
*/
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt = 1,
GrMipMapped = GrMipMapped::kNo,
GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
const SkSurfaceProps* surfaceProps = nullptr,
SkBudgeted budgeted = SkBudgeted::kYes);
///////////////////////////////////////////////////////////////////////////
// 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.
*/
void flush();
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[]);
/**
* An ID associated with this context, guaranteed to be unique.
*/
uint32_t uniqueID() { return fUniqueID; }
///////////////////////////////////////////////////////////////////////////
// Functions intended for internal use only.
bool abandoned() const;
/** Reset GPU stats */
void resetGpuStats() const ;
/** Prints cache stats to the string if GR_CACHE_STATS == 1. */
void dumpCacheStats(SkString*) const;
void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
void printCacheStats() const;
/** Prints GPU stats to the string if GR_GPU_STATS == 1. */
void dumpGpuStats(SkString*) const;
void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
void printGpuStats() const;
/** Returns a string with detailed information about the context & GPU, in JSON format. */
SkString dump() const;
/** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
this is for testing only */
void setTextBlobCacheLimit_ForTesting(size_t bytes);
/** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be
to an array of 3 entries */
void setTextContextAtlasSizes_ForTesting(const GrDrawOpAtlasConfig* configs);
/** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
/** Get pointer to atlas texture for given mask format. Note that this wraps an
actively mutating texture in an SkImage. This could yield unexpected results
if it gets cached or used more generally. */
sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index = 0);
GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
GrContextOptions::PersistentCache* getPersistentCache() { return fPersistentCache; }
/** This is only useful for debug purposes */
SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } )
// Provides access to functions that aren't part of the public API.
GrContextPriv contextPriv();
const GrContextPriv contextPriv() const;
protected:
GrContext(GrContextThreadSafeProxy*);
GrContext(GrBackend);
private:
sk_sp<GrGpu> fGpu;
sk_sp<const GrCaps> fCaps;
GrResourceCache* fResourceCache;
GrResourceProvider* fResourceProvider;
GrProxyProvider* fProxyProvider;
sk_sp<GrContextThreadSafeProxy> fThreadSafeProxy;
GrAtlasGlyphCache* fAtlasGlyphCache;
std::unique_ptr<GrTextBlobCache> fTextBlobCache;
bool fDisableGpuYUVConversion;
bool fDidTestPMConversions;
// true if the PM/UPM conversion succeeded; false otherwise
bool fPMUPMConversionsRoundTrip;
// In debug builds we guard against improper thread handling
// This guard is passed to the GrDrawingManager and, from there to all the
// GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice.
mutable GrSingleOwner fSingleOwner;
std::unique_ptr<SkTaskGroup> fTaskGroup;
struct CleanUpData {
PFCleanUpFunc fFunc;
void* fInfo;
};
SkTDArray<CleanUpData> fCleanUpData;
const uint32_t fUniqueID;
std::unique_ptr<GrDrawingManager> fDrawingManager;
GrAuditTrail fAuditTrail;
const GrBackend fBackend;
GrContextOptions::PersistentCache* fPersistentCache;
// TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
friend class GrContextPriv;
bool init(const GrContextOptions&); // init must be called after either constructor.
/**
* 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.
*/
std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>,
bool useConfigConversionEffect);
std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>,
bool useConfigConversionEffect);
/**
* 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();
/**
* 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);
typedef SkRefCnt INHERITED;
};
/**
* 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.
*/
class GrContextThreadSafeProxy : public SkRefCnt {
public:
bool matches(GrContext* context) const { return context->uniqueID() == fContextUniqueID; }
private:
// DDL TODO: need to add unit tests for backend & maybe options
GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
uint32_t uniqueID,
GrBackend backend,
const GrContextOptions& options)
: fCaps(std::move(caps))
, fContextUniqueID(uniqueID)
, fBackend(backend)
, fOptions(options) {
}
sk_sp<const GrCaps> fCaps;
const uint32_t fContextUniqueID;
const GrBackend fBackend;
const GrContextOptions fOptions;
friend class GrContext;
friend class GrContextPriv;
friend class SkImage;
typedef SkRefCnt INHERITED;
};
#endif