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

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

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkMergeImageFilter.h" 8 #include "SkMergeImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkSurface.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkValidationUtils.h" 13 #include "SkValidationUtils.h"
14 14
15 /////////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////////
16 16
17 void SkMergeImageFilter::initAllocModes() { 17 void SkMergeImageFilter::initAllocModes() {
18 int inputCount = countInputs(); 18 int inputCount = countInputs();
19 if (inputCount) { 19 if (inputCount) {
20 size_t size = sizeof(uint8_t) * inputCount; 20 size_t size = sizeof(uint8_t) * inputCount;
(...skipping 28 matching lines...) Expand all
49 this->initModes(modes); 49 this->initModes(modes);
50 } 50 }
51 51
52 SkMergeImageFilter::~SkMergeImageFilter() { 52 SkMergeImageFilter::~SkMergeImageFilter() {
53 53
54 if (fModes != SkTCast<uint8_t*>(fStorage)) { 54 if (fModes != SkTCast<uint8_t*>(fStorage)) {
55 sk_free(fModes); 55 sk_free(fModes);
56 } 56 }
57 } 57 }
58 58
59 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, 59 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, SkImage& src,
60 const Context& ctx, 60 const Context& ctx,
61 SkBitmap* result, SkIPoint* offset) const { 61 SkAutoTUnref<SkImage>& result, SkIPoint* offset) const {
62 if (countInputs() < 1) { 62 if (countInputs() < 1) {
63 return false; 63 return false;
64 } 64 }
65 65
66 SkIRect bounds; 66 SkIRect bounds;
67 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) { 67 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) {
68 return false; 68 return false;
69 } 69 }
70 70
71 const int x0 = bounds.left(); 71 const int x0 = bounds.left();
72 const int y0 = bounds.top(); 72 const int y0 = bounds.top();
73 73
74 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); 74 SkAutoTUnref<SkSurface> surface(proxy->createSurface(bounds.width(), bounds. height()));
75 if (NULL == dst) { 75 if (NULL == surface) {
76 return false; 76 return false;
77 } 77 }
78 SkCanvas canvas(dst); 78 SkCanvas* canvas = surface->getCanvas();
79 SkPaint paint; 79 SkPaint paint;
80 80
81 int inputCount = countInputs(); 81 int inputCount = countInputs();
82 for (int i = 0; i < inputCount; ++i) { 82 for (int i = 0; i < inputCount; ++i) {
83 SkBitmap tmp; 83 SkAutoTUnref<SkImage> tmp;
84 const SkBitmap* srcPtr; 84 SkImage* srcPtr;
85 SkIPoint pos = SkIPoint::Make(0, 0); 85 SkIPoint pos = SkIPoint::Make(0, 0);
86 SkImageFilter* filter = getInput(i); 86 SkImageFilter* filter = getInput(i);
87 if (filter) { 87 if (filter) {
88 if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) { 88 if (!filter->filterImage(proxy, src, ctx, tmp, &pos)) {
89 return false; 89 return false;
90 } 90 }
91 srcPtr = &tmp; 91 srcPtr = tmp.get();
92 } else { 92 } else {
93 srcPtr = &src; 93 srcPtr = &src;
94 } 94 }
95 95
96 if (fModes) { 96 if (fModes) {
97 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); 97 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
98 } else { 98 } else {
99 paint.setXfermode(NULL); 99 paint.setXfermode(NULL);
100 } 100 }
101 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint); 101 canvas->drawImage(srcPtr, pos.x() - x0, pos.y() - y0, &paint);
102 } 102 }
103 103 SkImage* image = surface->newImageSnapshot(SkSurface::kYes_Budgeted);
104 if (NULL == image) {
105 return false;
106 }
107 result.reset(image);
104 offset->fX = bounds.left(); 108 offset->fX = bounds.left();
105 offset->fY = bounds.top(); 109 offset->fY = bounds.top();
106 *result = dst->accessBitmap(false);
107 return true; 110 return true;
108 } 111 }
109 112
110 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { 113 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
111 Common common; 114 Common common;
112 if (!common.unflatten(buffer, -1)) { 115 if (!common.unflatten(buffer, -1)) {
113 return NULL; 116 return NULL;
114 } 117 }
115 118
116 const int count = common.inputCount(); 119 const int count = common.inputCount();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (int i = 0; i < this->countInputs(); ++i) { 151 for (int i = 0; i < this->countInputs(); ++i) {
149 SkImageFilter* filter = this->getInput(i); 152 SkImageFilter* filter = this->getInput(i);
150 str->appendf("%d: (", i); 153 str->appendf("%d: (", i);
151 filter->toString(str); 154 filter->toString(str);
152 str->appendf(")"); 155 str->appendf(")");
153 } 156 }
154 157
155 str->append(")"); 158 str->append(")");
156 } 159 }
157 #endif 160 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698