blob: d168fb6853428898f6b3ccef878e994af89b4a52 [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
reed6f1216a2015-08-04 08:10:13 -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 */
reed80c772b2015-07-30 18:58:23 -070025 SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*,
26 int sampleCountForNewSurfaces, SkSurface::Budgeted);
reed6f1216a2015-08-04 08:10:13 -070027 ~SkImage_Gpu() override;
bsalomoneaaaf0b2015-01-23 08:08:04 -080028
29 void applyBudgetDecision() const {
reed8b26b992015-05-07 15:36:17 -070030 GrTexture* tex = this->getTexture();
31 SkASSERT(tex);
bsalomoneaaaf0b2015-01-23 08:08:04 -080032 if (fBudgeted) {
reed8b26b992015-05-07 15:36:17 -070033 tex->resourcePriv().makeBudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -080034 } else {
reed8b26b992015-05-07 15:36:17 -070035 tex->resourcePriv().makeUnbudgeted();
bsalomoneaaaf0b2015-01-23 08:08:04 -080036 }
37 }
38
reed8b26b992015-05-07 15:36:17 -070039 bool getROPixels(SkBitmap*) const override;
reed85d91782015-09-10 14:33:38 -070040 GrTexture* asTextureRef(GrContext* ctx, SkImageUsageType usage) const override;
41
42 GrTexture* peekTexture() const override { return fTexture; }
reed8b26b992015-05-07 15:36:17 -070043 SkShader* onNewShader(SkShader::TileMode,
44 SkShader::TileMode,
45 const SkMatrix* localMatrix) const override;
46 bool isOpaque() const override;
47 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const override;
48 bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
49 int srcX, int srcY) const override;
50
bsalomoneaaaf0b2015-01-23 08:08:04 -080051private:
reed6f1216a2015-08-04 08:10:13 -070052 SkAutoTUnref<GrTexture> fTexture;
53 const int fSampleCountForNewSurfaces; // 0 if we don't know
54 const SkAlphaType fAlphaType;
55 const SkSurface::Budgeted fBudgeted;
56 mutable SkAtomic<bool> fAddedRasterVersionToCache;
57
bsalomoneaaaf0b2015-01-23 08:08:04 -080058
59 typedef SkImage_Base INHERITED;
60};
61
62#endif