1/*
2 * Copyright 2015 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_Gpu_DEFINED
9#define SkImage_Gpu_DEFINED
10
11#include "src/core/SkImagePriv.h"
12#include "src/gpu/GrGpuResourcePriv.h"
13#include "src/gpu/GrSurfaceProxyPriv.h"
14#include "src/gpu/GrSurfaceProxyView.h"
15#include "src/gpu/SkGr.h"
16#include "src/image/SkImage_GpuBase.h"
17
18class GrContext;
19class GrTexture;
20
21class SkBitmap;
22struct SkYUVAIndex;
23
24class SkImage_Gpu : public SkImage_GpuBase {
25public:
26 SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, GrSurfaceProxyView, SkColorType, SkAlphaType,
27 sk_sp<SkColorSpace>);
28 ~SkImage_Gpu() override;
29
30 GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) override;
31
32 GrTextureProxy* peekProxy() const override {
33 return fView.asTextureProxy();
34 }
35
36 const GrSurfaceProxyView* view(GrRecordingContext* context) const override {
37 if (!fView.proxy()) {
38 return nullptr;
39 }
40 return &fView;
41 }
42
43 bool onIsTextureBacked() const override {
44 SkASSERT(fView.proxy());
45 return true;
46 }
47
48 sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
49 GrDirectContext*) const final;
50
51 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
52
53 void onAsyncRescaleAndReadPixels(const SkImageInfo&,
54 const SkIRect& srcRect,
55 RescaleGamma,
56 SkFilterQuality,
57 ReadPixelsCallback,
58 ReadPixelsContext) override;
59
60 void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace,
61 sk_sp<SkColorSpace>,
62 const SkIRect& srcRect,
63 const SkISize& dstSize,
64 RescaleGamma,
65 SkFilterQuality,
66 ReadPixelsCallback,
67 ReadPixelsContext) override;
68
69 /**
70 * This is the implementation of SkDeferredDisplayListRecorder::makePromiseImage.
71 */
72 static sk_sp<SkImage> MakePromiseTexture(GrRecordingContext*,
73 const GrBackendFormat& backendFormat,
74 int width,
75 int height,
76 GrMipmapped mipMapped,
77 GrSurfaceOrigin origin,
78 SkColorType colorType,
79 SkAlphaType alphaType,
80 sk_sp<SkColorSpace> colorSpace,
81 PromiseImageTextureFulfillProc textureFulfillProc,
82 PromiseImageTextureReleaseProc textureReleaseProc,
83 PromiseImageTextureDoneProc textureDoneProc,
84 PromiseImageTextureContext textureContext,
85 PromiseImageApiVersion);
86
87 static sk_sp<SkImage> ConvertYUVATexturesToRGB(GrRecordingContext*, SkYUVColorSpace,
88 const GrBackendTexture [],
89 const SkYUVAIndex [4],
90 SkISize, GrSurfaceOrigin,
91 GrRenderTargetContext*);
92
93private:
94 GrSurfaceProxyView fView;
95
96 typedef SkImage_GpuBase INHERITED;
97};
98
99#endif
100