| 1 |
/* |
| 2 |
* Copyright 2022 Google LLC. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef skgpu_MutableTextureState_DEFINED |
| 9 |
#define skgpu_MutableTextureState_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkTypes.h" |
| 13 |
#include "include/private/base/SkAnySubclass.h" |
| 14 |
|
| 15 |
#include <cstddef> |
| 16 |
|
| 17 |
namespace skgpu { |
| 18 |
enum class BackendApi : unsigned int; |
| 19 |
class MutableTextureStateData; |
| 20 |
|
| 21 |
/** |
| 22 |
* Since Skia and clients can both modify gpu textures and their connected state, Skia needs a way |
| 23 |
* for clients to inform us if they have modifiend any of this state. In order to not need setters |
| 24 |
* for every single API and state, we use this class to be a generic wrapper around all the mutable |
| 25 |
* state. This class is used for calls that inform Skia of these texture/image state changes by the |
| 26 |
* client as well as for requesting state changes to be done by Skia. The backend specific state |
| 27 |
* that is wrapped by this class are located in files like: |
| 28 |
* - include/gpu/vk/VulkanMutableTextureState.h |
| 29 |
*/ |
| 30 |
class SK_API MutableTextureState : public SkRefCnt { |
| 31 |
public: |
| 32 |
MutableTextureState(); |
| 33 |
~MutableTextureState() override; |
| 34 |
|
| 35 |
MutableTextureState(const MutableTextureState& that); |
| 36 |
|
| 37 |
MutableTextureState& operator=(const MutableTextureState& that); |
| 38 |
|
| 39 |
void set(const MutableTextureState& that); |
| 40 |
|
| 41 |
BackendApi backend() const { return fBackend; } |
| 42 |
|
| 43 |
// Returns true if the backend mutable state has been initialized. |
| 44 |
bool isValid() const { return fIsValid; } |
| 45 |
|
| 46 |
private: |
| 47 |
friend class MutableTextureStateData; |
| 48 |
friend class MutableTextureStatePriv; |
| 49 |
// Size determined by looking at the MutableTextureStateData subclasses, then |
| 50 |
// guessing-and-checking. Compiler will complain if this is too small - in that case, |
| 51 |
// just increase the number. |
| 52 |
inline constexpr static size_t kMaxSubclassSize = 16; |
| 53 |
using AnyStateData = SkAnySubclass<MutableTextureStateData, kMaxSubclassSize>; |
| 54 |
|
| 55 |
template <typename StateData> |
| 56 |
MutableTextureState(BackendApi api, const StateData& data) : fBackend(api), fIsValid(true) { |
| 57 |
fStateData.emplace<StateData>(data); |
| 58 |
} |
| 59 |
|
| 60 |
AnyStateData fStateData; |
| 61 |
|
| 62 |
BackendApi fBackend; |
| 63 |
bool fIsValid; |
| 64 |
}; |
| 65 |
|
| 66 |
} // namespace skgpu |
| 67 |
|
| 68 |
#endif // skgpu_MutableTextureState_DEFINED |