2 * Copyright 2021 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef skgpu_graphite_Context_DEFINED
9 #define skgpu_graphite_Context_DEFINED
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkShader.h"
13 #include "include/gpu/graphite/GraphiteTypes.h"
16 class SkCombinationBuilder;
17 class SkRuntimeEffect;
19 namespace skgpu::graphite {
27 struct MtlBackendContext;
34 Context(const Context&) = delete;
35 Context(Context&&) = delete;
36 Context& operator=(const Context&) = delete;
37 Context& operator=(Context&&) = delete;
42 static std::unique_ptr<Context> MakeMetal(const skgpu::graphite::MtlBackendContext&);
45 BackendApi backend() const { return fBackend; }
47 std::unique_ptr<Recorder> makeRecorder();
49 void insertRecording(const InsertRecordingInfo&);
50 void submit(SyncToCpu = SyncToCpu::kNo);
53 * Checks whether any asynchronous work is complete and if so calls related callbacks.
55 void checkAsyncWorkCompletion();
57 // TODO: add "SkShaderID addUserDefinedShader(sk_sp<SkRuntimeEffect>)" here
58 // TODO: add "SkColorFilterID addUserDefinedColorFilter(sk_sp<SkRuntimeEffect>)" here
59 SkBlenderID addUserDefinedBlender(sk_sp<SkRuntimeEffect>);
61 void preCompile(const SkCombinationBuilder&);
64 * Creates a new backend gpu texture matching the dimensinos and TextureInfo. If an invalid
65 * TextureInfo or a TextureInfo Skia can't support is passed in, this will return an invalid
66 * BackendTexture. Thus the client should check isValid on the returned BackendTexture to know
67 * if it succeeded or not.
69 * If this does return a valid BackendTexture, the caller is required to use
70 * Context::deleteBackendTexture to delete that texture.
72 BackendTexture createBackendTexture(SkISize dimensions, const TextureInfo&);
75 * Called to delete the passed in BackendTexture. This should only be called if the
76 * BackendTexture was created by calling Context::createBackendTexture. If the BackendTexture is
77 * not valid or does not match the BackendApi of the Context then nothing happens.
79 * Otherwise this will delete/release the backend object that is wrapped in the BackendTexture.
80 * The BackendTexture will be reset to an invalid state and should not be used again.
82 void deleteBackendTexture(BackendTexture&);
84 // Provides access to functions that aren't part of the public API.
86 const ContextPriv priv() const; // NOLINT(readability-const-return-type)
89 Context(sk_sp<Gpu>, BackendApi);
92 friend class ContextPriv;
94 sk_sp<CommandBuffer> fCurrentCommandBuffer;
97 sk_sp<GlobalCache> fGlobalCache;
101 } // namespace skgpu::graphite
103 #endif // skgpu_graphite_Context_DEFINED