Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: src/effects/SkTestImageFilters.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updating to ToT (10994) Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/effects/SkRectShaderImageFilter.cpp ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 #include "SkTestImageFilters.h" 2 #include "SkTestImageFilters.h"
3 #include "SkCanvas.h" 3 #include "SkCanvas.h"
4 #include "SkDevice.h" 4 #include "SkDevice.h"
5 #include "SkFlattenableBuffers.h" 5 #include "SkFlattenableBuffers.h"
6 6
7 // Simple helper canvas that "takes ownership" of the provided device, so that 7 // Simple helper canvas that "takes ownership" of the provided device, so that
8 // when this canvas goes out of scope, so will its device. Could be replaced 8 // when this canvas goes out of scope, so will its device. Could be replaced
9 // with the following: 9 // with the following:
10 // 10 //
11 // SkCanvas canvas(device); 11 // SkCanvas canvas(device);
12 // SkAutoTUnref<SkDevice> aur(device); 12 // SkAutoTUnref<SkBaseDevice> aur(device);
13 // 13 //
14 class OwnDeviceCanvas : public SkCanvas { 14 class OwnDeviceCanvas : public SkCanvas {
15 public: 15 public:
16 OwnDeviceCanvas(SkDevice* device) : SkCanvas(device) { 16 OwnDeviceCanvas(SkBaseDevice* device) : SkCanvas(device) {
17 SkSafeUnref(device); 17 SkSafeUnref(device);
18 } 18 }
19 }; 19 };
20 20
21 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
22 22
23 bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, 23 bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
24 const SkMatrix&, 24 const SkMatrix&,
25 SkBitmap* result, SkIPoint*) { 25 SkBitmap* result, SkIPoint*) {
26 SkScalar scale = fScale; 26 SkScalar scale = fScale;
27 if (scale > SK_Scalar1 || scale <= 0) { 27 if (scale > SK_Scalar1 || scale <= 0) {
28 return false; 28 return false;
29 } 29 }
30 30
31 int dstW = SkScalarRoundToInt(src.width() * scale); 31 int dstW = SkScalarRoundToInt(src.width() * scale);
32 int dstH = SkScalarRoundToInt(src.height() * scale); 32 int dstH = SkScalarRoundToInt(src.height() * scale);
33 if (dstW < 1) { 33 if (dstW < 1) {
34 dstW = 1; 34 dstW = 1;
35 } 35 }
36 if (dstH < 1) { 36 if (dstH < 1) {
37 dstH = 1; 37 dstH = 1;
38 } 38 }
39 39
40 SkBitmap tmp; 40 SkBitmap tmp;
41 41
42 // downsample 42 // downsample
43 { 43 {
44 SkDevice* dev = proxy->createDevice(dstW, dstH); 44 SkBaseDevice* dev = proxy->createDevice(dstW, dstH);
45 if (NULL == dev) { 45 if (NULL == dev) {
46 return false; 46 return false;
47 } 47 }
48 OwnDeviceCanvas canvas(dev); 48 OwnDeviceCanvas canvas(dev);
49 SkPaint paint; 49 SkPaint paint;
50 50
51 paint.setFilterBitmap(true); 51 paint.setFilterBitmap(true);
52 canvas.scale(scale, scale); 52 canvas.scale(scale, scale);
53 canvas.drawBitmap(src, 0, 0, &paint); 53 canvas.drawBitmap(src, 0, 0, &paint);
54 tmp = dev->accessBitmap(false); 54 tmp = dev->accessBitmap(false);
55 } 55 }
56 56
57 // upscale 57 // upscale
58 { 58 {
59 SkDevice* dev = proxy->createDevice(src.width(), src.height()); 59 SkBaseDevice* dev = proxy->createDevice(src.width(), src.height());
60 if (NULL == dev) { 60 if (NULL == dev) {
61 return false; 61 return false;
62 } 62 }
63 OwnDeviceCanvas canvas(dev); 63 OwnDeviceCanvas canvas(dev);
64 64
65 SkRect r = SkRect::MakeWH(SkIntToScalar(src.width()), 65 SkRect r = SkRect::MakeWH(SkIntToScalar(src.width()),
66 SkIntToScalar(src.height())); 66 SkIntToScalar(src.height()));
67 canvas.drawBitmapRect(tmp, NULL, r, NULL); 67 canvas.drawBitmapRect(tmp, NULL, r, NULL);
68 *result = dev->accessBitmap(false); 68 *result = dev->accessBitmap(false);
69 } 69 }
70 return true; 70 return true;
71 } 71 }
72 72
73 void SkDownSampleImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 73 void SkDownSampleImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
74 this->INHERITED::flatten(buffer); 74 this->INHERITED::flatten(buffer);
75 75
76 buffer.writeScalar(fScale); 76 buffer.writeScalar(fScale);
77 } 77 }
78 78
79 SkDownSampleImageFilter::SkDownSampleImageFilter(SkFlattenableReadBuffer& buffer ) : INHERITED(buffer) { 79 SkDownSampleImageFilter::SkDownSampleImageFilter(SkFlattenableReadBuffer& buffer ) : INHERITED(buffer) {
80 fScale = buffer.readScalar(); 80 fScale = buffer.readScalar();
81 } 81 }
OLDNEW
« no previous file with comments | « src/effects/SkRectShaderImageFilter.cpp ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698