2019-01-29 18:14:47 +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 GrContextThreadSafeProxy_DEFINED
|
|
|
|
#define GrContextThreadSafeProxy_DEFINED
|
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2021-02-22 19:08:07 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#include "include/core/SkImageInfo.h"
|
2020-06-02 15:23:16 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2020-06-01 14:11:49 +00:00
|
|
|
#include <atomic>
|
|
|
|
|
2019-01-29 18:14:47 +00:00
|
|
|
class GrBackendFormat;
|
2020-06-02 15:23:16 +00:00
|
|
|
class GrCaps;
|
2019-01-29 18:14:47 +00:00
|
|
|
class GrContextThreadSafeProxyPriv;
|
2020-06-25 19:35:23 +00:00
|
|
|
class GrTextBlobCache;
|
2020-10-08 15:00:02 +00:00
|
|
|
class GrThreadSafeCache;
|
2021-03-03 16:03:38 +00:00
|
|
|
class GrThreadSafePipelineBuilder;
|
2019-01-29 18:14:47 +00:00
|
|
|
class SkSurfaceCharacterization;
|
2020-03-30 19:57:14 +00:00
|
|
|
class SkSurfaceProps;
|
2019-01-29 18:14:47 +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.
|
|
|
|
*/
|
2020-06-02 15:23:16 +00:00
|
|
|
class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt<GrContextThreadSafeProxy> {
|
2019-01-29 18:14:47 +00:00
|
|
|
public:
|
2020-06-02 15:23:16 +00:00
|
|
|
~GrContextThreadSafeProxy();
|
2019-01-29 18:14:47 +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()").
|
|
|
|
*
|
2020-11-04 15:50:39 +00:00
|
|
|
* @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
|
2020-11-06 15:29:57 +00:00
|
|
|
* created with this characterization will be replayed
|
|
|
|
* into
|
2020-11-04 15:50:39 +00:00
|
|
|
* @param isMipMapped Will the surface the DDL will be replayed into have
|
|
|
|
* space allocated for mipmaps?
|
|
|
|
* @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.
|
|
|
|
* @param isTextureable Will the surface be able to act as a texture?
|
|
|
|
* @param isProtected Will the (Vulkan) surface be DRM protected?
|
|
|
|
* @param vkRTSupportsInputAttachment Can the vulkan surface be used as in input
|
|
|
|
attachment?
|
|
|
|
* @param forVulkanSecondaryCommandBuffer Will the surface be wrapping a vulkan secondary
|
|
|
|
* command buffer via a GrVkSecondaryCBDrawContext? If
|
|
|
|
* this is true then the following is required:
|
|
|
|
* isTexureable = false
|
|
|
|
* isMipMapped = false
|
|
|
|
* willUseGLFBO0 = false
|
|
|
|
* vkRTSupportsInputAttachment = false
|
2019-01-29 18:14:47 +00:00
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createCharacterization(
|
|
|
|
size_t cacheMaxResourceBytes,
|
2020-07-22 13:35:49 +00:00
|
|
|
const SkImageInfo& ii,
|
|
|
|
const GrBackendFormat& backendFormat,
|
|
|
|
int sampleCount,
|
|
|
|
GrSurfaceOrigin origin,
|
2019-01-29 18:14:47 +00:00
|
|
|
const SkSurfaceProps& surfaceProps,
|
2019-02-03 22:17:54 +00:00
|
|
|
bool isMipMapped,
|
|
|
|
bool willUseGLFBO0 = false,
|
2019-07-10 13:28:59 +00:00
|
|
|
bool isTextureable = true,
|
2020-08-27 18:29:00 +00:00
|
|
|
GrProtected isProtected = GrProtected::kNo,
|
2020-11-04 15:50:39 +00:00
|
|
|
bool vkRTSupportsInputAttachment = false,
|
|
|
|
bool forVulkanSecondaryCommandBuffer = false);
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2019-08-13 20:16:42 +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.
|
|
|
|
*/
|
2020-06-02 15:23:16 +00:00
|
|
|
GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const;
|
|
|
|
|
|
|
|
bool isValid() const { return nullptr != fCaps; }
|
2019-08-13 20:16:42 +00:00
|
|
|
|
2019-01-29 18:14:47 +00:00
|
|
|
bool operator==(const GrContextThreadSafeProxy& that) const {
|
|
|
|
// Each GrContext should only ever have a single thread-safe proxy.
|
2020-06-02 15:23:16 +00:00
|
|
|
SkASSERT((this == &that) == (this->fContextID == that.fContextID));
|
2019-01-29 18:14:47 +00:00
|
|
|
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();
|
2020-08-07 17:05:14 +00:00
|
|
|
const GrContextThreadSafeProxyPriv priv() const; // NOLINT(readability-const-return-type)
|
2019-01-29 18:14:47 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-04 22:50:57 +00:00
|
|
|
friend class GrContextThreadSafeProxyPriv; // for ctor and hidden methods
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2019-02-04 22:50:57 +00:00
|
|
|
// DDL TODO: need to add unit tests for backend & maybe options
|
2020-06-02 15:23:16 +00:00
|
|
|
GrContextThreadSafeProxy(GrBackendApi, const GrContextOptions&);
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2020-06-01 14:11:49 +00:00
|
|
|
void abandonContext();
|
|
|
|
bool abandoned() const;
|
|
|
|
|
2020-06-02 15:23:16 +00:00
|
|
|
// TODO: This should be part of the constructor but right now we have a chicken-and-egg problem
|
|
|
|
// with GrContext where we get the caps by creating a GPU which requires a context (see the
|
|
|
|
// `init` method on GrContext_Base).
|
2021-03-03 16:03:38 +00:00
|
|
|
void init(sk_sp<const GrCaps>, sk_sp<GrThreadSafePipelineBuilder>);
|
|
|
|
|
|
|
|
const GrBackendApi fBackend;
|
|
|
|
const GrContextOptions fOptions;
|
|
|
|
const uint32_t fContextID;
|
|
|
|
sk_sp<const GrCaps> fCaps;
|
|
|
|
std::unique_ptr<GrTextBlobCache> fTextBlobCache;
|
|
|
|
std::unique_ptr<GrThreadSafeCache> fThreadSafeCache;
|
|
|
|
sk_sp<GrThreadSafePipelineBuilder> fPipelineBuilder;
|
|
|
|
std::atomic<bool> fAbandoned{false};
|
2019-01-29 18:14:47 +00:00
|
|
|
};
|
|
|
|
|
2021-02-22 19:08:07 +00:00
|
|
|
#else // !SK_SUPPORT_GPU
|
|
|
|
class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt<GrContextThreadSafeProxy> {};
|
|
|
|
#endif
|
|
|
|
|
2019-01-29 18:14:47 +00:00
|
|
|
#endif
|