| 1 |
/* |
| 2 |
* Copyright 2024 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 |
#ifndef skgpu_graphite_TextureInfoPriv_DEFINED |
| 8 |
#define skgpu_graphite_TextureInfoPriv_DEFINED |
| 9 |
|
| 10 |
#include "include/gpu/graphite/TextureInfo.h" |
| 11 |
#include "src/gpu/graphite/ResourceTypes.h" |
| 12 |
#include "src/gpu/graphite/TextureFormat.h" |
| 13 |
|
| 14 |
#include <cstdint> |
| 15 |
|
| 16 |
namespace skgpu::graphite { |
| 17 |
|
| 18 |
class Caps; |
| 19 |
|
| 20 |
// NOTE: This is a class so that it can be friended by TextureInfo and the backend info classes. |
| 21 |
class TextureInfoPriv { |
| 22 |
public: |
| 23 |
static TextureFormat ViewFormat(const TextureInfo& info) { |
| 24 |
return info.fViewFormat; |
| 25 |
} |
| 26 |
static uint32_t ChannelMask(const TextureInfo& info) { |
| 27 |
return TextureFormatChannelMask(ViewFormat(info)); |
| 28 |
} |
| 29 |
|
| 30 |
template <typename BackendTextureInfo> |
| 31 |
static TextureInfo Make(const BackendTextureInfo& data) { |
| 32 |
return TextureInfo(data); |
| 33 |
} |
| 34 |
|
| 35 |
template <typename BackendTextureInfo> |
| 36 |
static const BackendTextureInfo& Get(const TextureInfo& info) { |
| 37 |
SkASSERT(info.isValid() && info.backend() == BackendTextureInfo::kBackend); |
| 38 |
return *(static_cast<const BackendTextureInfo*>(info.fData.get())); |
| 39 |
} |
| 40 |
|
| 41 |
template <typename BackendTextureInfo> |
| 42 |
static bool Copy(const TextureInfo& info, BackendTextureInfo* out) { |
| 43 |
if (!info.isValid() || info.backend() != BackendTextureInfo::kBackend) { |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
SkASSERT(out); |
| 48 |
*out = Get<BackendTextureInfo>(info); |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
private: |
| 53 |
TextureInfoPriv() = delete; |
| 54 |
TextureInfoPriv(const TextureInfoPriv&) = delete; |
| 55 |
}; |
| 56 |
|
| 57 |
} // namespace skgpu::graphite |
| 58 |
|
| 59 |
#endif |