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_Base.h" |
9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
14 #include "SkGrPixelRef.h" | 14 #include "SkGrPixelRef.h" |
15 | 15 |
16 class SkImage_Gpu : public SkImage_Base { | 16 class SkImage_Gpu : public SkImage_Base { |
17 public: | 17 public: |
18 SK_DECLARE_INST_COUNT(SkImage_Gpu) | 18 SK_DECLARE_INST_COUNT(SkImage_Gpu) |
19 | 19 |
20 explicit SkImage_Gpu(const SkBitmap&); | 20 explicit SkImage_Gpu(const SkBitmap&); |
21 virtual ~SkImage_Gpu(); | 21 virtual ~SkImage_Gpu(); |
22 | 22 |
23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OV
ERRIDE; | 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, const SkPaint*) SK_OVERRIDE; | 24 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& ds
t, |
25 virtual GrTexture* onGetTexture() SK_OVERRIDE; | 25 const SkPaint*) const SK_OVERRIDE; |
| 26 virtual GrTexture* onGetTexture() const SK_OVERRIDE; |
26 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 27 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
27 | 28 |
28 GrTexture* getTexture() { return fBitmap.getTexture(); } | 29 GrTexture* getTexture() const { return fBitmap.getTexture(); } |
29 | 30 |
30 virtual SkShader* onNewShader(SkShader::TileMode, | 31 virtual SkShader* onNewShader(SkShader::TileMode, |
31 SkShader::TileMode, | 32 SkShader::TileMode, |
32 const SkMatrix* localMatrix) const SK_OVERRIDE
; | 33 const SkMatrix* localMatrix) const SK_OVERRIDE
; |
33 private: | 34 private: |
34 SkBitmap fBitmap; | 35 SkBitmap fBitmap; |
35 | 36 |
36 typedef SkImage_Base INHERITED; | 37 typedef SkImage_Base INHERITED; |
37 }; | 38 }; |
38 | 39 |
39 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
40 | 41 |
41 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) | 42 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) |
42 : INHERITED(bitmap.width(), bitmap.height()) | 43 : INHERITED(bitmap.width(), bitmap.height()) |
43 , fBitmap(bitmap) { | 44 , fBitmap(bitmap) { |
44 SkASSERT(NULL != fBitmap.getTexture()); | 45 SkASSERT(NULL != fBitmap.getTexture()); |
45 } | 46 } |
46 | 47 |
47 SkImage_Gpu::~SkImage_Gpu() { | 48 SkImage_Gpu::~SkImage_Gpu() { |
48 } | 49 } |
49 | 50 |
50 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, | 51 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
51 SkShader::TileMode tileY, | 52 SkShader::TileMode tileY, |
52 const SkMatrix* localMatrix) const | 53 const SkMatrix* localMatrix) const |
53 { | 54 { |
54 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 55 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
55 } | 56 } |
56 | 57 |
57 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 58 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint
* paint) const { |
58 const SkPaint* paint) { | |
59 canvas->drawBitmap(fBitmap, x, y, paint); | 59 canvas->drawBitmap(fBitmap, x, y, paint); |
60 } | 60 } |
61 | 61 |
62 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const Sk
Rect& dst, | 62 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const Sk
Rect& dst, |
63 const SkPaint* paint) { | 63 const SkPaint* paint) const { |
64 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | 64 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
65 } | 65 } |
66 | 66 |
67 GrTexture* SkImage_Gpu::onGetTexture() { | 67 GrTexture* SkImage_Gpu::onGetTexture() const { |
68 return fBitmap.getTexture(); | 68 return fBitmap.getTexture(); |
69 } | 69 } |
70 | 70 |
71 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 71 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
72 return fBitmap.copyTo(dst, kN32_SkColorType); | 72 return fBitmap.copyTo(dst, kN32_SkColorType); |
73 } | 73 } |
74 | 74 |
75 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
76 | 76 |
77 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { | 77 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
78 if (NULL == bitmap.getTexture()) { | 78 if (NULL == bitmap.getTexture()) { |
79 return NULL; | 79 return NULL; |
80 } | 80 } |
81 | 81 |
82 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); | 82 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); |
83 } | 83 } |
84 | 84 |
85 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 85 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
86 return ((SkImage_Gpu*)image)->getTexture(); | 86 return ((SkImage_Gpu*)image)->getTexture(); |
87 } | 87 } |
OLD | NEW |