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 { |
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(); } | |
30 | |
31 virtual SkShader* onNewShader(SkShader::TileMode, | |
32 SkShader::TileMode, | |
33 const SkMatrix* localMatrix) const SK_OVERRIDE
; | |
34 | |
35 virtual bool isOpaque() const SK_OVERRIDE; | |
36 | |
37 private: | 25 private: |
38 SkBitmap fBitmap; | 26 typedef SkImage_BitmapBase INHERITED; |
39 | |
40 typedef SkImage_Base INHERITED; | |
41 }; | 27 }; |
42 | 28 |
43 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
44 | 30 |
45 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) | 31 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) |
46 : INHERITED(bitmap.width(), bitmap.height()) | 32 : INHERITED(bitmap) { |
47 , fBitmap(bitmap) { | |
48 SkASSERT(fBitmap.getTexture()); | 33 SkASSERT(fBitmap.getTexture()); |
49 } | 34 } |
50 | 35 |
51 SkImage_Gpu::~SkImage_Gpu() { | 36 SkImage_Gpu::~SkImage_Gpu() { |
52 } | 37 } |
53 | 38 |
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 { | 39 GrTexture* SkImage_Gpu::onGetTexture() const { |
71 return fBitmap.getTexture(); | 40 return this->getBitmap().getTexture(); |
72 } | 41 } |
73 | 42 |
74 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 43 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
75 return fBitmap.copyTo(dst, kN32_SkColorType); | 44 return this->getBitmap().copyTo(dst, kN32_SkColorType); |
76 } | 45 } |
77 | 46 |
78 bool SkImage_Gpu::isOpaque() const { | |
79 return fBitmap.isOpaque(); | |
80 } | |
81 | 47 |
82 /////////////////////////////////////////////////////////////////////////////// | 48 /////////////////////////////////////////////////////////////////////////////// |
83 | 49 |
84 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { | 50 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
85 if (NULL == bitmap.getTexture()) { | 51 if (NULL == bitmap.getTexture()) { |
86 return NULL; | 52 return NULL; |
87 } | 53 } |
88 | 54 |
89 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); | 55 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); |
90 } | 56 } |
91 | 57 |
92 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 58 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
93 return ((SkImage_Gpu*)image)->getTexture(); | 59 return image->getTexture(); |
94 } | 60 } |
OLD | NEW |