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

Side by Side Diff: Source/core/rendering/shapes/Shape.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: build fixes for win+mac 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 19 matching lines...) Expand all
30 #include "config.h" 30 #include "config.h"
31 #include "core/rendering/shapes/Shape.h" 31 #include "core/rendering/shapes/Shape.h"
32 32
33 #include "core/fetch/ImageResource.h" 33 #include "core/fetch/ImageResource.h"
34 #include "core/platform/graphics/ImageBuffer.h" 34 #include "core/platform/graphics/ImageBuffer.h"
35 #include "core/rendering/shapes/PolygonShape.h" 35 #include "core/rendering/shapes/PolygonShape.h"
36 #include "core/rendering/shapes/RasterShape.h" 36 #include "core/rendering/shapes/RasterShape.h"
37 #include "core/rendering/shapes/RectangleShape.h" 37 #include "core/rendering/shapes/RectangleShape.h"
38 #include "platform/LengthFunctions.h" 38 #include "platform/LengthFunctions.h"
39 #include "platform/geometry/FloatSize.h" 39 #include "platform/geometry/FloatSize.h"
40 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
40 #include "platform/graphics/WindRule.h" 41 #include "platform/graphics/WindRule.h"
41 #include "wtf/MathExtras.h" 42 #include "wtf/MathExtras.h"
42 #include "wtf/OwnPtr.h" 43 #include "wtf/OwnPtr.h"
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 static PassOwnPtr<Shape> createRectangleShape(const FloatRect& bounds, const Flo atSize& radii) 47 static PassOwnPtr<Shape> createRectangleShape(const FloatRect& bounds, const Flo atSize& radii)
47 { 48 {
48 ASSERT(bounds.width() >= 0 && bounds.height() >= 0 && radii.width() >= 0 && radii.height() >= 0); 49 ASSERT(bounds.width() >= 0 && bounds.height() >= 0 && radii.width() >= 0 && radii.height() >= 0);
49 return adoptPtr(new RectangleShape(bounds, radii)); 50 return adoptPtr(new RectangleShape(bounds, radii));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 204
204 return shape.release(); 205 return shape.release();
205 } 206 }
206 207
207 PassOwnPtr<Shape> Shape::createShape(const StyleImage* styleImage, float thresho ld, const LayoutSize&, WritingMode writingMode, Length margin, Length padding) 208 PassOwnPtr<Shape> Shape::createShape(const StyleImage* styleImage, float thresho ld, const LayoutSize&, WritingMode writingMode, Length margin, Length padding)
208 { 209 {
209 ASSERT(styleImage && styleImage->isImageResource() && styleImage->cachedImag e() && styleImage->cachedImage()->image()); 210 ASSERT(styleImage && styleImage->isImageResource() && styleImage->cachedImag e() && styleImage->cachedImage()->image());
210 211
211 Image* image = styleImage->cachedImage()->image(); 212 Image* image = styleImage->cachedImage()->image();
212 const IntSize& imageSize = image->size(); 213 const IntSize& imageSize = image->size();
213 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageSize);
214
215 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(i mageSize.height())); 214 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(i mageSize.height()));
216 215 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(imageSize));
217 if (imageBuffer) { 216 if (surface->isValid()) {
218 GraphicsContext* graphicsContext = imageBuffer->context(); 217 ImageBuffer imageBuffer(surface.release());
218 GraphicsContext* graphicsContext = imageBuffer.context();
219 graphicsContext->drawImage(image, IntPoint()); 219 graphicsContext->drawImage(image, IntPoint());
220 220
221 RefPtr<Uint8ClampedArray> pixelArray = imageBuffer->getUnmultipliedImage Data(IntRect(IntPoint(), imageSize)); 221 RefPtr<Uint8ClampedArray> pixelArray = imageBuffer.getUnmultipliedImageD ata(IntRect(IntPoint(), imageSize));
222 unsigned pixelArrayLength = pixelArray->length(); 222 unsigned pixelArrayLength = pixelArray->length();
223 unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA. 223 unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA.
224 uint8_t alphaPixelThreshold = threshold * 255; 224 uint8_t alphaPixelThreshold = threshold * 255;
225 225
226 ASSERT(static_cast<unsigned>(imageSize.width() * imageSize.height() * 4) == pixelArrayLength); 226 ASSERT(static_cast<unsigned>(imageSize.width() * imageSize.height() * 4) == pixelArrayLength);
227 227
228 for (int y = 0; y < imageSize.height(); ++y) { 228 for (int y = 0; y < imageSize.height(); ++y) {
229 int startX = -1; 229 int startX = -1;
230 for (int x = 0; x < imageSize.width() && pixelArrayOffset < pixelArr ayLength; ++x, pixelArrayOffset += 4) { 230 for (int x = 0; x < imageSize.width() && pixelArrayOffset < pixelArr ayLength; ++x, pixelArrayOffset += 4) {
231 uint8_t alpha = pixelArray->item(pixelArrayOffset); 231 uint8_t alpha = pixelArray->item(pixelArrayOffset);
232 if ((startX == -1) && alpha > alphaPixelThreshold) { 232 if ((startX == -1) && alpha > alphaPixelThreshold) {
233 startX = x; 233 startX = x;
234 } else if (startX != -1 && (alpha <= alphaPixelThreshold || x == imageSize.width() - 1)) { 234 } else if (startX != -1 && (alpha <= alphaPixelThreshold || x == imageSize.width() - 1)) {
235 intervals->appendInterval(y, startX, x); 235 intervals->appendInterval(y, startX, x);
236 startX = -1; 236 startX = -1;
237 } 237 }
238 } 238 }
239 } 239 }
240 } 240 }
241 241
242 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), imageSize)); 242 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), imageSize));
243 rasterShape->m_writingMode = writingMode; 243 rasterShape->m_writingMode = writingMode;
244 rasterShape->m_margin = floatValueForLength(margin, 0); 244 rasterShape->m_margin = floatValueForLength(margin, 0);
245 rasterShape->m_padding = floatValueForLength(padding, 0); 245 rasterShape->m_padding = floatValueForLength(padding, 0);
246 return rasterShape.release(); 246 return rasterShape.release();
247 } 247 }
248 248
249 } // namespace WebCore 249 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698