blob: a36c8ebc135ca403db2e845864f9a375ad92cb54 [file] [log] [blame]
bsalomoneaaaf0b2015-01-23 08:08:04 -08001/*
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
herbb906daf2015-09-29 09:37:59 -070011#include "SkAtomics.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080012#include "GrTexture.h"
bsalomon3582d3e2015-02-13 14:20:05 -080013#include "GrGpuResourcePriv.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080014#include "SkBitmap.h"
15#include "SkImage_Base.h"
16#include "SkImagePriv.h"
17#include "SkSurface.h"
18
19class SkImage_Gpu : public SkImage_Base {
20public:
reed8b26b992015-05-07 15:36:17 -070021 /**
22 * An "image" can be a subset/window into a larger texture, so we explicit take the
23 * width and height.
24 */
bsalomonbd500f02016-02-25 06:52:12 -080025 SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkSurface::Budgeted);
reed6f1216a2015-08-04 08:10:13 -070026 ~SkImage_Gpu() override;
bsalomoneaaaf0b2015-01-23 08:08:04 -080027
28 void applyBudgetDecision() const {
reed8b26b992015-05-07 15:36:17 -070029 GrTexture* tex = this->getTexture();
30 SkASSERT(tex);
bsalomonbd500f02016-02-25 06:52:12 -080031 if (fBudgeted) {
reed8b26b992015-05-07 15:36:17 -070032 tex->resourcePriv().makeBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -080033 } else {
reed8b26b992015-05-07 15:36:17 -070034 tex->resourcePriv().makeUnbudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -080035 }
36 }
37
reed09553032015-11-23 12:32:16 -080038 bool getROPixels(SkBitmap*, CachingHint) const override;
bsalomonafa95e22015-10-12 10:39:46 -070039 GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override;
reed7b6945b2015-09-24 00:50:58 -070040 SkImage* onNewSubset(const SkIRect&) const override;
reed85d91782015-09-10 14:33:38 -070041
42 GrTexture* peekTexture() const override { return fTexture; }
reed8b26b992015-05-07 15:36:17 -070043 bool isOpaque() const override;
reed8b26b992015-05-07 15:36:17 -070044 bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
reed09553032015-11-23 12:32:16 -080045 int srcX, int srcY, CachingHint) const override;
reed88d064d2015-10-12 11:30:02 -070046
47 SkSurface* onNewSurface(const SkImageInfo& info) const override {
bsalomonbd500f02016-02-25 06:52:12 -080048 return SkSurface::NewRenderTarget(fTexture->getContext(), SkSurface::kNo_Budgeted, info);
reed88d064d2015-10-12 11:30:02 -070049 }
reed8b26b992015-05-07 15:36:17 -070050
reed262a71b2015-12-05 13:07:27 -080051 bool asBitmapForImageFilters(SkBitmap* bitmap) const override;
52
bsalomoneaaaf0b2015-01-23 08:08:04 -080053private:
reed6f1216a2015-08-04 08:10:13 -070054 SkAutoTUnref<GrTexture> fTexture;
reed6f1216a2015-08-04 08:10:13 -070055 const SkAlphaType fAlphaType;
bsalomonbd500f02016-02-25 06:52:12 -080056 const SkSurface::Budgeted fBudgeted;
reed6f1216a2015-08-04 08:10:13 -070057 mutable SkAtomic<bool> fAddedRasterVersionToCache;
58
bsalomoneaaaf0b2015-01-23 08:08:04 -080059
60 typedef SkImage_Base INHERITED;
61};
62
63#endif