2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkImage_Gpu_DEFINED
9 #define SkImage_Gpu_DEFINED
11 #include "SkAtomics.h"
12 #include "GrTexture.h"
13 #include "GrGpuResourcePriv.h"
16 #include "SkImage_Base.h"
17 #include "SkImagePriv.h"
18 #include "SkSurface.h"
20 class SkImage_Gpu : public SkImage_Base {
23 * An "image" can be a subset/window into a larger texture, so we explicit take the
26 SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, sk_sp<GrTexture>, sk_sp<SkColorSpace>,
28 ~SkImage_Gpu() override;
30 SkImageInfo onImageInfo() const override;
31 SkAlphaType onAlphaType() const override { return fAlphaType; }
33 void applyBudgetDecision() const {
34 if (SkBudgeted::kYes == fBudgeted) {
35 fTexture->resourcePriv().makeBudgeted();
37 fTexture->resourcePriv().makeUnbudgeted();
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;
46 GrTexture* peekTexture() const override { return fTexture.get(); }
47 sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override {
48 *uniqueID = this->uniqueID();
51 bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
52 int srcX, int srcY, CachingHint) const override;
55 sk_sp<GrTexture> fTexture;
56 const SkAlphaType fAlphaType;
57 const SkBudgeted fBudgeted;
58 sk_sp<SkColorSpace> fColorSpace;
59 mutable SkAtomic<bool> fAddedRasterVersionToCache;
62 typedef SkImage_Base INHERITED;