| 1 |
/* |
| 2 |
* Copyright 2021 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 |
#include "include/gpu/graphite/TextureInfo.h" |
| 9 |
|
| 10 |
#include "include/core/SkFourByteTag.h" |
| 11 |
#include "include/core/SkStream.h" |
| 12 |
#include "src/gpu/GpuTypesPriv.h" |
| 13 |
#include "src/gpu/graphite/Caps.h" |
| 14 |
#include "src/gpu/graphite/TextureFormat.h" |
| 15 |
#include "src/gpu/graphite/TextureInfoPriv.h" |
| 16 |
|
| 17 |
namespace skgpu::graphite { |
| 18 |
|
| 19 |
TextureInfo::TextureInfo(const TextureInfo& that) |
| 20 |
: fBackend(that.fBackend) |
| 21 |
, fViewFormat(that.fViewFormat) |
| 22 |
, fProtected(that.fProtected) { |
| 23 |
if (!that.fData.has_value()) { |
| 24 |
SkASSERT(!fData.has_value()); |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
that.fData->copyTo(fData); |
| 29 |
} |
| 30 |
|
| 31 |
TextureInfo& TextureInfo::operator=(const TextureInfo& that) { |
| 32 |
if (this != &that) { |
| 33 |
this->~TextureInfo(); |
| 34 |
new (this) TextureInfo(that); |
| 35 |
} |
| 36 |
return *this; |
| 37 |
} |
| 38 |
|
| 39 |
bool TextureInfo::isCompatible(const TextureInfo& that, bool requireExact) const { |
| 40 |
if (fBackend != that.fBackend) { |
| 41 |
return false; |
| 42 |
} else if (fBackend == skgpu::BackendApi::kUnsupported) { |
| 43 |
SkASSERT(!fData.has_value() && !that.fData.has_value()); |
| 44 |
return true; |
| 45 |
} else { |
| 46 |
SkASSERT(fData.has_value() && that.fData.has_value()); |
| 47 |
return fData->fSampleCount == that.fData->fSampleCount && |
| 48 |
fData->fMipmapped == that.fData->fMipmapped && |
| 49 |
fData->isCompatible(that, requireExact); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
SkString TextureInfo::toString() const { |
| 54 |
if (!this->isValid()) { |
| 55 |
return SkString("{}"); |
| 56 |
} |
| 57 |
|
| 58 |
// Strip the leading "k" from the enum name when creating the TextureInfo string. |
| 59 |
SkASSERT(BackendApiToStr(fBackend)[0] == 'k'); |
| 60 |
const char* backendName = BackendApiToStr(fBackend) + 1; |
| 61 |
|
| 62 |
return SkStringPrintf("%s(viewFormat=%s,%s,bpp=%zu,sampleCount=%u,mipmapped=%d,protected=%d)", |
| 63 |
backendName, |
| 64 |
TextureFormatName(fViewFormat), |
| 65 |
fData->toBackendString().c_str(), |
| 66 |
TextureFormatBytesPerBlock(fViewFormat), |
| 67 |
(unsigned) fData->fSampleCount, |
| 68 |
static_cast<int>(fData->fMipmapped), |
| 69 |
static_cast<int>(fProtected)); |
| 70 |
} |
| 71 |
|
| 72 |
} // namespace skgpu::graphite |