blob: 6270aa3fdec0911022f898626cc3cb16b7f0cc4a [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)
: fDimensions(dimensions), fInfo(info) {}
TextureProxy::TextureProxy(sk_sp<Texture> texture)
: fDimensions(texture->dimensions())
, fInfo(texture->textureInfo())
, fTexture(std::move(texture)) {}
TextureProxy::~TextureProxy() {}
bool TextureProxy::instantiate(ResourceProvider* resourceProvider) {
if (fTexture) {
return true;
}
fTexture = resourceProvider->findOrCreateScratchTexture(fDimensions, fInfo);
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