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 SkImage_Gpu(GrTexture*); | 20 SkImage_Gpu(GrTexture*); |
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*) SK_OV
ERRIDE; |
| 24 virtual GrTexture* onGetTexture() SK_OVERRIDE; |
24 | 25 |
25 GrTexture* getTexture() { return fTexture; } | 26 GrTexture* getTexture() { return fTexture; } |
26 | 27 |
27 void setTexture(GrTexture* texture); | 28 void setTexture(GrTexture* texture); |
28 | 29 |
29 private: | 30 private: |
30 GrTexture* fTexture; | 31 GrTexture* fTexture; |
31 SkBitmap fBitmap; | 32 SkBitmap fBitmap; |
32 | 33 |
33 typedef SkImage_Base INHERITED; | 34 typedef SkImage_Base INHERITED; |
(...skipping 15 matching lines...) Expand all Loading... |
49 | 50 |
50 SkImage_Gpu::~SkImage_Gpu() { | 51 SkImage_Gpu::~SkImage_Gpu() { |
51 SkSafeUnref(fTexture); | 52 SkSafeUnref(fTexture); |
52 } | 53 } |
53 | 54 |
54 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 55 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
55 const SkPaint* paint) { | 56 const SkPaint* paint) { |
56 canvas->drawBitmap(fBitmap, x, y, paint); | 57 canvas->drawBitmap(fBitmap, x, y, paint); |
57 } | 58 } |
58 | 59 |
| 60 GrTexture* SkImage_Gpu::onGetTexture() { |
| 61 return fTexture; |
| 62 } |
| 63 |
59 void SkImage_Gpu::setTexture(GrTexture* texture) { | 64 void SkImage_Gpu::setTexture(GrTexture* texture) { |
60 | 65 |
61 if (texture == fTexture) { | 66 if (texture == fTexture) { |
62 return; | 67 return; |
63 } | 68 } |
64 | 69 |
65 SkRefCnt_SafeAssign(fTexture, texture); | 70 SkRefCnt_SafeAssign(fTexture, texture); |
66 fBitmap.setPixelRef(new SkGrPixelRef(texture))->unref(); | 71 fBitmap.setPixelRef(new SkGrPixelRef(texture))->unref(); |
67 } | 72 } |
68 | 73 |
69 /////////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////////// |
70 | 75 |
71 SkImage* SkImage::NewTexture(GrTexture* texture) { | 76 SkImage* SkImage::NewTexture(GrTexture* texture) { |
72 if (NULL == texture) { | 77 if (NULL == texture) { |
73 return NULL; | 78 return NULL; |
74 } | 79 } |
75 | 80 |
76 return SkNEW_ARGS(SkImage_Gpu, (texture)); | 81 return SkNEW_ARGS(SkImage_Gpu, (texture)); |
77 } | 82 } |
78 | 83 |
79 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 84 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
80 return ((SkImage_Gpu*)image)->getTexture(); | 85 return ((SkImage_Gpu*)image)->getTexture(); |
81 } | 86 } |
82 | 87 |
83 void SkTextureImageSetTexture(SkImage* image, GrTexture* texture) { | 88 void SkTextureImageSetTexture(SkImage* image, GrTexture* texture) { |
84 ((SkImage_Gpu*)image)->setTexture(texture); | 89 ((SkImage_Gpu*)image)->setTexture(texture); |
85 } | 90 } |
OLD | NEW |