Index: src/image/SkImage_Gpu.cpp |
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp |
index de49d1e33973f6f3e3dbd3f33e291fe4213ae931..7a8da36d28338b9447649ad61feab8dbc1b3e94a 100644 |
--- a/src/image/SkImage_Gpu.cpp |
+++ b/src/image/SkImage_Gpu.cpp |
@@ -9,6 +9,7 @@ |
#include "SkImagePriv.h" |
#include "SkBitmap.h" |
#include "SkCanvas.h" |
+#include "SkSurface.h" |
#include "GrContext.h" |
#include "GrTexture.h" |
@@ -16,40 +17,40 @@ class SkImage_Gpu : public SkImage_Base { |
public: |
SK_DECLARE_INST_COUNT(SkImage_Gpu) |
- explicit SkImage_Gpu(const SkBitmap&); |
- virtual ~SkImage_Gpu(); |
+ SkImage_Gpu(const SkBitmap&, int sampleCount); |
- virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVERRIDE; |
- virtual void onDrawRect(SkCanvas*, const SkRect* src, const SkRect& dst, |
- const SkPaint*) const SK_OVERRIDE; |
- virtual GrTexture* onGetTexture() const SK_OVERRIDE; |
- virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
+ void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVERRIDE; |
+ void onDrawRect(SkCanvas*, const SkRect* src, const SkRect& dst, |
+ const SkPaint*) const SK_OVERRIDE; |
+ SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_OVERRIDE; |
+ GrTexture* onGetTexture() const SK_OVERRIDE; |
+ bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
GrTexture* getTexture() const { return fBitmap.getTexture(); } |
- virtual SkShader* onNewShader(SkShader::TileMode, |
+ SkShader* onNewShader(SkShader::TileMode, |
SkShader::TileMode, |
const SkMatrix* localMatrix) const SK_OVERRIDE; |
- virtual bool isOpaque() const SK_OVERRIDE; |
+ bool isOpaque() const SK_OVERRIDE; |
private: |
SkBitmap fBitmap; |
+ const int fSampleCount; // 0 if we weren't built from a surface |
typedef SkImage_Base INHERITED; |
}; |
/////////////////////////////////////////////////////////////////////////////// |
-SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) |
- : INHERITED(bitmap.width(), bitmap.height()) |
- , fBitmap(bitmap) { |
+SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap, int sampleCount) |
+ : INHERITED(bitmap.width(), bitmap.height(), NULL) |
+ , fBitmap(bitmap) |
+ , fSampleCount(sampleCount) |
+{ |
SkASSERT(fBitmap.getTexture()); |
} |
-SkImage_Gpu::~SkImage_Gpu() { |
-} |
- |
SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
SkShader::TileMode tileY, |
const SkMatrix* localMatrix) const |
@@ -66,6 +67,11 @@ void SkImage_Gpu::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRect& |
canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
} |
+SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const { |
+ GrContext* ctx = this->getTexture()->getContext(); |
+ return SkSurface::NewRenderTarget(ctx, info, fSampleCount, &props); |
+} |
+ |
GrTexture* SkImage_Gpu::onGetTexture() const { |
return fBitmap.getTexture(); |
} |
@@ -80,14 +86,18 @@ bool SkImage_Gpu::isOpaque() const { |
/////////////////////////////////////////////////////////////////////////////// |
-SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
+SkImage* SkNewImageFromBitmapTexture(const SkBitmap& bitmap, int sampleCount) { |
if (NULL == bitmap.getTexture()) { |
return NULL; |
} |
+ return SkNEW_ARGS(SkImage_Gpu, (bitmap, sampleCount)); |
+} |
- return SkNEW_ARGS(SkImage_Gpu, (bitmap)); |
+SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
+ return SkNewImageFromBitmapTexture(bitmap, 0); |
} |
GrTexture* SkTextureImageGetTexture(SkImage* image) { |
return ((SkImage_Gpu*)image)->getTexture(); |
} |
+ |