| 1 |
/* |
| 2 |
* Copyright 2018 Google Inc. |
| 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 SkImage_GaneshBase_DEFINED |
| 9 |
#define SkImage_GaneshBase_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkSamplingOptions.h" |
| 13 |
#include "include/gpu/ganesh/GrRecordingContext.h" |
| 14 |
#include "include/private/chromium/SkImageChromium.h" |
| 15 |
#include "include/private/gpu/ganesh/GrImageContext.h" |
| 16 |
#include "src/image/SkImage_Base.h" |
| 17 |
|
| 18 |
#include <memory> |
| 19 |
#include <tuple> |
| 20 |
#include <cstddef> |
| 21 |
#include <cstdint> |
| 22 |
|
| 23 |
class GrBackendFormat; |
| 24 |
class GrBackendTexture; |
| 25 |
class GrCaps; |
| 26 |
class GrContextThreadSafeProxy; |
| 27 |
class GrDirectContext; |
| 28 |
class GrFragmentProcessor; |
| 29 |
class GrRenderTargetProxy; |
| 30 |
class GrSurfaceProxyView; |
| 31 |
class GrTextureProxy; |
| 32 |
class SkBitmap; |
| 33 |
class SkColorSpace; |
| 34 |
class SkImage; |
| 35 |
class SkMatrix; |
| 36 |
class SkRecorder; |
| 37 |
class SkSurface; |
| 38 |
enum GrSurfaceOrigin : int; |
| 39 |
enum SkAlphaType : int; |
| 40 |
enum SkColorType : int; |
| 41 |
enum class GrColorType; |
| 42 |
enum class GrImageTexGenPolicy : int; |
| 43 |
enum class GrSemaphoresSubmitted : bool; |
| 44 |
enum class SkTileMode; |
| 45 |
struct GrFlushInfo; |
| 46 |
struct SkIRect; |
| 47 |
struct SkISize; |
| 48 |
struct SkImageInfo; |
| 49 |
struct SkRect; |
| 50 |
namespace skgpu { |
| 51 |
enum class Mipmapped : bool; |
| 52 |
class RefCntedCallback; |
| 53 |
} // namespace skgpu |
| 54 |
namespace skgpu::ganesh { class SurfaceDrawContext; } |
| 55 |
|
| 56 |
class SkImage_GaneshBase : public SkImage_Base { |
| 57 |
public: |
| 58 |
// From SkImage.h |
| 59 |
bool isValid(SkRecorder*) const final; |
| 60 |
|
| 61 |
// From SkImage_Base.h |
| 62 |
GrImageContext* context() const final { return fContext.get(); } |
| 63 |
GrDirectContext* directContext() const final { return GrAsDirectContext(this->context()); } |
| 64 |
|
| 65 |
bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final; |
| 66 |
|
| 67 |
sk_sp<SkSurface> onMakeSurface(SkRecorder*, const SkImageInfo&) const final; |
| 68 |
|
| 69 |
bool onReadPixels(GrDirectContext* dContext, |
| 70 |
const SkImageInfo& dstInfo, |
| 71 |
void* dstPixels, |
| 72 |
size_t dstRB, |
| 73 |
int srcX, |
| 74 |
int srcY, |
| 75 |
CachingHint) const override; |
| 76 |
|
| 77 |
virtual GrSemaphoresSubmitted flush(GrDirectContext*, const GrFlushInfo&) const = 0; |
| 78 |
|
| 79 |
static bool ValidateBackendTexture(const GrCaps*, |
| 80 |
const GrBackendTexture& tex, |
| 81 |
GrColorType grCT, |
| 82 |
SkColorType ct, |
| 83 |
SkAlphaType at, |
| 84 |
sk_sp<SkColorSpace> cs); |
| 85 |
static bool ValidateCompressedBackendTexture(const GrCaps*, |
| 86 |
const GrBackendTexture& tex, |
| 87 |
SkAlphaType); |
| 88 |
|
| 89 |
// Helper for making a lazy proxy for a promise image. |
| 90 |
// PromiseImageTextureFulfillProc must not be null. |
| 91 |
static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy( |
| 92 |
GrContextThreadSafeProxy*, |
| 93 |
SkISize dimensions, |
| 94 |
const GrBackendFormat&, |
| 95 |
skgpu::Mipmapped, |
| 96 |
SkImages::PromiseImageTextureFulfillProc, |
| 97 |
sk_sp<skgpu::RefCntedCallback> releaseHelper); |
| 98 |
|
| 99 |
virtual std::tuple<GrSurfaceProxyView, GrColorType> asView(GrRecordingContext*, |
| 100 |
skgpu::Mipmapped, |
| 101 |
GrImageTexGenPolicy, |
| 102 |
GrRenderTargetProxy*) const = 0; |
| 103 |
|
| 104 |
virtual std::unique_ptr<GrFragmentProcessor> asFragmentProcessor( |
| 105 |
skgpu::ganesh::SurfaceDrawContext*, |
| 106 |
SkSamplingOptions, |
| 107 |
const SkTileMode[2], |
| 108 |
const SkMatrix&, |
| 109 |
const SkRect*, |
| 110 |
const SkRect*) const = 0; |
| 111 |
|
| 112 |
virtual GrSurfaceOrigin origin() const = 0; |
| 113 |
|
| 114 |
protected: |
| 115 |
SkImage_GaneshBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID); |
| 116 |
sk_sp<SkImage> onMakeSubset(SkRecorder*, const SkIRect& subset, RequiredProperties) const final; |
| 117 |
sk_sp<SkImage> makeColorTypeAndColorSpace(SkRecorder*, |
| 118 |
SkColorType, |
| 119 |
sk_sp<SkColorSpace>, |
| 120 |
RequiredProperties) const final; |
| 121 |
virtual sk_sp<SkImage> onMakeColorTypeAndColorSpace(GrDirectContext*, |
| 122 |
SkColorType, |
| 123 |
sk_sp<SkColorSpace>) const = 0; |
| 124 |
|
| 125 |
sk_sp<GrImageContext> fContext; |
| 126 |
}; |
| 127 |
|
| 128 |
#endif |