| 1 |
/* |
| 2 |
* Copyright 2022 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 |
#ifndef skgpu_graphite_TextureUtils_DEFINED |
| 9 |
#define skgpu_graphite_TextureUtils_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkImage.h" |
| 12 |
#include "include/core/SkRefCnt.h" |
| 13 |
#include "include/gpu/GpuTypes.h" |
| 14 |
#include "include/gpu/graphite/Image.h" |
| 15 |
#include "src/gpu/graphite/TextureProxyView.h" |
| 16 |
|
| 17 |
#include <functional> |
| 18 |
#include <tuple> |
| 19 |
#include <utility> |
| 20 |
|
| 21 |
class SkBitmap; |
| 22 |
enum SkColorType : int; |
| 23 |
class SkImage; |
| 24 |
struct SkImageInfo; |
| 25 |
struct SkSamplingOptions; |
| 26 |
|
| 27 |
namespace skgpu { |
| 28 |
class RefCntedCallback; |
| 29 |
} |
| 30 |
|
| 31 |
namespace skgpu::graphite { |
| 32 |
|
| 33 |
class Caps; |
| 34 |
class Context; |
| 35 |
class DrawContext; |
| 36 |
class Image; |
| 37 |
class Recorder; |
| 38 |
class TextureProxyView; |
| 39 |
|
| 40 |
// Create TextureProxyView and SkColorType pair using pixel data in SkBitmap, |
| 41 |
// adding any necessary copy commands to Recorder |
| 42 |
std::tuple<TextureProxyView, SkColorType> MakeBitmapProxyView(Recorder*, |
| 43 |
const SkBitmap&, |
| 44 |
sk_sp<SkMipmap>, |
| 45 |
Mipmapped, |
| 46 |
skgpu::Budgeted, |
| 47 |
std::string_view label); |
| 48 |
|
| 49 |
sk_sp<TextureProxy> MakePromiseImageLazyProxy(const Caps*, |
| 50 |
SkISize dimensions, |
| 51 |
TextureInfo, |
| 52 |
Volatile, |
| 53 |
sk_sp<skgpu::RefCntedCallback> releaseHelper, |
| 54 |
SkImages::GraphitePromiseTextureFulfillProc, |
| 55 |
SkImages::GraphitePromiseTextureFulfillContext, |
| 56 |
SkImages::GraphitePromiseTextureReleaseProc, |
| 57 |
std::string_view label); |
| 58 |
|
| 59 |
sk_sp<SkImage> MakeFromBitmap(Recorder*, |
| 60 |
const SkColorInfo&, |
| 61 |
const SkBitmap&, |
| 62 |
sk_sp<SkMipmap>, |
| 63 |
skgpu::Budgeted, |
| 64 |
SkImage::RequiredProperties, |
| 65 |
std::string_view label); |
| 66 |
|
| 67 |
// NOTE: This estimates a GPU size assuming the texture is not actually memoryless. |
| 68 |
size_t ComputeSize(SkISize dimensions, const TextureInfo&); |
| 69 |
|
| 70 |
sk_sp<Image> CopyAsDraw(Recorder*, |
| 71 |
DrawContext* drawContext, |
| 72 |
const SkImage* image, |
| 73 |
const SkIRect& subset, |
| 74 |
const SkColorInfo& dstColorInfo, |
| 75 |
Budgeted, |
| 76 |
Mipmapped, |
| 77 |
SkBackingFit, |
| 78 |
std::string_view label); |
| 79 |
|
| 80 |
sk_sp<SkImage> RescaleImage(Recorder*, |
| 81 |
const SkImage* srcImage, |
| 82 |
SkIRect srcIRect, |
| 83 |
const SkImageInfo& dstInfo, |
| 84 |
SkImage::RescaleGamma rescaleGamma, |
| 85 |
SkImage::RescaleMode rescaleMode); |
| 86 |
|
| 87 |
bool GenerateMipmaps(Recorder*, DrawContext*, sk_sp<TextureProxy>, const SkColorInfo&); |
| 88 |
|
| 89 |
// Returns the underlying TextureProxyView if it's a non-YUVA Graphite-backed image. |
| 90 |
TextureProxyView AsView(const SkImage*); |
| 91 |
inline TextureProxyView AsView(sk_sp<SkImage> image) { return AsView(image.get()); } |
| 92 |
|
| 93 |
std::pair<sk_sp<SkImage>, SkSamplingOptions> GetGraphiteBacked(Recorder*, |
| 94 |
const SkImage*, |
| 95 |
SkSamplingOptions); |
| 96 |
|
| 97 |
// Return the color format used for coverage mask textures that are rendered by a GPU |
| 98 |
// compute program. |
| 99 |
SkColorType ComputeShaderCoverageMaskTargetFormat(const Caps*); |
| 100 |
|
| 101 |
} // namespace skgpu::graphite |
| 102 |
|
| 103 |
namespace skif { |
| 104 |
|
| 105 |
class Backend; |
| 106 |
|
| 107 |
sk_sp<Backend> MakeGraphiteBackend(skgpu::graphite::Recorder* recorder, |
| 108 |
const SkSurfaceProps&, |
| 109 |
SkColorType); |
| 110 |
|
| 111 |
} // namespace skif |
| 112 |
|
| 113 |
#endif // skgpu_graphite_TextureUtils_DEFINED |