* 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 sktext_StrikeForGPU_DEFINED
#define sktext_StrikeForGPU_DEFINED
#include "include/core/SkPath.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypes.h"
#include "src/core/SkGlyph.h"
#include <memory>
#include <optional>
#include <variant>
class SkDescriptor;
class SkDrawable;
class SkReadBuffer;
class SkStrike;
class SkStrikeCache;
class SkStrikeClient;
class SkStrikeSpec;
class SkWriteBuffer;
namespace sktext {
class SkStrikePromise {
public:
SkStrikePromise() = delete;
SkStrikePromise(const SkStrikePromise&) = delete;
SkStrikePromise& operator=(const SkStrikePromise&) = delete;
SkStrikePromise(SkStrikePromise&&);
SkStrikePromise& operator=(SkStrikePromise&&);
explicit SkStrikePromise(sk_sp<SkStrike>&& strike);
explicit SkStrikePromise(const SkStrikeSpec& spec);
static std::optional<SkStrikePromise> MakeFromBuffer(SkReadBuffer& buffer,
const SkStrikeClient* client,
SkStrikeCache* strikeCache);
void flatten(SkWriteBuffer& buffer) const;
SkStrike* strike();
void resetStrike();
const SkDescriptor& descriptor() const;
private:
std::variant<sk_sp<SkStrike>, std::unique_ptr<SkStrikeSpec>> fStrikeOrSpec;
};
class StrikeForGPU : public SkRefCnt {
public:
virtual void lock() = 0;
virtual void unlock() = 0;
virtual SkGlyphDigest digestFor(skglyph::ActionType, SkPackedGlyphID) = 0;
virtual bool prepareForImage(SkGlyph*) = 0;
virtual bool prepareForPath(SkGlyph*) = 0;
virtual bool prepareForDrawable(SkGlyph*) = 0;
virtual const SkDescriptor& getDescriptor() const = 0;
virtual const SkGlyphPositionRoundingSpec& roundingSpec() const = 0;
virtual SkStrikePromise strikePromise() = 0;
};
union IDOrPath {
IDOrPath() {}
IDOrPath(SkGlyphID glyphID) : fGlyphID{glyphID} {}
~IDOrPath() {}
SkGlyphID fGlyphID;
SkPath fPath;
};
union IDOrDrawable {
SkGlyphID fGlyphID;
SkDrawable* fDrawable;
};
class StrikeMutationMonitor {
public:
StrikeMutationMonitor(StrikeForGPU* strike);
~StrikeMutationMonitor();
private:
StrikeForGPU* fStrike;
};
class StrikeForGPUCacheInterface {
public:
virtual ~StrikeForGPUCacheInterface() = default;
virtual sk_sp<StrikeForGPU> findOrCreateScopedStrike(const SkStrikeSpec& strikeSpec) = 0;
};
}
#endif