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

Side by Side Diff: third_party/WebKit/Source/core/layout/shapes/Shape.cpp

Issue 2748103015: Replace ASSERT with DCHECK in core/layout/<sub dirs> (Closed)
Patch Set: Rebase with latest Created 3 years, 9 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) 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "platform/graphics/ImageBuffer.h" 45 #include "platform/graphics/ImageBuffer.h"
46 #include "platform/graphics/paint/PaintFlags.h" 46 #include "platform/graphics/paint/PaintFlags.h"
47 #include "wtf/MathExtras.h" 47 #include "wtf/MathExtras.h"
48 #include "wtf/PtrUtil.h" 48 #include "wtf/PtrUtil.h"
49 #include "wtf/typed_arrays/ArrayBufferContents.h" 49 #include "wtf/typed_arrays/ArrayBufferContents.h"
50 #include <memory> 50 #include <memory>
51 51
52 namespace blink { 52 namespace blink {
53 53
54 static std::unique_ptr<Shape> createInsetShape(const FloatRoundedRect& bounds) { 54 static std::unique_ptr<Shape> createInsetShape(const FloatRoundedRect& bounds) {
55 ASSERT(bounds.rect().width() >= 0 && bounds.rect().height() >= 0); 55 DCHECK_GE(bounds.rect().width(), 0);
56 DCHECK_GE(bounds.rect().height(), 0);
56 return WTF::makeUnique<BoxShape>(bounds); 57 return WTF::makeUnique<BoxShape>(bounds);
57 } 58 }
58 59
59 static std::unique_ptr<Shape> createCircleShape(const FloatPoint& center, 60 static std::unique_ptr<Shape> createCircleShape(const FloatPoint& center,
60 float radius) { 61 float radius) {
61 ASSERT(radius >= 0); 62 DCHECK_GE(radius, 0);
62 return WTF::wrapUnique( 63 return WTF::wrapUnique(
63 new RectangleShape(FloatRect(center.x() - radius, center.y() - radius, 64 new RectangleShape(FloatRect(center.x() - radius, center.y() - radius,
64 radius * 2, radius * 2), 65 radius * 2, radius * 2),
65 FloatSize(radius, radius))); 66 FloatSize(radius, radius)));
66 } 67 }
67 68
68 static std::unique_ptr<Shape> createEllipseShape(const FloatPoint& center, 69 static std::unique_ptr<Shape> createEllipseShape(const FloatPoint& center,
69 const FloatSize& radii) { 70 const FloatSize& radii) {
70 ASSERT(radii.width() >= 0 && radii.height() >= 0); 71 DCHECK_GE(radii.width(), 0);
72 DCHECK_GE(radii.height(), 0);
71 return WTF::wrapUnique(new RectangleShape( 73 return WTF::wrapUnique(new RectangleShape(
72 FloatRect(center.x() - radii.width(), center.y() - radii.height(), 74 FloatRect(center.x() - radii.width(), center.y() - radii.height(),
73 radii.width() * 2, radii.height() * 2), 75 radii.width() * 2, radii.height() * 2),
74 radii)); 76 radii));
75 } 77 }
76 78
77 static std::unique_ptr<Shape> createPolygonShape( 79 static std::unique_ptr<Shape> createPolygonShape(
78 std::unique_ptr<Vector<FloatPoint>> vertices, 80 std::unique_ptr<Vector<FloatPoint>> vertices,
79 WindRule fillRule) { 81 WindRule fillRule) {
80 return WTF::wrapUnique(new PolygonShape(std::move(vertices), fillRule)); 82 return WTF::wrapUnique(new PolygonShape(std::move(vertices), fillRule));
(...skipping 24 matching lines...) Expand all
105 WritingMode writingMode) { 107 WritingMode writingMode) {
106 if (isHorizontalWritingMode(writingMode)) 108 if (isHorizontalWritingMode(writingMode))
107 return size; 109 return size;
108 return size.transposedSize(); 110 return size.transposedSize();
109 } 111 }
110 112
111 std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, 113 std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape,
112 const LayoutSize& logicalBoxSize, 114 const LayoutSize& logicalBoxSize,
113 WritingMode writingMode, 115 WritingMode writingMode,
114 float margin) { 116 float margin) {
115 ASSERT(basicShape); 117 DCHECK(basicShape);
116 118
117 bool horizontalWritingMode = isHorizontalWritingMode(writingMode); 119 bool horizontalWritingMode = isHorizontalWritingMode(writingMode);
118 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() 120 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat()
119 : logicalBoxSize.height().toFloat(); 121 : logicalBoxSize.height().toFloat();
120 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat() 122 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat()
121 : logicalBoxSize.width().toFloat(); 123 : logicalBoxSize.width().toFloat();
122 std::unique_ptr<Shape> shape; 124 std::unique_ptr<Shape> shape;
123 125
124 switch (basicShape->type()) { 126 switch (basicShape->type()) {
125 case BasicShape::BasicShapeCircleType: { 127 case BasicShape::BasicShapeCircleType: {
(...skipping 22 matching lines...) Expand all
148 center, logicalBoxSize.height().toFloat(), writingMode); 150 center, logicalBoxSize.height().toFloat(), writingMode);
149 151
150 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); 152 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY));
151 break; 153 break;
152 } 154 }
153 155
154 case BasicShape::BasicShapePolygonType: { 156 case BasicShape::BasicShapePolygonType: {
155 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape); 157 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape);
156 const Vector<Length>& values = polygon->values(); 158 const Vector<Length>& values = polygon->values();
157 size_t valuesSize = values.size(); 159 size_t valuesSize = values.size();
158 ASSERT(!(valuesSize % 2)); 160 DCHECK(!(valuesSize % 2));
159 std::unique_ptr<Vector<FloatPoint>> vertices = 161 std::unique_ptr<Vector<FloatPoint>> vertices =
160 WTF::wrapUnique(new Vector<FloatPoint>(valuesSize / 2)); 162 WTF::wrapUnique(new Vector<FloatPoint>(valuesSize / 2));
161 for (unsigned i = 0; i < valuesSize; i += 2) { 163 for (unsigned i = 0; i < valuesSize; i += 2) {
162 FloatPoint vertex(floatValueForLength(values.at(i), boxWidth), 164 FloatPoint vertex(floatValueForLength(values.at(i), boxWidth),
163 floatValueForLength(values.at(i + 1), boxHeight)); 165 floatValueForLength(values.at(i + 1), boxHeight));
164 (*vertices)[i / 2] = physicalPointToLogical( 166 (*vertices)[i / 2] = physicalPointToLogical(
165 vertex, logicalBoxSize.height().toFloat(), writingMode); 167 vertex, logicalBoxSize.height().toFloat(), writingMode);
166 } 168 }
167 shape = createPolygonShape(std::move(vertices), polygon->getWindRule()); 169 shape = createPolygonShape(std::move(vertices), polygon->getWindRule());
168 break; 170 break;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 252
251 WTF::ArrayBufferContents contents; 253 WTF::ArrayBufferContents contents;
252 imageBuffer->getImageData(Unmultiplied, 254 imageBuffer->getImageData(Unmultiplied,
253 IntRect(IntPoint(), imageRect.size()), contents); 255 IntRect(IntPoint(), imageRect.size()), contents);
254 DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents); 256 DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents);
255 DOMUint8ClampedArray* pixelArray = 257 DOMUint8ClampedArray* pixelArray =
256 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()); 258 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength());
257 unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA. 259 unsigned pixelArrayOffset = 3; // Each pixel is four bytes: RGBA.
258 uint8_t alphaPixelThreshold = threshold * 255; 260 uint8_t alphaPixelThreshold = threshold * 255;
259 261
260 ASSERT(static_cast<unsigned>(imageRect.width() * imageRect.height() * 4) == 262 DCHECK_EQ(static_cast<unsigned>(imageRect.width() * imageRect.height() * 4),
261 pixelArray->length()); 263 pixelArray->length());
262 264
263 int minBufferY = std::max(0, marginRect.y() - imageRect.y()); 265 int minBufferY = std::max(0, marginRect.y() - imageRect.y());
264 int maxBufferY = 266 int maxBufferY =
265 std::min(imageRect.height(), marginRect.maxY() - imageRect.y()); 267 std::min(imageRect.height(), marginRect.maxY() - imageRect.y());
266 268
267 for (int y = minBufferY; y < maxBufferY; ++y) { 269 for (int y = minBufferY; y < maxBufferY; ++y) {
268 int startX = -1; 270 int startX = -1;
269 for (int x = 0; x < imageRect.width(); ++x, pixelArrayOffset += 4) { 271 for (int x = 0; x < imageRect.width(); ++x, pixelArrayOffset += 4) {
270 uint8_t alpha = pixelArray->item(pixelArrayOffset); 272 uint8_t alpha = pixelArray->item(pixelArrayOffset);
271 bool alphaAboveThreshold = alpha > alphaPixelThreshold; 273 bool alphaAboveThreshold = alpha > alphaPixelThreshold;
(...skipping 25 matching lines...) Expand all
297 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height()); 299 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height());
298 FloatRoundedRect bounds(rect, roundedRect.getRadii()); 300 FloatRoundedRect bounds(rect, roundedRect.getRadii());
299 std::unique_ptr<Shape> shape = createInsetShape(bounds); 301 std::unique_ptr<Shape> shape = createInsetShape(bounds);
300 shape->m_writingMode = writingMode; 302 shape->m_writingMode = writingMode;
301 shape->m_margin = margin; 303 shape->m_margin = margin;
302 304
303 return shape; 305 return shape;
304 } 306 }
305 307
306 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698