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 "GrClip.h"
12 #include "GrContext.h"
13 #include "GrGpuResourcePriv.h"
14 #include "GrSurfaceProxyPriv.h"
15 #include "GrTexture.h"
16 #include "SkAtomics.h"
17 #include "SkBitmap.h"
18 #include "SkGr.h"
19 #include "SkImagePriv.h"
20 #include "SkImage_Base.h"
21 #include "SkSurface.h"
22 
23 class SkImage_Gpu : public SkImage_Base {
24 public:
25     SkImage_Gpu(GrContext*, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
26                 sk_sp<SkColorSpace>, SkBudgeted);
27     ~SkImage_Gpu() override;
28 
29     SkImageInfo onImageInfo() const override;
onAlphaType()30     SkAlphaType onAlphaType() const override { return fAlphaType; }
31 
32     bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
33     sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
34 
peekProxy()35     GrTextureProxy* peekProxy() const override {
36         return fProxy.get();
37     }
peekTexture()38     GrTexture* peekTexture() const override {
39         return fProxy->instantiate(fContext->resourceProvider());
40     }
asTextureProxyRef()41     sk_sp<GrTextureProxy> asTextureProxyRef() const override {
42         return fProxy;
43     }
44     sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
45                                             sk_sp<SkColorSpace>*,
46                                             SkScalar scaleAdjust[2]) const override;
47 
refPinnedTextureProxy(uint32_t * uniqueID)48     sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const override {
49         *uniqueID = this->uniqueID();
50         return fProxy;
51     }
52     GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
53                                        GrSurfaceOrigin* origin) const override;
54     GrTexture* onGetTexture() const override;
55 
56     bool onReadYUV8Planes(const SkISize sizes[3], void* const planes[3],
57                           const size_t rowBytes[3], SkYUVColorSpace colorSpace) const override;
58 
59     bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
60                       int srcX, int srcY, CachingHint) const override;
61 
context()62     GrContext* context() { return fContext; }
refColorSpace()63     sk_sp<SkColorSpace> refColorSpace() { return fColorSpace; }
64 
65     sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
66 
67 private:
68     GrContext*             fContext;
69     sk_sp<GrTextureProxy>  fProxy;
70     const SkAlphaType      fAlphaType;
71     const SkBudgeted       fBudgeted;
72     sk_sp<SkColorSpace>    fColorSpace;
73     mutable SkAtomic<bool> fAddedRasterVersionToCache;
74 
75 
76     typedef SkImage_Base INHERITED;
77 };
78 
79 #endif
80