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 "SkSurface.h" | |
12 #include "GrContext.h" | 13 #include "GrContext.h" |
13 #include "GrTexture.h" | 14 #include "GrTexture.h" |
14 | 15 |
15 class SkImage_Gpu : public SkImage_Base { | 16 class SkImage_Gpu : public SkImage_Base { |
16 public: | 17 public: |
17 SK_DECLARE_INST_COUNT(SkImage_Gpu) | 18 SK_DECLARE_INST_COUNT(SkImage_Gpu) |
18 | 19 |
19 explicit SkImage_Gpu(const SkBitmap&); | 20 explicit SkImage_Gpu(const SkBitmap&); |
20 virtual ~SkImage_Gpu(); | 21 virtual ~SkImage_Gpu(); |
21 | 22 |
22 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVERRIDE; | 23 void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const SK_OVER RIDE; |
23 virtual void onDrawRect(SkCanvas*, const SkRect* src, const SkRect& dst, | 24 void onDrawRect(SkCanvas*, const SkRect* src, const SkRect& dst, |
24 const SkPaint*) const SK_OVERRIDE; | 25 const SkPaint*) const SK_OVERRIDE; |
25 virtual GrTexture* onGetTexture() const SK_OVERRIDE; | 26 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const SK_ OVERRIDE; |
26 virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; | 27 GrTexture* onGetTexture() const SK_OVERRIDE; |
28 bool getROPixels(SkBitmap*) const SK_OVERRIDE; | |
27 | 29 |
28 GrTexture* getTexture() const { return fBitmap.getTexture(); } | 30 GrTexture* getTexture() const { return fBitmap.getTexture(); } |
29 | 31 |
30 virtual SkShader* onNewShader(SkShader::TileMode, | 32 SkShader* onNewShader(SkShader::TileMode, |
31 SkShader::TileMode, | 33 SkShader::TileMode, |
32 const SkMatrix* localMatrix) const SK_OVERRIDE ; | 34 const SkMatrix* localMatrix) const SK_OVERRIDE ; |
33 | 35 |
34 virtual bool isOpaque() const SK_OVERRIDE; | 36 bool isOpaque() const SK_OVERRIDE; |
35 | 37 |
36 private: | 38 private: |
37 SkBitmap fBitmap; | 39 SkBitmap fBitmap; |
38 | 40 |
39 typedef SkImage_Base INHERITED; | 41 typedef SkImage_Base INHERITED; |
40 }; | 42 }; |
41 | 43 |
42 /////////////////////////////////////////////////////////////////////////////// | 44 /////////////////////////////////////////////////////////////////////////////// |
43 | 45 |
44 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) | 46 SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap) |
45 : INHERITED(bitmap.width(), bitmap.height()) | 47 : INHERITED(bitmap.width(), bitmap.height(), NULL) |
46 , fBitmap(bitmap) { | 48 , fBitmap(bitmap) { |
47 SkASSERT(fBitmap.getTexture()); | 49 SkASSERT(fBitmap.getTexture()); |
48 } | 50 } |
49 | 51 |
50 SkImage_Gpu::~SkImage_Gpu() { | 52 SkImage_Gpu::~SkImage_Gpu() { |
51 } | 53 } |
52 | 54 |
53 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, | 55 SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, |
54 SkShader::TileMode tileY, | 56 SkShader::TileMode tileY, |
55 const SkMatrix* localMatrix) const | 57 const SkMatrix* localMatrix) const |
56 { | 58 { |
57 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | 59 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); |
58 } | 60 } |
59 | 61 |
60 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint * paint) const { | 62 void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint * paint) const { |
61 canvas->drawBitmap(fBitmap, x, y, paint); | 63 canvas->drawBitmap(fBitmap, x, y, paint); |
62 } | 64 } |
63 | 65 |
64 void SkImage_Gpu::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, | 66 void SkImage_Gpu::onDrawRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, |
65 const SkPaint* paint) const { | 67 const SkPaint* paint) const { |
66 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); | 68 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
67 } | 69 } |
68 | 70 |
71 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro ps& props) const { | |
72 GrContext* ctx = this->getTexture()->getContext(); | |
73 const int sampleCount = 0; // TODO: extract this from this image... | |
bsalomon
2014/11/21 14:45:44
why not just do this as part of this CL?
reed1
2014/11/21 16:33:06
Done.
| |
74 return SkSurface::NewRenderTarget(ctx, info, sampleCount, &props); | |
75 } | |
76 | |
69 GrTexture* SkImage_Gpu::onGetTexture() const { | 77 GrTexture* SkImage_Gpu::onGetTexture() const { |
70 return fBitmap.getTexture(); | 78 return fBitmap.getTexture(); |
71 } | 79 } |
72 | 80 |
73 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 81 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
74 return fBitmap.copyTo(dst, kN32_SkColorType); | 82 return fBitmap.copyTo(dst, kN32_SkColorType); |
75 } | 83 } |
76 | 84 |
77 bool SkImage_Gpu::isOpaque() const { | 85 bool SkImage_Gpu::isOpaque() const { |
78 return fBitmap.isOpaque(); | 86 return fBitmap.isOpaque(); |
79 } | 87 } |
80 | 88 |
81 /////////////////////////////////////////////////////////////////////////////// | 89 /////////////////////////////////////////////////////////////////////////////// |
82 | 90 |
83 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { | 91 SkImage* SkImage::NewTexture(const SkBitmap& bitmap) { |
84 if (NULL == bitmap.getTexture()) { | 92 if (NULL == bitmap.getTexture()) { |
85 return NULL; | 93 return NULL; |
86 } | 94 } |
87 | 95 |
88 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); | 96 return SkNEW_ARGS(SkImage_Gpu, (bitmap)); |
89 } | 97 } |
90 | 98 |
91 GrTexture* SkTextureImageGetTexture(SkImage* image) { | 99 GrTexture* SkTextureImageGetTexture(SkImage* image) { |
92 return ((SkImage_Gpu*)image)->getTexture(); | 100 return ((SkImage_Gpu*)image)->getTexture(); |
93 } | 101 } |
OLD | NEW |