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

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

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 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
« no previous file with comments | « src/effects/SkMatrixImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.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 * 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"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint); 99 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint);
100 } 100 }
101 101
102 offset->fX = bounds.left(); 102 offset->fX = bounds.left();
103 offset->fY = bounds.top(); 103 offset->fY = bounds.top();
104 *result = dst->accessBitmap(false); 104 *result = dst->accessBitmap(false);
105 return true; 105 return true;
106 } 106 }
107 107
108 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
109 Common common;
110 if (!common.unflatten(buffer, -1)) {
111 return NULL;
112 }
113
114 const int count = common.inputCount();
115 bool hasModes = buffer.readBool();
116 if (hasModes) {
117 SkAutoSTArray<4, SkXfermode::Mode> modes(count);
118 SkAutoSTArray<4, uint8_t> modes8(count);
119 if (!buffer.readByteArray(modes8.get(), count)) {
120 return NULL;
121 }
122 for (int i = 0; i < count; ++i) {
123 modes[i] = (SkXfermode::Mode)modes8[i];
124 buffer.validate(SkIsValidMode(modes[i]));
125 }
126 if (!buffer.isValid()) {
127 return NULL;
128 }
129 return Create(common.inputs(), count, modes.get(), &common.cropRect());
130 }
131 return Create(common.inputs(), count, NULL, &common.cropRect());
132 }
133
108 void SkMergeImageFilter::flatten(SkWriteBuffer& buffer) const { 134 void SkMergeImageFilter::flatten(SkWriteBuffer& buffer) const {
109 this->INHERITED::flatten(buffer); 135 this->INHERITED::flatten(buffer);
110
111 buffer.writeBool(fModes != NULL); 136 buffer.writeBool(fModes != NULL);
112 if (fModes) { 137 if (fModes) {
113 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0])); 138 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0]));
114 } 139 }
115 } 140 }
116 141
142 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
117 SkMergeImageFilter::SkMergeImageFilter(SkReadBuffer& buffer) 143 SkMergeImageFilter::SkMergeImageFilter(SkReadBuffer& buffer)
118 : INHERITED(-1, buffer) { 144 : INHERITED(-1, buffer) {
119 bool hasModes = buffer.readBool(); 145 bool hasModes = buffer.readBool();
120 if (hasModes) { 146 if (hasModes) {
121 this->initAllocModes(); 147 this->initAllocModes();
122 int nbInputs = countInputs(); 148 int nbInputs = countInputs();
123 size_t size = nbInputs * sizeof(fModes[0]); 149 size_t size = nbInputs * sizeof(fModes[0]);
124 SkASSERT(buffer.getArrayCount() == size); 150 SkASSERT(buffer.getArrayCount() == size);
125 if (buffer.validate(buffer.getArrayCount() == size) && 151 if (buffer.validate(buffer.getArrayCount() == size) &&
126 buffer.readByteArray(fModes, size)) { 152 buffer.readByteArray(fModes, size)) {
127 for (int i = 0; i < nbInputs; ++i) { 153 for (int i = 0; i < nbInputs; ++i) {
128 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i])); 154 buffer.validate(SkIsValidMode((SkXfermode::Mode)fModes[i]));
129 } 155 }
130 } 156 }
131 } else { 157 } else {
132 fModes = 0; 158 fModes = 0;
133 } 159 }
134 } 160 }
161 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMatrixImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698