michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkImage_Base.h" michael@0: #include "SkImagePriv.h" michael@0: #include "SkBitmap.h" michael@0: #include "SkCanvas.h" michael@0: #include "GrContext.h" michael@0: #include "GrTexture.h" michael@0: #include "SkGrPixelRef.h" michael@0: michael@0: class SkImage_Gpu : public SkImage_Base { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkImage_Gpu) michael@0: michael@0: explicit SkImage_Gpu(const SkBitmap&); michael@0: virtual ~SkImage_Gpu(); michael@0: michael@0: virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE; michael@0: virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) SK_OVERRIDE; michael@0: virtual GrTexture* onGetTexture() SK_OVERRIDE; michael@0: virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; michael@0: michael@0: GrTexture* getTexture() { return fBitmap.getTexture(); } michael@0: michael@0: private: michael@0: SkBitmap fBitmap; michael@0: michael@0: typedef SkImage_Base INHERITED; michael@0: }; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) michael@0: : INHERITED(bitmap.width(), bitmap.height()) michael@0: , fBitmap(bitmap) { michael@0: SkASSERT(NULL != fBitmap.getTexture()); michael@0: } michael@0: michael@0: SkImage_Gpu::~SkImage_Gpu() { michael@0: } michael@0: michael@0: void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, michael@0: const SkPaint* paint) { michael@0: canvas->drawBitmap(fBitmap, x, y, paint); michael@0: } michael@0: michael@0: void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, michael@0: const SkPaint* paint) { michael@0: canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); michael@0: } michael@0: michael@0: GrTexture* SkImage_Gpu::onGetTexture() { michael@0: return fBitmap.getTexture(); michael@0: } michael@0: michael@0: bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { michael@0: return fBitmap.copyTo(dst, kPMColor_SkColorType); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { michael@0: if (NULL == bitmap.getTexture()) { michael@0: return NULL; michael@0: } michael@0: michael@0: return SkNEW_ARGS(SkImage_Gpu, (bitmap)); michael@0: } michael@0: michael@0: GrTexture* SkTextureImageGetTexture(SkImage* image) { michael@0: return ((SkImage_Gpu*)image)->getTexture(); michael@0: }