Plumb dst color space in many places, rather than "mode"
[platform/upstream/libSkiaSharp.git] / src / image / SkImage_Gpu.h
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 "SkAtomics.h"
12 #include "GrTexture.h"
13 #include "GrGpuResourcePriv.h"
14 #include "SkBitmap.h"
15 #include "SkGr.h"
16 #include "SkImage_Base.h"
17 #include "SkImagePriv.h"
18 #include "SkSurface.h"
19
20 class SkImage_Gpu : public SkImage_Base {
21 public:
22     /**
23      *  An "image" can be a subset/window into a larger texture, so we explicit take the
24      *  width and height.
25      */
26     SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, sk_sp<GrTexture>, sk_sp<SkColorSpace>,
27                 SkBudgeted);
28     ~SkImage_Gpu() override;
29
30     SkImageInfo onImageInfo() const override;
31     SkAlphaType onAlphaType() const override { return fAlphaType; }
32
33     void applyBudgetDecision() const {
34         if (SkBudgeted::kYes == fBudgeted) {
35             fTexture->resourcePriv().makeBudgeted();
36         } else {
37             fTexture->resourcePriv().makeUnbudgeted();
38         }
39     }
40
41     bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
42     GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params, SkColorSpace*,
43                             sk_sp<SkColorSpace>*) const override;
44     sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
45
46     GrTexture* peekTexture() const override { return fTexture.get(); }
47     sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override {
48         *uniqueID = this->uniqueID();
49         return fTexture;
50     }
51     bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
52                       int srcX, int srcY, CachingHint) const override;
53
54 private:
55     sk_sp<GrTexture>       fTexture;
56     const SkAlphaType      fAlphaType;
57     const SkBudgeted       fBudgeted;
58     sk_sp<SkColorSpace>    fColorSpace;
59     mutable SkAtomic<bool> fAddedRasterVersionToCache;
60
61
62     typedef SkImage_Base INHERITED;
63 };
64
65 #endif