blob: 7f7e075451f81c37dfc7f0743723fe98ee53ef29 [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.
*/
#ifndef skgpu_graphite_Image_Graphite_DEFINED
#define skgpu_graphite_Image_Graphite_DEFINED
#include "src/gpu/graphite/Image_Base_Graphite.h"
#include "include/gpu/graphite/Image.h"
#include "src/gpu/graphite/TextureProxyView.h"
namespace skgpu {
class RefCntedCallback;
}
namespace skgpu::graphite {
class Context;
class Device;
class Recorder;
class Image final : public Image_Base {
public:
Image(TextureProxyView, const SkColorInfo&);
~Image() override;
// Create an Image that wraps the Device and automatically flushes or references the Device's
// pending tasks when the Image is used in a draw to another canvas.
static sk_sp<Image> WrapDevice(sk_sp<Device> device);
// Create an Image by copying the provided texture proxy view into a new texturable proxy.
// The source texture does not have to be texturable if it is blittable.
static sk_sp<Image> Copy(Recorder*,
const TextureProxyView& srcView,
const SkColorInfo&,
const SkIRect& subset,
Budgeted,
Mipmapped,
SkBackingFit);
const TextureProxyView& textureProxyView() const { return fTextureProxyView; }
// Always copy this image, even if 'subset' and mipmapping match this image exactly.
sk_sp<Image> copyImage(Recorder*, const SkIRect& subset,
Budgeted, Mipmapped, SkBackingFit) const;
SkImage_Base::Type type() const override { return SkImage_Base::Type::kGraphite; }
bool onHasMipmaps() const override {
return fTextureProxyView.proxy()->mipmapped() == Mipmapped::kYes;
}
bool onIsProtected() const override {
return fTextureProxyView.proxy()->isProtected();
}
size_t textureSize() const override;
sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const override;
sk_sp<SkImage> makeTextureImage(Recorder*, RequiredProperties) const override;
static sk_sp<TextureProxy> MakePromiseImageLazyProxy(
const Caps*,
SkISize dimensions,
TextureInfo,
Volatile,
SkImages::GraphitePromiseImageFulfillProc,
sk_sp<RefCntedCallback>,
SkImages::GraphitePromiseTextureReleaseProc);
#if defined(GRAPHITE_TEST_UTILS)
bool onReadPixelsGraphite(Recorder*,
const SkPixmap& dst,
int srcX,
int srcY) const override;
#endif
private:
sk_sp<SkImage> onMakeSubset(Recorder*, const SkIRect&, RequiredProperties) const override;
sk_sp<SkImage> makeColorTypeAndColorSpace(Recorder*,
SkColorType targetCT,
sk_sp<SkColorSpace> targetCS,
RequiredProperties) const override;
// Include the no-op Ganesh functions to avoid warnings about hidden virtuals.
using Image_Base::onMakeSubset;
using Image_Base::onMakeColorTypeAndColorSpace;
TextureProxyView fTextureProxyView;
};
} // namespace skgpu::graphite
#endif // skgpu_graphite_Image_Graphite_DEFINED