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

Side by Side Diff: Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp

Issue 11192059: Merge 129796 - Rewrite multithreaded filter job dispatching (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1271/
Patch Set: Created 8 years, 2 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 (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) 2010 Igalia, S.L. 6 * Copyright (C) 2010 Igalia, S.L.
7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 { 164 {
165 int scanline = 4 * paintSize.width(); 165 int scanline = 4 * paintSize.width();
166 int extraHeight = 3 * kernelSizeY * 0.5f; 166 int extraHeight = 3 * kernelSizeY * 0.5f;
167 int optimalThreadNumber = (paintSize.width() * paintSize.height()) / (s_mini malRectDimension + extraHeight * paintSize.width()); 167 int optimalThreadNumber = (paintSize.width() * paintSize.height()) / (s_mini malRectDimension + extraHeight * paintSize.width());
168 168
169 if (optimalThreadNumber > 1) { 169 if (optimalThreadNumber > 1) {
170 WTF::ParallelJobs<PlatformApplyParameters> parallelJobs(&platformApplyWo rker, optimalThreadNumber); 170 WTF::ParallelJobs<PlatformApplyParameters> parallelJobs(&platformApplyWo rker, optimalThreadNumber);
171 171
172 int jobs = parallelJobs.numberOfJobs(); 172 int jobs = parallelJobs.numberOfJobs();
173 if (jobs > 1) { 173 if (jobs > 1) {
174 int blockHeight = paintSize.height() / jobs; 174 // Split the job into "blockHeight"-sized jobs but there a few jobs that need to be slightly larger since
175 --jobs; 175 // blockHeight * jobs < total size. These extras are handled by the remainder "jobsWithExtra".
176 for (int job = jobs; job >= 0; --job) { 176 const int blockHeight = paintSize.height() / jobs;
177 const int jobsWithExtra = paintSize.height() % jobs;
178
179 int currentY = 0;
180 for (int job = 0; job < jobs; job++) {
177 PlatformApplyParameters& params = parallelJobs.parameter(job); 181 PlatformApplyParameters& params = parallelJobs.parameter(job);
178 params.filter = this; 182 params.filter = this;
179 183
180 int startY; 184 int startY = !job ? 0 : currentY - extraHeight;
181 int endY; 185 currentY += job < jobsWithExtra ? blockHeight + 1 : blockHeight;
186 int endY = job == jobs - 1 ? currentY : currentY + extraHeight;
187
188 int blockSize = (endY - startY) * scanline;
182 if (!job) { 189 if (!job) {
183 startY = 0;
184 endY = blockHeight + extraHeight;
185 params.srcPixelArray = srcPixelArray; 190 params.srcPixelArray = srcPixelArray;
186 params.dstPixelArray = tmpPixelArray; 191 params.dstPixelArray = tmpPixelArray;
187 } else { 192 } else {
188 if (job == jobs) {
189 startY = job * blockHeight - extraHeight;
190 endY = paintSize.height();
191 } else {
192 startY = job * blockHeight - extraHeight;
193 endY = (job + 1) * blockHeight + extraHeight;
194 }
195
196 int blockSize = (endY - startY) * scanline;
197 params.srcPixelArray = Uint8ClampedArray::createUninitialize d(blockSize); 193 params.srcPixelArray = Uint8ClampedArray::createUninitialize d(blockSize);
198 params.dstPixelArray = Uint8ClampedArray::createUninitialize d(blockSize); 194 params.dstPixelArray = Uint8ClampedArray::createUninitialize d(blockSize);
199 memcpy(params.srcPixelArray->data(), srcPixelArray->data() + startY * scanline, blockSize); 195 memcpy(params.srcPixelArray->data(), srcPixelArray->data() + startY * scanline, blockSize);
200 } 196 }
201 197
202 params.width = paintSize.width(); 198 params.width = paintSize.width();
203 params.height = endY - startY; 199 params.height = endY - startY;
204 params.kernelSizeX = kernelSizeX; 200 params.kernelSizeX = kernelSizeX;
205 params.kernelSizeY = kernelSizeY; 201 params.kernelSizeY = kernelSizeY;
206 } 202 }
207 203
208 parallelJobs.execute(); 204 parallelJobs.execute();
209 205
210 // Copy together the parts of the image. 206 // Copy together the parts of the image.
211 for (int job = jobs; job >= 1; --job) { 207 currentY = 0;
208 for (int job = 1; job < jobs; job++) {
212 PlatformApplyParameters& params = parallelJobs.parameter(job); 209 PlatformApplyParameters& params = parallelJobs.parameter(job);
213 int sourceOffset; 210 int sourceOffset;
214 int destinationOffset; 211 int destinationOffset;
215 int size; 212 int size;
216 if (job == jobs) { 213 int adjustedBlockHeight = job < jobsWithExtra ? blockHeight + 1 : blockHeight;
217 sourceOffset = extraHeight * scanline; 214
218 destinationOffset = job * blockHeight * scanline; 215 currentY += adjustedBlockHeight;
219 size = (paintSize.height() - job * blockHeight) * scanline; 216 sourceOffset = extraHeight * scanline;
220 } else { 217 destinationOffset = currentY * scanline;
221 sourceOffset = extraHeight * scanline; 218 size = adjustedBlockHeight * scanline;
222 destinationOffset = job * blockHeight * scanline; 219
223 size = blockHeight * scanline;
224 }
225 memcpy(srcPixelArray->data() + destinationOffset, params.srcPixe lArray->data() + sourceOffset, size); 220 memcpy(srcPixelArray->data() + destinationOffset, params.srcPixe lArray->data() + sourceOffset, size);
226 } 221 }
227 return; 222 return;
228 } 223 }
229 // Fallback to single threaded mode. 224 // Fallback to single threaded mode.
230 } 225 }
231 226
232 // The selection here eventually should happen dynamically on some platforms . 227 // The selection here eventually should happen dynamically on some platforms .
233 platformApplyGeneric(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize); 228 platformApplyGeneric(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize);
234 } 229 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 316
322 float FEGaussianBlur::calculateStdDeviation(float radius) 317 float FEGaussianBlur::calculateStdDeviation(float radius)
323 { 318 {
324 // Blur radius represents 2/3 times the kernel size, the dest pixel is half of the radius applied 3 times 319 // Blur radius represents 2/3 times the kernel size, the dest pixel is half of the radius applied 3 times
325 return max((radius * 2 / 3.f - 0.5f) / gaussianKernelFactor(), 0.f); 320 return max((radius * 2 / 3.f - 0.5f) / gaussianKernelFactor(), 0.f);
326 } 321 }
327 322
328 } // namespace WebCore 323 } // namespace WebCore
329 324
330 #endif // ENABLE(FILTERS) 325 #endif // ENABLE(FILTERS)
OLDNEW
« no previous file with comments | « Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp ('k') | Source/WebCore/platform/graphics/filters/FELighting.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698