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