OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkImage_Base.h" | 8 #include "SkImage_Gpu.h" |
9 #include "SkImagePriv.h" | |
10 #include "SkBitmap.h" | |
11 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
12 #include "SkSurface.h" | |
13 #include "GrContext.h" | 10 #include "GrContext.h" |
14 #include "GrTexture.h" | |
15 | 11 |
16 class SkImage_Gpu : public SkImage_Base { | 12 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces, |
17 public: | 13 SkSurface::Budgeted budgeted) |
18 SK_DECLARE_INST_COUNT(SkImage_Gpu) | |
19 | |
20 SkImage_Gpu(const SkBitmap&, int sampleCountForNewSurfaces); | |
21 | |
22 void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVER RIDE; | |
23 void onDrawRect(SkCanvas*, const SkRect* src, const SkRect& dst, | |
24 const SkPaint*) const SK_OVERRIDE; | |
25 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_ OVERRIDE; | |
26 GrTexture* onGetTexture() const SK_OVERRIDE; | |
27 bool getROPixels(SkBitmap*) const SK_OVERRIDE; | |
28 | |
29 GrTexture* getTexture() const { return fBitmap.getTexture(); } | |
30 | |
31 SkShader* onNewShader(SkShader::TileMode, | |
32 SkShader::TileMode, | |
33 const SkMatrix* localMatrix) const SK_OVERRIDE ; | |
34 | |
35 bool isOpaque() const SK_OVERRIDE; | |
36 | |
37 private: | |
38 SkBitmap fBitmap; | |
39 const int fSampleCountForNewSurfaces; // 0 if we don't know | |
40 | |
41 typedef SkImage_Base INHERITED; | |
42 }; | |
43 | |
44 /////////////////////////////////////////////////////////////////////////////// | |
45 | |
46 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCountForNewSurfaces) | |
47 : INHERITED(bitmap.width(), bitmap.height(), NULL) | 14 : INHERITED(bitmap.width(), bitmap.height(), NULL) |
48 , fBitmap(bitmap) | 15 , fBitmap(bitmap) |
49 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) | 16 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
17 , fBudgeted(budgeted) | |
50 { | 18 { |
51 SkASSERT(fBitmap.getTexture()); | 19 SkASSERT(fBitmap.getTexture()); |
52 } | 20 } |
53 | 21 |
54 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, | 22 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
55 SkShader::TileMode tileY, | 23 SkShader::TileMode tileY, |
56 const SkMatrix* localMatrix) const | 24 const SkMatrix* localMatrix) const |
57 { | 25 { |
58 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 26 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
59 } | 27 } |
(...skipping 20 matching lines...) Expand all Loading... | |
80 | 48 |
81 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 49 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
82 return fBitmap.copyTo(dst, kN32_SkColorType); | 50 return fBitmap.copyTo(dst, kN32_SkColorType); |
83 } | 51 } |
84 | 52 |
85 bool SkImage_Gpu::isOpaque() const { | 53 bool SkImage_Gpu::isOpaque() const { |
86 return fBitmap.isOpaque(); | 54 return fBitmap.isOpaque(); |
87 } | 55 } |
88 | 56 |
89 /////////////////////////////////////////////////////////////////////////////// | 57 /////////////////////////////////////////////////////////////////////////////// |
90 | 58 |
robertphillips
2015/01/23 15:09:28
overlength
bsalomon
2015/01/23 15:32:12
Done.
| |
91 SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForN ewSurfaces) { | 59 SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCountForN ewSurfaces, SkSurface::Budgeted budgeted) { |
92 if (NULL == bitmap.getTexture()) { | 60 if (NULL == bitmap.getTexture()) { |
93 return NULL; | 61 return NULL; |
94 } | 62 } |
95 return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces)); | 63 return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCountForNewSurfaces, budgeted) ); |
96 } | 64 } |
97 | 65 |
98 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 66 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
99 return ((SkImage_Gpu*)image)->getTexture(); | 67 return ((SkImage_Gpu*)image)->getTexture(); |
100 } | 68 } |
101 | 69 |
70 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | |
71 ((SkImage_Gpu*)image)->applyBudgetDecision(); | |
72 } | |
OLD | NEW |