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 "SkBitmap.h"
9 #include "SkCanvas.h"
10 #include "SkImagePriv.h"
11 #include "SkImage_Base.h"
12
as_IB(SkImage * image)13 static SkImage_Base* as_IB(SkImage* image) {
14 return static_cast<SkImage_Base*>(image);
15 }
16
as_IB(const SkImage * image)17 static const SkImage_Base* as_IB(const SkImage* image) {
18 return static_cast<const SkImage_Base*>(image);
19 }
20
NextUniqueID()21 uint32_t SkImage::NextUniqueID() {
22 static int32_t gUniqueID;
23
24 // never return 0;
25 uint32_t id;
26 do {
27 id = sk_atomic_inc(&gUniqueID) + 1;
28 } while (0 == id);
29 return id;
30 }
31
draw(SkCanvas * canvas,SkScalar x,SkScalar y,const SkPaint * paint)32 void SkImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
33 const SkPaint* paint) {
34 as_IB(this)->onDraw(canvas, x, y, paint);
35 }
36
draw(SkCanvas * canvas,const SkRect * src,const SkRect & dst,const SkPaint * paint)37 void SkImage::draw(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
38 const SkPaint* paint) {
39 as_IB(this)->onDrawRectToRect(canvas, src, dst, paint);
40 }
41
getTexture()42 GrTexture* SkImage::getTexture() {
43 return as_IB(this)->onGetTexture();
44 }
45
encode(SkImageEncoder::Type type,int quality) const46 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
47 SkBitmap bm;
48 if (as_IB(this)->getROPixels(&bm)) {
49 return SkImageEncoder::EncodeData(bm, type, quality);
50 }
51 return NULL;
52 }
53