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

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

Issue 787073003: Adding an option for pixelated rendering in SkPictureImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: filter level Created 6 years 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
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | no next file » | 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 * Copyright 2013 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
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 "SkPictureImageFilter.h" 8 #include "SkPictureImageFilter.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkSurfaceProps.h" 12 #include "SkSurfaceProps.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkValidationUtils.h" 14 #include "SkValidationUtils.h"
15 15
16 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, uint32_t un iqueID) 16 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, uint32_t un iqueID)
17 : INHERITED(0, 0, NULL, uniqueID) 17 : INHERITED(0, 0, NULL, uniqueID)
18 , fPicture(SkSafeRef(picture)) 18 , fPicture(SkSafeRef(picture))
19 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty()) 19 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty())
20 , fPictureResolution(kDeviceSpace_PictureResolution) { 20 , fPictureResolution(kDeviceSpace_PictureResolution)
21 , fFilterLevel(SkPaint::kLow_FilterLevel) {
21 } 22 }
22 23
23 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect, 24 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect,
24 uint32_t uniqueID, PictureResolution pictureResolution) 25 uint32_t uniqueID, PictureResolution pictureResolution,
26 SkPaint::FilterLevel filterLevel)
25 : INHERITED(0, 0, NULL, uniqueID) 27 : INHERITED(0, 0, NULL, uniqueID)
26 , fPicture(SkSafeRef(picture)) 28 , fPicture(SkSafeRef(picture))
27 , fCropRect(cropRect) 29 , fCropRect(cropRect)
28 , fPictureResolution(pictureResolution) { 30 , fPictureResolution(pictureResolution)
31 , fFilterLevel(filterLevel) {
29 } 32 }
30 33
31 SkPictureImageFilter::~SkPictureImageFilter() { 34 SkPictureImageFilter::~SkPictureImageFilter() {
32 SkSafeUnref(fPicture); 35 SkSafeUnref(fPicture);
33 } 36 }
34 37
35 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { 38 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
36 SkAutoTUnref<SkPicture> picture; 39 SkAutoTUnref<SkPicture> picture;
37 SkRect cropRect; 40 SkRect cropRect;
38 41
39 if (!buffer.isCrossProcess()) { 42 if (!buffer.isCrossProcess()) {
40 if (buffer.readBool()) { 43 if (buffer.readBool()) {
41 picture.reset(SkPicture::CreateFromBuffer(buffer)); 44 picture.reset(SkPicture::CreateFromBuffer(buffer));
42 } 45 }
43 } else { 46 } else {
44 buffer.validate(!buffer.readBool()); 47 buffer.validate(!buffer.readBool());
45 } 48 }
46 buffer.readRect(&cropRect); 49 buffer.readRect(&cropRect);
47 PictureResolution pictureResolution; 50 PictureResolution pictureResolution;
48 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) { 51 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
49 pictureResolution = kDeviceSpace_PictureResolution; 52 pictureResolution = kDeviceSpace_PictureResolution;
50 } else { 53 } else {
51 pictureResolution = (PictureResolution)buffer.readInt(); 54 pictureResolution = (PictureResolution)buffer.readInt();
52 } 55 }
53 56
54 if (pictureResolution == kLocalSpace_PictureResolution) { 57 if (kLocalSpace_PictureResolution == pictureResolution) {
55 return CreateForLocalSpace(picture, cropRect); 58 //filterLevel is only serialized if pictureResolution is LocalSpace
Stephen White 2014/12/09 16:54:23 Nit: space between // and "filterLevel"
59 SkPaint::FilterLevel filterLevel;
60 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterLevel_Version)) {
61 filterLevel = SkPaint::kLow_FilterLevel;
62 } else {
63 filterLevel = (SkPaint::FilterLevel)buffer.readInt();
64 }
65 return CreateForLocalSpace(picture, cropRect, filterLevel);
56 } 66 }
57 return Create(picture, cropRect); 67 return Create(picture, cropRect);
58 } 68 }
59 69
60 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { 70 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
61 if (!buffer.isCrossProcess()) { 71 if (!buffer.isCrossProcess()) {
62 bool hasPicture = (fPicture != NULL); 72 bool hasPicture = (fPicture != NULL);
63 buffer.writeBool(hasPicture); 73 buffer.writeBool(hasPicture);
64 if (hasPicture) { 74 if (hasPicture) {
65 fPicture->flatten(buffer); 75 fPicture->flatten(buffer);
66 } 76 }
67 } else { 77 } else {
68 buffer.writeBool(false); 78 buffer.writeBool(false);
69 } 79 }
70 buffer.writeRect(fCropRect); 80 buffer.writeRect(fCropRect);
71 buffer.writeInt(fPictureResolution); 81 buffer.writeInt(fPictureResolution);
82 if (kLocalSpace_PictureResolution == fPictureResolution) {
83 buffer.writeInt(fFilterLevel);
84 }
72 } 85 }
73 86
74 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 87 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx,
75 SkBitmap* result, SkIPoint* offset) con st { 88 SkBitmap* result, SkIPoint* offset) con st {
76 if (!fPicture) { 89 if (!fPicture) {
77 offset->fX = offset->fY = 0; 90 offset->fX = offset->fY = 0;
78 return true; 91 return true;
79 } 92 }
80 93
81 SkRect floatBounds; 94 SkRect floatBounds;
82 ctx.ctm().mapRect(&floatBounds, fCropRect); 95 ctx.ctm().mapRect(&floatBounds, fCropRect);
83 SkIRect bounds = floatBounds.roundOut(); 96 SkIRect bounds = floatBounds.roundOut();
84 if (!bounds.intersect(ctx.clipBounds())) { 97 if (!bounds.intersect(ctx.clipBounds())) {
85 return false; 98 return false;
86 } 99 }
87 100
88 if (bounds.isEmpty()) { 101 if (bounds.isEmpty()) {
89 offset->fX = offset->fY = 0; 102 offset->fX = offset->fY = 0;
90 return true; 103 return true;
91 } 104 }
92 105
93 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 106 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
94 if (NULL == device.get()) { 107 if (NULL == device.get()) {
95 return false; 108 return false;
96 } 109 }
97 110
98 if (kLocalSpace_PictureResolution == fPictureResolution && 111 if (kDeviceSpace_PictureResolution == fPictureResolution ||
99 (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { 112 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
113 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
114 } else {
100 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); 115 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
101 } else {
102 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
103 } 116 }
104 117
105 *result = device.get()->accessBitmap(false); 118 *result = device.get()->accessBitmap(false);
106 offset->fX = bounds.fLeft; 119 offset->fX = bounds.fLeft;
107 offset->fY = bounds.fTop; 120 offset->fY = bounds.fTop;
108 return true; 121 return true;
109 } 122 }
110 123
111 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device, 124 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device,
112 const SkIRect& deviceBo unds, 125 const SkIRect& deviceBo unds,
(...skipping 29 matching lines...) Expand all
142 localCanvas.drawPicture(fPicture); 155 localCanvas.drawPicture(fPicture);
143 156
144 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 157 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
145 // FIXME: switch back to the public constructor (and unfriend) after 158 // FIXME: switch back to the public constructor (and unfriend) after
146 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 159 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
147 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ; 160 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
148 161
149 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop)); 162 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
150 canvas.concat(ctx.ctm()); 163 canvas.concat(ctx.ctm());
151 SkPaint paint; 164 SkPaint paint;
152 paint.setFilterLevel(SkPaint::kLow_FilterLevel); 165 paint.setFilterLevel(fFilterLevel);
153 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), SkIntToScalar(localIBounds.fTop), &paint); 166 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft),
167 SkIntToScalar(localIBounds.fTop), &paint);
154 //canvas.drawPicture(fPicture); 168 //canvas.drawPicture(fPicture);
155 } 169 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698