blob: 4c7ebd6f7185aef5c4d36c5157ba18982c48943f [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
11#include "GrTexture.h"
bsalomon3582d3e2015-02-13 14:20:05 -080012#include "GrGpuResourcePriv.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080013#include "SkBitmap.h"
14#include "SkImage_Base.h"
15#include "SkImagePriv.h"
16#include "SkSurface.h"
17
18class SkImage_Gpu : public SkImage_Base {
19public:
mtklein2766c002015-06-26 11:45:03 -070020
bsalomoneaaaf0b2015-01-23 08:08:04 -080021
reed8b26b992015-05-07 15:36:17 -070022 /**
23 * An "image" can be a subset/window into a larger texture, so we explicit take the
24 * width and height.
25 */
reed80c772b2015-07-30 18:58:23 -070026 SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*,
27 int sampleCountForNewSurfaces, SkSurface::Budgeted);
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;
bsalomon55812362015-06-10 08:49:28 -070040 GrTexture* getTexture() const override { return fTexture; }
reed8b26b992015-05-07 15:36:17 -070041 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
bsalomoneaaaf0b2015-01-23 08:08:04 -080049private:
reed8b26b992015-05-07 15:36:17 -070050 SkAutoTUnref<GrTexture> fTexture;
51 const int fSampleCountForNewSurfaces; // 0 if we don't know
52 const SkAlphaType fAlphaType;
53 SkSurface::Budgeted fBudgeted;
bsalomoneaaaf0b2015-01-23 08:08:04 -080054
55 typedef SkImage_Base INHERITED;
56};
57
58#endif