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 "include/gpu/GrContext.h"
12#include "src/core/SkImagePriv.h"
13#include "src/gpu/GrGpuResourcePriv.h"
14#include "src/gpu/GrSurfaceProxyPriv.h"
15#include "src/gpu/GrSurfaceProxyView.h"
16#include "src/gpu/SkGr.h"
17#include "src/image/SkImage_GpuBase.h"
18
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(GrContext*, 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(GrRecordingContext*,
49 SkColorType, sk_sp<SkColorSpace>) const final;
50
51 sk_sp<SkImage> onReinterpretColorSpace(sk_sp<SkColorSpace>) const final;
52
53 /**
54 * This is the implementation of SkDeferredDisplayListRecorder::makePromiseImage.
55 */
56 static sk_sp<SkImage> MakePromiseTexture(GrContext* context,
57 const GrBackendFormat& backendFormat,
58 int width,
59 int height,
60 GrMipMapped mipMapped,
61 GrSurfaceOrigin origin,
62 SkColorType colorType,
63 SkAlphaType alphaType,
64 sk_sp<SkColorSpace> colorSpace,
65 PromiseImageTextureFulfillProc textureFulfillProc,
66 PromiseImageTextureReleaseProc textureReleaseProc,
67 PromiseImageTextureDoneProc textureDoneProc,
68 PromiseImageTextureContext textureContext,
69 PromiseImageApiVersion);
70
71 static sk_sp<SkImage> ConvertYUVATexturesToRGB(GrContext*, SkYUVColorSpace yuvColorSpace,
72 const GrBackendTexture yuvaTextures[],
73 const SkYUVAIndex yuvaIndices[4],
74 SkISize imageSize, GrSurfaceOrigin imageOrigin,
75 GrRenderTargetContext*);
76
77private:
78 GrSurfaceProxyView fView;
79
80 typedef SkImage_GpuBase INHERITED;
81};
82
83#endif
84