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 | |
herb | b906daf | 2015-09-29 09:37:59 -0700 | [diff] [blame] | 11 | #include "SkAtomics.h" |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 12 | #include "GrTexture.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 13 | #include "GrGpuResourcePriv.h" |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 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: |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 21 | /** |
| 22 | * An "image" can be a subset/window into a larger texture, so we explicit take the |
| 23 | * width and height. |
| 24 | */ |
bsalomon | 57599fe | 2016-02-25 06:33:26 -0800 | [diff] [blame] | 25 | SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkBudgeted); |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 26 | ~SkImage_Gpu() override; |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 27 | |
| 28 | void applyBudgetDecision() const { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 29 | GrTexture* tex = this->getTexture(); |
| 30 | SkASSERT(tex); |
bsalomon | 57599fe | 2016-02-25 06:33:26 -0800 | [diff] [blame] | 31 | if (SkBudgeted::kYes == fBudgeted) { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 32 | tex->resourcePriv().makeBudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 33 | } else { |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 34 | tex->resourcePriv().makeUnbudgeted(); |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 38 | bool getROPixels(SkBitmap*, CachingHint) const override; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 39 | GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override; |
reed | 7b6945b | 2015-09-24 00:50:58 -0700 | [diff] [blame] | 40 | SkImage* onNewSubset(const SkIRect&) const override; |
reed | 85d9178 | 2015-09-10 14:33:38 -0700 | [diff] [blame] | 41 | |
| 42 | GrTexture* peekTexture() const override { return fTexture; } |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 43 | bool isOpaque() const override; |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 44 | bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes, |
reed | 0955303 | 2015-11-23 12:32:16 -0800 | [diff] [blame] | 45 | int srcX, int srcY, CachingHint) const override; |
reed | 88d064d | 2015-10-12 11:30:02 -0700 | [diff] [blame] | 46 | |
| 47 | SkSurface* onNewSurface(const SkImageInfo& info) const override { |
bsalomon | 57599fe | 2016-02-25 06:33:26 -0800 | [diff] [blame] | 48 | return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kNo, info); |
reed | 88d064d | 2015-10-12 11:30:02 -0700 | [diff] [blame] | 49 | } |
reed | 8b26b99 | 2015-05-07 15:36:17 -0700 | [diff] [blame] | 50 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 51 | bool asBitmapForImageFilters(SkBitmap* bitmap) const override; |
| 52 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 53 | private: |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 54 | SkAutoTUnref<GrTexture> fTexture; |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 55 | const SkAlphaType fAlphaType; |
bsalomon | 57599fe | 2016-02-25 06:33:26 -0800 | [diff] [blame] | 56 | const SkBudgeted fBudgeted; |
reed | 6f1216a | 2015-08-04 08:10:13 -0700 | [diff] [blame] | 57 | mutable SkAtomic<bool> fAddedRasterVersionToCache; |
| 58 | |
bsalomon | eaaaf0b | 2015-01-23 08:08:04 -0800 | [diff] [blame] | 59 | |
| 60 | typedef SkImage_Base INHERITED; |
| 61 | }; |
| 62 | |
| 63 | #endif |