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_BitmapBase.h" |
9 | |
10 #include "SkBitmap.h" | |
9 #include "SkImagePriv.h" | 11 #include "SkImagePriv.h" |
10 #include "SkBitmap.h" | |
11 #include "SkCanvas.h" | |
12 #include "GrContext.h" | |
13 #include "GrTexture.h" | 12 #include "GrTexture.h" |
14 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
15 | 14 |
16 class SkImage_Gpu : public SkImage_Base { | 15 class SkImage_Gpu : public SkImage_BitmapBase { |
bsalomon
2014/09/18 14:41:51
Given that we want to remove support for texture-b
Rémi Piotaix
2014/09/18 18:27:15
Hum, for now this two classes are backed by a SkBi
bsalomon
2014/09/18 18:46:28
It wasn't obvious at all from the code, but the di
| |
17 public: | 16 public: |
18 SK_DECLARE_INST_COUNT(SkImage_Gpu) | 17 SK_DECLARE_INST_COUNT(SkImage_Gpu) |
19 | 18 |
20 explicit SkImage_Gpu(const SkBitmap&); | 19 explicit SkImage_Gpu(const SkBitmap&); |
21 virtual ~SkImage_Gpu(); | 20 virtual ~SkImage_Gpu(); |
22 | 21 |
23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVERRIDE; | |
24 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& ds t, | |
25 const SkPaint*) const SK_OVERRIDE; | |
26 virtual GrTexture* onGetTexture() const SK_OVERRIDE; | 22 virtual GrTexture* onGetTexture() const SK_OVERRIDE; |
27 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 23 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
28 | 24 |
29 GrTexture* getTexture() const { return fBitmap.getTexture(); } | 25 private: |
26 // SkBitmap fBitmap; | |
reed1
2014/09/18 13:07:16
remove?
Rémi Piotaix
2014/09/18 18:27:15
Done.
| |
30 | 27 |
31 virtual SkShader* onNewShader(SkShader::TileMode, | 28 typedef SkImage_BitmapBase INHERITED; |
32 SkShader::TileMode, | |
33 const SkMatrix* localMatrix) const SK_OVERRIDE ; | |
34 | |
35 virtual bool isOpaque() const SK_OVERRIDE; | |
36 | |
37 private: | |
38 SkBitmap fBitmap; | |
39 | |
40 typedef SkImage_Base INHERITED; | |
41 }; | 29 }; |
42 | 30 |
43 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
44 | 32 |
45 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) | 33 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) |
46 : INHERITED(bitmap.width(), bitmap.height()) | 34 : INHERITED(bitmap) { |
47 , fBitmap(bitmap) { | |
48 SkASSERT(fBitmap.getTexture()); | 35 SkASSERT(fBitmap.getTexture()); |
49 } | 36 } |
50 | 37 |
51 SkImage_Gpu::~SkImage_Gpu() { | 38 SkImage_Gpu::~SkImage_Gpu() { |
52 } | 39 } |
53 | 40 |
54 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, | |
55 SkShader::TileMode tileY, | |
56 const SkMatrix* localMatrix) const | |
57 { | |
58 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | |
59 } | |
60 | |
61 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint * paint) const { | |
62 canvas->drawBitmap(fBitmap, x, y, paint); | |
63 } | |
64 | |
65 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const Sk Rect& dst, | |
66 const SkPaint* paint) const { | |
67 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | |
68 } | |
69 | |
70 GrTexture* SkImage_Gpu::onGetTexture() const { | 41 GrTexture* SkImage_Gpu::onGetTexture() const { |
71 return fBitmap.getTexture(); | 42 return this->getBitmap().getTexture(); |
72 } | 43 } |
73 | 44 |
74 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 45 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
75 return fBitmap.copyTo(dst, kN32_SkColorType); | 46 return this->getBitmap().copyTo(dst, kN32_SkColorType); |
76 } | 47 } |
77 | 48 |
78 bool SkImage_Gpu::isOpaque() const { | |
79 return fBitmap.isOpaque(); | |
80 } | |
81 | 49 |
82 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
83 | 51 |
84 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { | 52 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
85 if (NULL == bitmap.getTexture()) { | 53 if (NULL == bitmap.getTexture()) { |
86 return NULL; | 54 return NULL; |
87 } | 55 } |
88 | 56 |
89 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); | 57 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); |
90 } | 58 } |
91 | 59 |
92 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 60 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
reed1
2014/09/18 13:07:16
Why do we have this helper?
Rémi Piotaix
2014/09/18 18:27:15
Uh... dunno.
It is used in SkSurface_Gpu when maki
| |
93 return ((SkImage_Gpu*)image)->getTexture(); | 61 return image->getTexture(); |
94 } | 62 } |
OLD | NEW |