2021-09-20 21:15:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
#ifndef skgpu_graphite_Context_DEFINED
|
|
|
|
#define skgpu_graphite_Context_DEFINED
|
2021-09-20 21:15:16 +00:00
|
|
|
|
2021-09-29 18:29:32 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2021-10-11 20:28:46 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2022-05-18 19:08:40 +00:00
|
|
|
#include "include/gpu/graphite/GraphiteTypes.h"
|
2021-10-14 20:30:49 +00:00
|
|
|
|
2022-05-23 18:38:16 +00:00
|
|
|
class SkBlenderID;
|
|
|
|
class SkCombinationBuilder;
|
2022-05-17 17:47:59 +00:00
|
|
|
class SkRuntimeEffect;
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
namespace skgpu::graphite {
|
2021-09-20 21:15:16 +00:00
|
|
|
|
2021-11-30 17:02:30 +00:00
|
|
|
class BackendTexture;
|
2022-03-24 16:01:50 +00:00
|
|
|
class CommandBuffer;
|
2022-05-18 19:08:40 +00:00
|
|
|
class Context;
|
2021-10-11 15:28:21 +00:00
|
|
|
class ContextPriv;
|
2022-02-01 21:15:04 +00:00
|
|
|
class GlobalCache;
|
2021-09-29 18:29:32 +00:00
|
|
|
class Gpu;
|
2022-04-07 20:08:04 +00:00
|
|
|
struct MtlBackendContext;
|
2021-10-14 20:30:49 +00:00
|
|
|
class Recorder;
|
|
|
|
class Recording;
|
2021-11-30 17:02:30 +00:00
|
|
|
class TextureInfo;
|
2021-09-29 18:29:32 +00:00
|
|
|
|
2022-02-03 16:12:45 +00:00
|
|
|
class Context final {
|
2021-09-20 21:15:16 +00:00
|
|
|
public:
|
2022-02-03 16:12:45 +00:00
|
|
|
Context(const Context&) = delete;
|
|
|
|
Context(Context&&) = delete;
|
|
|
|
Context& operator=(const Context&) = delete;
|
|
|
|
Context& operator=(Context&&) = delete;
|
|
|
|
|
|
|
|
~Context();
|
2021-09-29 18:29:32 +00:00
|
|
|
|
|
|
|
#ifdef SK_METAL
|
2022-04-06 21:16:56 +00:00
|
|
|
static std::unique_ptr<Context> MakeMetal(const skgpu::graphite::MtlBackendContext&);
|
2021-09-29 18:29:32 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-30 17:02:30 +00:00
|
|
|
BackendApi backend() const { return fBackend; }
|
|
|
|
|
2022-01-13 14:51:23 +00:00
|
|
|
std::unique_ptr<Recorder> makeRecorder();
|
2021-10-14 20:30:49 +00:00
|
|
|
|
2022-03-24 16:01:50 +00:00
|
|
|
void insertRecording(const InsertRecordingInfo&);
|
2021-10-14 20:30:49 +00:00
|
|
|
void submit(SyncToCpu = SyncToCpu::kNo);
|
|
|
|
|
2022-03-28 19:27:44 +00:00
|
|
|
/**
|
|
|
|
* Checks whether any asynchronous work is complete and if so calls related callbacks.
|
|
|
|
*/
|
|
|
|
void checkAsyncWorkCompletion();
|
|
|
|
|
2022-05-17 17:47:59 +00:00
|
|
|
// TODO: add "SkShaderID addUserDefinedShader(sk_sp<SkRuntimeEffect>)" here
|
|
|
|
// TODO: add "SkColorFilterID addUserDefinedColorFilter(sk_sp<SkRuntimeEffect>)" here
|
|
|
|
SkBlenderID addUserDefinedBlender(sk_sp<SkRuntimeEffect>);
|
|
|
|
|
2022-05-23 18:38:16 +00:00
|
|
|
void preCompile(const SkCombinationBuilder&);
|
2021-10-11 20:28:46 +00:00
|
|
|
|
2021-11-30 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Creates a new backend gpu texture matching the dimensinos and TextureInfo. If an invalid
|
|
|
|
* TextureInfo or a TextureInfo Skia can't support is passed in, this will return an invalid
|
|
|
|
* BackendTexture. Thus the client should check isValid on the returned BackendTexture to know
|
|
|
|
* if it succeeded or not.
|
|
|
|
*
|
|
|
|
* If this does return a valid BackendTexture, the caller is required to use
|
|
|
|
* Context::deleteBackendTexture to delete that texture.
|
|
|
|
*/
|
|
|
|
BackendTexture createBackendTexture(SkISize dimensions, const TextureInfo&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to delete the passed in BackendTexture. This should only be called if the
|
|
|
|
* BackendTexture was created by calling Context::createBackendTexture. If the BackendTexture is
|
|
|
|
* not valid or does not match the BackendApi of the Context then nothing happens.
|
|
|
|
*
|
|
|
|
* Otherwise this will delete/release the backend object that is wrapped in the BackendTexture.
|
|
|
|
* The BackendTexture will be reset to an invalid state and should not be used again.
|
|
|
|
*/
|
|
|
|
void deleteBackendTexture(BackendTexture&);
|
|
|
|
|
2021-10-11 15:28:21 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
ContextPriv priv();
|
|
|
|
const ContextPriv priv() const; // NOLINT(readability-const-return-type)
|
|
|
|
|
2021-09-29 18:29:32 +00:00
|
|
|
protected:
|
2021-11-30 17:02:30 +00:00
|
|
|
Context(sk_sp<Gpu>, BackendApi);
|
2021-09-29 18:29:32 +00:00
|
|
|
|
2021-09-20 21:15:16 +00:00
|
|
|
private:
|
2021-10-11 15:28:21 +00:00
|
|
|
friend class ContextPriv;
|
|
|
|
|
2022-03-24 16:01:50 +00:00
|
|
|
sk_sp<CommandBuffer> fCurrentCommandBuffer;
|
|
|
|
|
2021-09-29 18:29:32 +00:00
|
|
|
sk_sp<Gpu> fGpu;
|
2022-02-01 21:15:04 +00:00
|
|
|
sk_sp<GlobalCache> fGlobalCache;
|
2021-11-30 17:02:30 +00:00
|
|
|
BackendApi fBackend;
|
2021-09-20 21:15:16 +00:00
|
|
|
};
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
} // namespace skgpu::graphite
|
2021-09-20 21:15:16 +00:00
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
#endif // skgpu_graphite_Context_DEFINED
|