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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/GrContext_Base.h"
|
2019-01-29 18:14:47 +00:00
|
|
|
|
|
|
|
class GrBackendFormat;
|
|
|
|
class GrContextThreadSafeProxyPriv;
|
|
|
|
struct SkImageInfo;
|
|
|
|
class SkSurfaceCharacterization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-02-04 17:05:37 +00:00
|
|
|
class SK_API GrContextThreadSafeProxy : public GrContext_Base {
|
2019-01-29 18:14:47 +00:00
|
|
|
public:
|
|
|
|
~GrContextThreadSafeProxy() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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?
|
|
|
|
* @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.
|
2019-02-03 22:17:54 +00:00
|
|
|
* @param isTextureable Will the surface be able to act as a texture?
|
2019-07-10 13:28:59 +00:00
|
|
|
* @param isProtected Will the (Vulkan) surface be DRM protected?
|
2019-01-29 18:14:47 +00:00
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createCharacterization(
|
|
|
|
size_t cacheMaxResourceBytes,
|
|
|
|
const SkImageInfo& ii, const GrBackendFormat& backendFormat,
|
|
|
|
int sampleCount, GrSurfaceOrigin origin,
|
|
|
|
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,
|
|
|
|
GrProtected isProtected = GrProtected::kNo);
|
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.
|
2019-02-04 17:05:37 +00:00
|
|
|
SkASSERT((this == &that) == (this->contextID() == that.contextID()));
|
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();
|
|
|
|
const GrContextThreadSafeProxyPriv priv() const;
|
|
|
|
|
|
|
|
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
|
|
|
|
GrContextThreadSafeProxy(GrBackendApi, const GrContextOptions&, uint32_t contextID);
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2019-02-04 22:50:57 +00:00
|
|
|
bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override;
|
2019-01-29 18:14:47 +00:00
|
|
|
|
2019-02-04 17:05:37 +00:00
|
|
|
typedef GrContext_Base INHERITED;
|
2019-01-29 18:14:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|