bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 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 "GrTexture.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 12 | #include "GrGpuResourcePriv.h" |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 13 | #include "SkBitmap.h" |
| 14 | #include "SkImage_Base.h" |
| 15 | #include "SkImagePriv.h" |
| 16 | #include "SkSurface.h" |
| 17 | |
| 18 | class SkImage_Gpu : public SkImage_Base { |
| 19 | public: |
| 20 | SK_DECLARE_INST_COUNT(SkImage_Gpu) |
| 21 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 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, SkAlphaType, GrTexture*, int sampleCountForNewSurfaces, |
| 27 | SkSurface::Budgeted); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 28 | |
| 29 | void applyBudgetDecision() const { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 30 | GrTexture* tex = this->getTexture(); |
| 31 | SkASSERT(tex); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 32 | if (fBudgeted) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 33 | tex->resourcePriv().makeBudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 34 | } else { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 35 | tex->resourcePriv().makeUnbudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 39 | bool getROPixels(SkBitmap*) const override; |
bsalomon | 5581236 | 2015-06-10 08:49:28 -0700 | [diff] [blame] | 40 | GrTexture* getTexture() const override { return fTexture; } |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 41 | SkShader* onNewShader(SkShader::TileMode, |
| 42 | SkShader::TileMode, |
| 43 | const SkMatrix* localMatrix) const override; |
| 44 | bool isOpaque() const override; |
| 45 | SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const override; |
| 46 | bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes, |
| 47 | int srcX, int srcY) const override; |
| 48 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 49 | private: |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 50 | SkAutoTUnref<GrTexture> fTexture; |
| 51 | const int fSampleCountForNewSurfaces; // 0 if we don't know |
| 52 | const SkAlphaType fAlphaType; |
| 53 | SkSurface::Budgeted fBudgeted; |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 54 | |
| 55 | typedef SkImage_Base INHERITED; |
| 56 | }; |
| 57 | |
| 58 | #endif |