blob: 33838c841078b8bbc535cf3652241ee12db7773a [file] [log] [blame]
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef skgpu_Context_DEFINED
#define skgpu_Context_DEFINED
#include <vector>
#include "include/core/SkBlendMode.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/core/SkTileMode.h"
#include "experimental/graphite/include/GraphiteTypes.h"
namespace skgpu {
class ContextPriv;
class Gpu;
class Recorder;
class Recording;
namespace mtl { struct BackendContext; }
struct ShaderCombo {
enum class ShaderType {
kNone,
kLinearGradient,
kRadialGradient,
kSweepGradient,
kConicalGradient
};
ShaderCombo() {}
ShaderCombo(std::vector<ShaderType> types,
std::vector<SkTileMode> tileModes)
: fTypes(std::move(types))
, fTileModes(std::move(tileModes)) {
}
std::vector<ShaderType> fTypes;
std::vector<SkTileMode> fTileModes;
};
struct PaintCombo {
std::vector<ShaderCombo> fShaders;
std::vector<SkBlendMode> fBlendModes;
};
class Context final : public SkRefCnt {
public:
~Context() override;
#ifdef SK_METAL
static sk_sp<Context> MakeMetal(const skgpu::mtl::BackendContext&);
#endif
sk_sp<Recorder> createRecorder();
void insertRecording(std::unique_ptr<Recording>);
void submit(SyncToCpu = SyncToCpu::kNo);
void preCompile(const PaintCombo&);
// Provides access to functions that aren't part of the public API.
ContextPriv priv();
const ContextPriv priv() const; // NOLINT(readability-const-return-type)
protected:
Context(sk_sp<Gpu>);
private:
friend class ContextPriv;
std::vector<std::unique_ptr<Recording>> fRecordings;
sk_sp<Gpu> fGpu;
};
} // namespace skgpu
#endif // skgpu_Context_DEFINED