blob: 9d83d4b2c7a6bd81e4b7d7be9ede5b87d159614d [file] [log] [blame]
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/graphite/TextureProxy.h"
#include "src/gpu/graphite/ResourceProvider.h"
#include "src/gpu/graphite/Texture.h"
namespace skgpu::graphite {
TextureProxy::TextureProxy(SkISize dimensions, const TextureInfo& info, SkBudgeted budgeted)
: fDimensions(dimensions), fInfo(info), fBudgeted(budgeted) {
// TODO: Enable this assert once we are correctly handling the creation of all graphite
// SkImages. Right now things like makeImageSnapshot create an invalid proxy with an invalid
// TextureInfo.
// SkASSERT(fInfo.isValid());
}
TextureProxy::TextureProxy(sk_sp<Texture> texture)
: fDimensions(texture->dimensions())
, fInfo(texture->textureInfo())
, fBudgeted(texture->budgeted())
, fTexture(std::move(texture)) {
SkASSERT(fInfo.isValid());
}
TextureProxy::~TextureProxy() {}
bool TextureProxy::instantiate(ResourceProvider* resourceProvider) {
if (fTexture) {
return true;
}
fTexture = resourceProvider->findOrCreateScratchTexture(fDimensions, fInfo, fBudgeted);
if (!fTexture) {
return false;
}
SkDEBUGCODE(this->validateTexture(fTexture.get()));
return true;
}
sk_sp<Texture> TextureProxy::refTexture() const {
return fTexture;
}
const Texture* TextureProxy::texture() const {
return fTexture.get();
}
#ifdef SK_DEBUG
void TextureProxy::validateTexture(const Texture* texture) {
SkASSERT(fDimensions == texture->dimensions());
SkASSERT(fInfo == texture->textureInfo());
}
#endif
} // namespace skgpu::graphite