• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkImage_Base.h"
16 #include "SkImagePriv.h"
17 #include "SkSurface.h"
18 
19 class SkImage_Gpu : public SkImage_Base {
20 public:
21     /**
22      *  An "image" can be a subset/window into a larger texture, so we explicit take the
23      *  width and height.
24      */
25     SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkBudgeted);
26     ~SkImage_Gpu() override;
27 
applyBudgetDecision()28     void applyBudgetDecision() const {
29         GrTexture* tex = this->getTexture();
30         SkASSERT(tex);
31         if (SkBudgeted::kYes == fBudgeted) {
32             tex->resourcePriv().makeBudgeted();
33         } else {
34             tex->resourcePriv().makeUnbudgeted();
35         }
36     }
37 
38     bool getROPixels(SkBitmap*, CachingHint) const override;
39     GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override;
40     SkImage* onNewSubset(const SkIRect&) const override;
41 
peekTexture()42     GrTexture* peekTexture() const override { return fTexture; }
43     bool isOpaque() const override;
44     bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
45                       int srcX, int srcY, CachingHint) const override;
46 
onNewSurface(const SkImageInfo & info)47     SkSurface* onNewSurface(const SkImageInfo& info) const override {
48         return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kNo, info);
49     }
50 
51     bool asBitmapForImageFilters(SkBitmap* bitmap) const override;
52 
53 private:
54     SkAutoTUnref<GrTexture>     fTexture;
55     const SkAlphaType           fAlphaType;
56     const SkBudgeted            fBudgeted;
57     mutable SkAtomic<bool>      fAddedRasterVersionToCache;
58 
59 
60     typedef SkImage_Base INHERITED;
61 };
62 
63 #endif
64