| 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 "src/gpu/graphite/Texture.h" |
| 9 |
|
| 10 |
#include "include/core/SkTraceMemoryDump.h" |
| 11 |
#include "include/gpu/MutableTextureState.h" |
| 12 |
#include "src/gpu/RefCntedCallback.h" |
| 13 |
#include "src/gpu/graphite/Caps.h" |
| 14 |
#include "src/gpu/graphite/SharedContext.h" |
| 15 |
#include "src/gpu/graphite/TextureUtils.h" |
| 16 |
|
| 17 |
namespace skgpu::graphite { |
| 18 |
|
| 19 |
Texture::Texture(const SharedContext* sharedContext, |
| 20 |
SkISize dimensions, |
| 21 |
const TextureInfo& info, |
| 22 |
bool isTransient, |
| 23 |
sk_sp<MutableTextureState> mutableState, |
| 24 |
Ownership ownership) |
| 25 |
// For the initial GPU size, this assumes that a transient texture will not have any actual |
| 26 |
// memory. Over a texture's lifetime this may not stay the case. |
| 27 |
: Resource(sharedContext, ownership, isTransient ? 0 : ComputeSize(dimensions, info)) |
| 28 |
, fDimensions(dimensions) |
| 29 |
, fInfo(info) |
| 30 |
, fMutableState(std::move(mutableState)) {} |
| 31 |
|
| 32 |
Texture::~Texture() = default; |
| 33 |
|
| 34 |
void Texture::setReleaseCallback(sk_sp<RefCntedCallback> releaseCallback) { |
| 35 |
fReleaseCallback = std::move(releaseCallback); |
| 36 |
} |
| 37 |
|
| 38 |
void Texture::invokeReleaseProc() { |
| 39 |
if (fReleaseCallback) { |
| 40 |
// Depending on the ref count of fReleaseCallback this may or may not actually trigger |
| 41 |
// the ReleaseProc to be called. |
| 42 |
fReleaseCallback.reset(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
bool Texture::uploadDataOnHost(const UploadSource& source, const SkIRect& dstRect) { |
| 47 |
SK_ABORT("Not implemented"); |
| 48 |
} |
| 49 |
|
| 50 |
MutableTextureState* Texture::mutableState() const { return fMutableState.get(); } |
| 51 |
|
| 52 |
void Texture::onDumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump, |
| 53 |
const char* dumpName) const { |
| 54 |
SkString dimensionsStr; |
| 55 |
dimensionsStr.printf("(%dx%d)", fDimensions.width(), fDimensions.height()); |
| 56 |
traceMemoryDump->dumpStringValue(dumpName, "dimensions", dimensionsStr.c_str()); |
| 57 |
traceMemoryDump->dumpStringValue(dumpName, "textureInfo", fInfo.toString().c_str()); |
| 58 |
} |
| 59 |
|
| 60 |
} // namespace skgpu::graphite |