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

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: 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
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 , fPictureMode(kDeviceSpace_PictureMode) {
21 } 21 }
22 22
23 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect, 23 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect,
24 uint32_t uniqueID, PictureResolution pictureResolution) 24 uint32_t uniqueID, PictureMode pictur eMode)
25 : INHERITED(0, 0, NULL, uniqueID) 25 : INHERITED(0, 0, NULL, uniqueID)
26 , fPicture(SkSafeRef(picture)) 26 , fPicture(SkSafeRef(picture))
27 , fCropRect(cropRect) 27 , fCropRect(cropRect)
28 , fPictureResolution(pictureResolution) { 28 , fPictureMode(pictureMode) {
29 } 29 }
30 30
31 SkPictureImageFilter::~SkPictureImageFilter() { 31 SkPictureImageFilter::~SkPictureImageFilter() {
32 SkSafeUnref(fPicture); 32 SkSafeUnref(fPicture);
33 } 33 }
34 34
35 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { 35 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
36 SkAutoTUnref<SkPicture> picture; 36 SkAutoTUnref<SkPicture> picture;
37 SkRect cropRect; 37 SkRect cropRect;
38 38
39 if (!buffer.isCrossProcess()) { 39 if (!buffer.isCrossProcess()) {
40 if (buffer.readBool()) { 40 if (buffer.readBool()) {
41 picture.reset(SkPicture::CreateFromBuffer(buffer)); 41 picture.reset(SkPicture::CreateFromBuffer(buffer));
42 } 42 }
43 } else { 43 } else {
44 buffer.validate(!buffer.readBool()); 44 buffer.validate(!buffer.readBool());
45 } 45 }
46 buffer.readRect(&cropRect); 46 buffer.readRect(&cropRect);
47 PictureResolution pictureResolution; 47 PictureMode pictureMode;
48 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) { 48 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
49 pictureResolution = kDeviceSpace_PictureResolution; 49 pictureMode = kDeviceSpace_PictureMode;
50 } else { 50 } else {
51 pictureResolution = (PictureResolution)buffer.readInt(); 51 pictureMode = (PictureMode)buffer.readInt();
52 } 52 }
53 53
54 if (pictureResolution == kLocalSpace_PictureResolution) { 54 if (kDeviceSpace_PictureMode == pictureMode) {
55 return CreateForLocalSpace(picture, cropRect); 55 return Create(picture, cropRect);
56 } 56 }
57 return Create(picture, cropRect); 57 return CreateForLocalSpace(picture, cropRect, 0, pictureMode == kLocalSpaceP ixelated_PictureMode);
58 } 58 }
59 59
60 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { 60 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
61 if (!buffer.isCrossProcess()) { 61 if (!buffer.isCrossProcess()) {
62 bool hasPicture = (fPicture != NULL); 62 bool hasPicture = (fPicture != NULL);
63 buffer.writeBool(hasPicture); 63 buffer.writeBool(hasPicture);
64 if (hasPicture) { 64 if (hasPicture) {
65 fPicture->flatten(buffer); 65 fPicture->flatten(buffer);
66 } 66 }
67 } else { 67 } else {
68 buffer.writeBool(false); 68 buffer.writeBool(false);
69 } 69 }
70 buffer.writeRect(fCropRect); 70 buffer.writeRect(fCropRect);
71 buffer.writeInt(fPictureResolution); 71 buffer.writeInt(fPictureMode);
72 } 72 }
73 73
74 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 74 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx,
75 SkBitmap* result, SkIPoint* offset) con st { 75 SkBitmap* result, SkIPoint* offset) con st {
76 if (!fPicture) { 76 if (!fPicture) {
77 offset->fX = offset->fY = 0; 77 offset->fX = offset->fY = 0;
78 return true; 78 return true;
79 } 79 }
80 80
81 SkRect floatBounds; 81 SkRect floatBounds;
82 ctx.ctm().mapRect(&floatBounds, fCropRect); 82 ctx.ctm().mapRect(&floatBounds, fCropRect);
83 SkIRect bounds = floatBounds.roundOut(); 83 SkIRect bounds = floatBounds.roundOut();
84 if (!bounds.intersect(ctx.clipBounds())) { 84 if (!bounds.intersect(ctx.clipBounds())) {
85 return false; 85 return false;
86 } 86 }
87 87
88 if (bounds.isEmpty()) { 88 if (bounds.isEmpty()) {
89 offset->fX = offset->fY = 0; 89 offset->fX = offset->fY = 0;
90 return true; 90 return true;
91 } 91 }
92 92
93 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 93 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
94 if (NULL == device.get()) { 94 if (NULL == device.get()) {
95 return false; 95 return false;
96 } 96 }
97 97
98 if (kLocalSpace_PictureResolution == fPictureResolution && 98 if (kDeviceSpace_PictureMode == fPictureMode ||
99 (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { 99 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
100 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
101 } else {
100 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); 102 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
101 } else {
102 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
103 } 103 }
104 104
105 *result = device.get()->accessBitmap(false); 105 *result = device.get()->accessBitmap(false);
106 offset->fX = bounds.fLeft; 106 offset->fX = bounds.fLeft;
107 offset->fY = bounds.fTop; 107 offset->fY = bounds.fTop;
108 return true; 108 return true;
109 } 109 }
110 110
111 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device, 111 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device,
112 const SkIRect& deviceBo unds, 112 const SkIRect& deviceBo unds,
(...skipping 29 matching lines...) Expand all
142 localCanvas.drawPicture(fPicture); 142 localCanvas.drawPicture(fPicture);
143 143
144 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 144 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
145 // FIXME: switch back to the public constructor (and unfriend) after 145 // FIXME: switch back to the public constructor (and unfriend) after
146 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 146 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
147 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ; 147 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
148 148
149 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop)); 149 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
150 canvas.concat(ctx.ctm()); 150 canvas.concat(ctx.ctm());
151 SkPaint paint; 151 SkPaint paint;
152 paint.setFilterLevel(SkPaint::kLow_FilterLevel); 152 paint.setFilterLevel(kLocalSpacePixelated_PictureMode == fPictureMode ?
153 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), SkIntToScalar(localIBounds.fTop), &paint); 153 SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
154 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft),
155 SkIntToScalar(localIBounds.fTop), &paint);
154 //canvas.drawPicture(fPicture); 156 //canvas.drawPicture(fPicture);
155 } 157 }
OLDNEW
« include/effects/SkPictureImageFilter.h ('K') | « include/effects/SkPictureImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698