2019-01-30 18:08:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrRecordingContext_DEFINED
|
|
|
|
#define GrRecordingContext_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/private/GrImageContext.h"
|
2020-03-30 19:57:14 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2019-06-18 13:58:02 +00:00
|
|
|
class GrAuditTrail;
|
|
|
|
class GrBackendFormat;
|
2019-02-12 20:24:12 +00:00
|
|
|
class GrDrawingManager;
|
2019-02-15 17:52:59 +00:00
|
|
|
class GrOnFlushCallbackObject;
|
2020-10-27 14:29:46 +00:00
|
|
|
class GrMemoryPool;
|
2020-02-18 19:26:46 +00:00
|
|
|
class GrProgramDesc;
|
2019-12-06 18:05:49 +00:00
|
|
|
class GrProgramInfo;
|
2021-02-18 18:09:36 +00:00
|
|
|
class GrProxyProvider;
|
2019-01-30 18:08:28 +00:00
|
|
|
class GrRecordingContextPriv;
|
2021-03-11 16:49:02 +00:00
|
|
|
class GrSubRunAllocator;
|
2019-06-18 13:58:02 +00:00
|
|
|
class GrSurfaceContext;
|
|
|
|
class GrSurfaceProxy;
|
2019-02-21 21:11:41 +00:00
|
|
|
class GrTextBlobCache;
|
2020-10-08 15:00:02 +00:00
|
|
|
class GrThreadSafeCache;
|
2019-10-22 15:58:17 +00:00
|
|
|
class SkArenaAlloc;
|
2020-05-05 17:03:07 +00:00
|
|
|
class SkJSONWriter;
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2020-08-17 18:31:02 +00:00
|
|
|
#if GR_TEST_UTILS
|
|
|
|
class SkString;
|
|
|
|
#endif
|
|
|
|
|
2019-08-21 19:21:09 +00:00
|
|
|
class GrRecordingContext : public GrImageContext {
|
2019-01-30 18:08:28 +00:00
|
|
|
public:
|
|
|
|
~GrRecordingContext() override;
|
|
|
|
|
2019-08-21 19:21:09 +00:00
|
|
|
SK_API GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
|
2019-08-13 20:16:42 +00:00
|
|
|
return INHERITED::defaultBackendFormat(ct, renderable);
|
|
|
|
}
|
2019-07-29 18:11:35 +00:00
|
|
|
|
2020-06-30 19:30:12 +00:00
|
|
|
/**
|
|
|
|
* Reports whether the GrDirectContext associated with this GrRecordingContext is abandoned.
|
|
|
|
* When called on a GrDirectContext it may actively check whether the underlying 3D API
|
|
|
|
* device/context has been disconnected before reporting the status. If so, calling this
|
|
|
|
* method will transition the GrDirectContext to the abandoned state.
|
|
|
|
*/
|
|
|
|
bool abandoned() override { return INHERITED::abandoned(); }
|
|
|
|
|
2020-07-07 14:20:27 +00:00
|
|
|
/*
|
|
|
|
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
|
|
|
|
* use maxSurfaceSampleCountForColorType().
|
|
|
|
*/
|
|
|
|
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const {
|
|
|
|
if (kR16G16_unorm_SkColorType == colorType ||
|
|
|
|
kA16_unorm_SkColorType == colorType ||
|
|
|
|
kA16_float_SkColorType == colorType ||
|
|
|
|
kR16G16_float_SkColorType == colorType ||
|
|
|
|
kR16G16B16A16_unorm_SkColorType == colorType ||
|
|
|
|
kGray_8_SkColorType == colorType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->maxSurfaceSampleCountForColorType(colorType) > 0;
|
|
|
|
}
|
|
|
|
|
2020-09-11 20:01:09 +00:00
|
|
|
/**
|
|
|
|
* Gets the maximum supported texture size.
|
|
|
|
*/
|
|
|
|
SK_API int maxTextureSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum supported render target size.
|
|
|
|
*/
|
|
|
|
SK_API int maxRenderTargetSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can a SkImage be created with the given color type.
|
|
|
|
*/
|
|
|
|
SK_API bool colorTypeSupportedAsImage(SkColorType) const;
|
|
|
|
|
2020-07-07 14:20:27 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
SK_API int maxSurfaceSampleCountForColorType(SkColorType) const;
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
GrRecordingContextPriv priv();
|
2020-08-07 17:05:14 +00:00
|
|
|
const GrRecordingContextPriv priv() const; // NOLINT(readability-const-return-type)
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2019-12-19 19:50:44 +00:00
|
|
|
// The collection of specialized memory arenas for different types of data recorded by a
|
|
|
|
// GrRecordingContext. Arenas does not maintain ownership of the pools it groups together.
|
|
|
|
class Arenas {
|
|
|
|
public:
|
2021-03-11 16:49:02 +00:00
|
|
|
Arenas(GrMemoryPool*, SkArenaAlloc*, GrSubRunAllocator*);
|
2019-12-19 19:50:44 +00:00
|
|
|
|
|
|
|
// For storing GrOp-derived classes recorded by a GrRecordingContext
|
2020-10-27 14:29:46 +00:00
|
|
|
GrMemoryPool* opMemoryPool() { return fOpMemoryPool; }
|
2019-12-19 19:50:44 +00:00
|
|
|
|
|
|
|
// For storing pipelines and other complex data as-needed by ops
|
|
|
|
SkArenaAlloc* recordTimeAllocator() { return fRecordTimeAllocator; }
|
|
|
|
|
2021-03-11 16:49:02 +00:00
|
|
|
// For storing GrTextBlob SubRuns
|
|
|
|
GrSubRunAllocator* recordTimeSubRunAllocator() { return fRecordTimeSubRunAllocator; }
|
|
|
|
|
2019-12-19 19:50:44 +00:00
|
|
|
private:
|
2020-10-27 14:29:46 +00:00
|
|
|
GrMemoryPool* fOpMemoryPool;
|
|
|
|
SkArenaAlloc* fRecordTimeAllocator;
|
2021-03-11 16:49:02 +00:00
|
|
|
GrSubRunAllocator* fRecordTimeSubRunAllocator;
|
2019-12-19 19:50:44 +00:00
|
|
|
};
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
protected:
|
2020-02-18 19:26:46 +00:00
|
|
|
friend class GrRecordingContextPriv; // for hidden functions
|
|
|
|
friend class SkDeferredDisplayList; // for OwnedArenas
|
|
|
|
friend class SkDeferredDisplayListPriv; // for ProgramData
|
2019-12-19 19:50:44 +00:00
|
|
|
|
|
|
|
// Like Arenas, but preserves ownership of the underlying pools.
|
|
|
|
class OwnedArenas {
|
|
|
|
public:
|
|
|
|
OwnedArenas();
|
|
|
|
~OwnedArenas();
|
|
|
|
|
|
|
|
Arenas get();
|
|
|
|
|
|
|
|
OwnedArenas& operator=(OwnedArenas&&);
|
|
|
|
|
|
|
|
private:
|
2020-10-27 14:29:46 +00:00
|
|
|
std::unique_ptr<GrMemoryPool> fOpMemoryPool;
|
|
|
|
std::unique_ptr<SkArenaAlloc> fRecordTimeAllocator;
|
2021-03-11 16:49:02 +00:00
|
|
|
std::unique_ptr<GrSubRunAllocator> fRecordTimeSubRunAllocator;
|
2019-12-19 19:50:44 +00:00
|
|
|
};
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
GrRecordingContext(sk_sp<GrContextThreadSafeProxy>);
|
2020-12-30 16:20:25 +00:00
|
|
|
|
|
|
|
bool init() override;
|
2019-01-30 18:08:28 +00:00
|
|
|
|
2019-02-11 19:12:03 +00:00
|
|
|
void abandonContext() override;
|
|
|
|
|
2019-02-22 16:16:30 +00:00
|
|
|
GrDrawingManager* drawingManager();
|
2019-02-12 20:24:12 +00:00
|
|
|
|
2020-06-26 12:50:14 +00:00
|
|
|
// There is no going back from this method. It should only be called to control the timing
|
|
|
|
// during abandon or destruction of the context.
|
|
|
|
void destroyDrawingManager();
|
|
|
|
|
2019-12-19 19:50:44 +00:00
|
|
|
Arenas arenas() { return fArenas.get(); }
|
2019-12-12 18:59:20 +00:00
|
|
|
// This entry point should only be used for DDL creation where we want the ops' lifetime to
|
|
|
|
// match that of the DDL.
|
2019-12-19 19:50:44 +00:00
|
|
|
OwnedArenas&& detachArenas();
|
2019-10-22 15:58:17 +00:00
|
|
|
|
2021-02-18 18:09:36 +00:00
|
|
|
GrProxyProvider* proxyProvider() { return fProxyProvider.get(); }
|
|
|
|
const GrProxyProvider* proxyProvider() const { return fProxyProvider.get(); }
|
|
|
|
|
2020-02-18 19:26:46 +00:00
|
|
|
struct ProgramData {
|
|
|
|
ProgramData(std::unique_ptr<const GrProgramDesc>, const GrProgramInfo*);
|
|
|
|
ProgramData(ProgramData&&); // for SkTArray
|
|
|
|
ProgramData(const ProgramData&) = delete;
|
|
|
|
~ProgramData();
|
|
|
|
|
|
|
|
const GrProgramDesc& desc() const { return *fDesc; }
|
|
|
|
const GrProgramInfo& info() const { return *fInfo; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// TODO: store the GrProgramDescs in the 'fRecordTimeData' arena
|
|
|
|
std::unique_ptr<const GrProgramDesc> fDesc;
|
|
|
|
// The program infos should be stored in 'fRecordTimeData' so do not need to be ref
|
|
|
|
// counted or deleted in the destructor.
|
|
|
|
const GrProgramInfo* fInfo = nullptr;
|
|
|
|
};
|
|
|
|
|
2019-12-06 18:05:49 +00:00
|
|
|
// This entry point gives the recording context a chance to cache the provided
|
|
|
|
// programInfo. The DDL context takes this opportunity to store programInfos as a sidecar
|
|
|
|
// to the DDL.
|
|
|
|
virtual void recordProgramInfo(const GrProgramInfo*) {}
|
|
|
|
// This asks the recording context to return any programInfos it may have collected
|
|
|
|
// via the 'recordProgramInfo' call. It is up to the caller to ensure that the lifetime
|
|
|
|
// of the programInfos matches the intended use. For example, in DDL-record mode it
|
|
|
|
// is known that all the programInfos will have been allocated in an arena with the
|
|
|
|
// same lifetime at the DDL itself.
|
2020-02-18 19:26:46 +00:00
|
|
|
virtual void detachProgramData(SkTArray<ProgramData>*) {}
|
2019-12-06 18:05:49 +00:00
|
|
|
|
2019-02-21 21:11:41 +00:00
|
|
|
GrTextBlobCache* getTextBlobCache();
|
|
|
|
const GrTextBlobCache* getTextBlobCache() const;
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
GrThreadSafeCache* threadSafeCache();
|
|
|
|
const GrThreadSafeCache* threadSafeCache() const;
|
2020-09-16 16:31:34 +00:00
|
|
|
|
2019-02-15 17:52:59 +00:00
|
|
|
/**
|
|
|
|
* Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
|
|
|
|
*
|
|
|
|
* NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
|
|
|
|
* ensure its lifetime is tied to that of the context.
|
|
|
|
*/
|
|
|
|
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
|
|
|
|
|
2019-06-18 13:58:02 +00:00
|
|
|
GrAuditTrail* auditTrail() { return fAuditTrail.get(); }
|
2019-02-08 15:29:20 +00:00
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
GrRecordingContext* asRecordingContext() override { return this; }
|
|
|
|
|
2020-05-05 17:03:07 +00:00
|
|
|
class Stats {
|
|
|
|
public:
|
|
|
|
Stats() = default;
|
|
|
|
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
void reset() { *this = {}; }
|
|
|
|
|
|
|
|
int numPathMasksGenerated() const { return fNumPathMasksGenerated; }
|
|
|
|
void incNumPathMasksGenerated() { fNumPathMasksGenerated++; }
|
|
|
|
|
|
|
|
int numPathMaskCacheHits() const { return fNumPathMaskCacheHits; }
|
|
|
|
void incNumPathMasksCacheHits() { fNumPathMaskCacheHits++; }
|
|
|
|
|
|
|
|
#if GR_TEST_UTILS
|
|
|
|
void dump(SkString* out);
|
|
|
|
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
int fNumPathMasksGenerated{0};
|
|
|
|
int fNumPathMaskCacheHits{0};
|
|
|
|
|
|
|
|
#else // GR_GPU_STATS
|
|
|
|
void incNumPathMasksGenerated() {}
|
|
|
|
void incNumPathMasksCacheHits() {}
|
|
|
|
|
|
|
|
#if GR_TEST_UTILS
|
|
|
|
void dump(SkString*) {}
|
|
|
|
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {}
|
|
|
|
#endif
|
|
|
|
#endif // GR_GPU_STATS
|
|
|
|
} fStats;
|
|
|
|
|
|
|
|
Stats* stats() { return &fStats; }
|
|
|
|
const Stats* stats() const { return &fStats; }
|
|
|
|
void dumpJSON(SkJSONWriter*) const;
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
private:
|
2020-12-09 16:17:26 +00:00
|
|
|
// Delete last in case other objects call it during destruction.
|
|
|
|
std::unique_ptr<GrAuditTrail> fAuditTrail;
|
|
|
|
|
2019-12-19 19:50:44 +00:00
|
|
|
OwnedArenas fArenas;
|
|
|
|
|
2019-02-22 16:16:30 +00:00
|
|
|
std::unique_ptr<GrDrawingManager> fDrawingManager;
|
2021-02-18 18:09:36 +00:00
|
|
|
std::unique_ptr<GrProxyProvider> fProxyProvider;
|
2019-02-21 21:11:41 +00:00
|
|
|
|
2020-09-25 15:12:56 +00:00
|
|
|
#if GR_TEST_UTILS
|
2020-02-15 18:41:30 +00:00
|
|
|
int fSuppressWarningMessages = 0;
|
2019-12-11 18:24:11 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrImageContext;
|
2019-01-30 18:08:28 +00:00
|
|
|
};
|
|
|
|
|
2020-07-13 14:29:36 +00:00
|
|
|
/**
|
2020-09-14 15:58:06 +00:00
|
|
|
* Safely cast a possibly-null base context to direct context.
|
2020-07-13 14:29:36 +00:00
|
|
|
*/
|
2020-09-14 15:58:06 +00:00
|
|
|
static inline GrDirectContext* GrAsDirectContext(GrContext_Base* base) {
|
|
|
|
return base ? base->asDirectContext() : nullptr;
|
2020-07-13 14:29:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 18:08:28 +00:00
|
|
|
#endif
|