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

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

Issue 100803004: Changed maxInputCount for exact inputCount (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed input count condition Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkImageFilter.cpp ('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 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 "SkDevice.h"
11 #include "SkFlattenableBuffers.h" 11 #include "SkFlattenableBuffers.h"
12 #include "SkValidationUtils.h" 12 #include "SkValidationUtils.h"
13 13
14 // Use 65535 as an arbitrary large number of inputs that this image filter shoul d never overflow
15 static const int kMaxInputs = 65535;
16
17 /////////////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////////////
18 15
19 void SkMergeImageFilter::initAllocModes() { 16 void SkMergeImageFilter::initAllocModes() {
20 int inputCount = countInputs(); 17 int inputCount = countInputs();
21 if (inputCount) { 18 if (inputCount) {
22 size_t size = sizeof(uint8_t) * inputCount; 19 size_t size = sizeof(uint8_t) * inputCount;
23 if (size <= sizeof(fStorage)) { 20 if (size <= sizeof(fStorage)) {
24 fModes = SkTCast<uint8_t*>(fStorage); 21 fModes = SkTCast<uint8_t*>(fStorage);
25 } else { 22 } else {
26 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size)); 23 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size));
(...skipping 22 matching lines...) Expand all
49 SkXfermode::Mode modes[] = { mode, mode }; 46 SkXfermode::Mode modes[] = { mode, mode };
50 this->initModes(modes); 47 this->initModes(modes);
51 } else { 48 } else {
52 fModes = NULL; 49 fModes = NULL;
53 } 50 }
54 } 51 }
55 52
56 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count, 53 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count,
57 const SkXfermode::Mode modes[], 54 const SkXfermode::Mode modes[],
58 const CropRect* cropRect) : INHERITED(cou nt, filters, cropRect) { 55 const CropRect* cropRect) : INHERITED(cou nt, filters, cropRect) {
59 SkASSERT(count <= kMaxInputs); 56 SkASSERT(count >= 0);
60 this->initModes(modes); 57 this->initModes(modes);
61 } 58 }
62 59
63 SkMergeImageFilter::~SkMergeImageFilter() { 60 SkMergeImageFilter::~SkMergeImageFilter() {
64 61
65 if (fModes != SkTCast<uint8_t*>(fStorage)) { 62 if (fModes != SkTCast<uint8_t*>(fStorage)) {
66 sk_free(fModes); 63 sk_free(fModes);
67 } 64 }
68 } 65 }
69 66
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 151 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
155 this->INHERITED::flatten(buffer); 152 this->INHERITED::flatten(buffer);
156 153
157 buffer.writeBool(fModes != NULL); 154 buffer.writeBool(fModes != NULL);
158 if (fModes) { 155 if (fModes) {
159 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0])); 156 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0]));
160 } 157 }
161 } 158 }
162 159
163 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer) 160 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer)
164 : INHERITED(kMaxInputs, buffer) { 161 : INHERITED(-1, buffer) {
165 bool hasModes = buffer.readBool(); 162 bool hasModes = buffer.readBool();
166 if (hasModes) { 163 if (hasModes) {
167 this->initAllocModes(); 164 this->initAllocModes();
168 int nbInputs = countInputs(); 165 int nbInputs = countInputs();
169 size_t size = nbInputs * sizeof(fModes[0]); 166 size_t size = nbInputs * sizeof(fModes[0]);
170 SkASSERT(buffer.getArrayCount() == size); 167 SkASSERT(buffer.getArrayCount() == size);
171 buffer.readByteArray(fModes, size); 168 buffer.readByteArray(fModes, size);
172 for (int i = 0; i < nbInputs; ++i) { 169 for (int i = 0; i < nbInputs; ++i) {
173 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i])); 170 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i]));
174 } 171 }
175 } else { 172 } else {
176 fModes = 0; 173 fModes = 0;
177 } 174 }
178 } 175 }
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698