1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkImage_Base.h" 9 #include "SkImagePriv.h" 10 #include "SkBitmap.h" 11 #include "SkCanvas.h" 12 #include "GrContext.h" 13 #include "GrTexture.h" 14 #include "SkGrPixelRef.h" 15 16 class SkImage_Gpu : public SkImage_Base { 17 public: 18 SK_DECLARE_INST_COUNT(SkImage_Gpu) 19 20 explicit SkImage_Gpu(const SkBitmap&); 21 virtual ~SkImage_Gpu(); 22 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE; 24 virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) SK_OVERRIDE; 25 virtual GrTexture* onGetTexture() SK_OVERRIDE; 26 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE { 27 // TODO 28 return false; 29 } 30 31 GrTexture* getTexture() { return fBitmap.getTexture(); } 32 33 private: 34 SkBitmap fBitmap; 35 36 typedef SkImage_Base INHERITED; 37 }; 38 39 /////////////////////////////////////////////////////////////////////////////// 40 41 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) 42 : INHERITED(bitmap.width(), bitmap.height()) 43 , fBitmap(bitmap) { 44 SkASSERT(NULL != fBitmap.getTexture()); 45 } 46 47 SkImage_Gpu::~SkImage_Gpu() { 48 } 49 50 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 51 const SkPaint* paint) { 52 canvas->drawBitmap(fBitmap, x, y, paint); 53 } 54 55 void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, 56 const SkPaint* paint) { 57 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 58 } 59 60 GrTexture* SkImage_Gpu::onGetTexture() { 61 return fBitmap.getTexture(); 62 } 63 64 /////////////////////////////////////////////////////////////////////////////// 65 66 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { 67 if (NULL == bitmap.getTexture()) { 68 return NULL; 69 } 70 71 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); 72 } 73 74 GrTexture* SkTextureImageGetTexture(SkImage* image) { 75 return ((SkImage_Gpu*)image)->getTexture(); 76 } 77