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

Side by Side Diff: Source/core/platform/DragImage.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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 #include "core/platform/graphics/ImageBuffer.h" 34 #include "core/platform/graphics/ImageBuffer.h"
35 #include "core/platform/graphics/StringTruncator.h" 35 #include "core/platform/graphics/StringTruncator.h"
36 #include "core/platform/graphics/skia/NativeImageSkia.h" 36 #include "core/platform/graphics/skia/NativeImageSkia.h"
37 #include "platform/fonts/FontDescription.h" 37 #include "platform/fonts/FontDescription.h"
38 #include "platform/fonts/FontMetrics.h" 38 #include "platform/fonts/FontMetrics.h"
39 #include "platform/geometry/FloatPoint.h" 39 #include "platform/geometry/FloatPoint.h"
40 #include "platform/geometry/FloatRect.h" 40 #include "platform/geometry/FloatRect.h"
41 #include "platform/geometry/IntPoint.h" 41 #include "platform/geometry/IntPoint.h"
42 #include "platform/graphics/Color.h" 42 #include "platform/graphics/Color.h"
43 #include "platform/graphics/TextRun.h" 43 #include "platform/graphics/TextRun.h"
44 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
44 #include "platform/transforms/AffineTransform.h" 45 #include "platform/transforms/AffineTransform.h"
45 #include "platform/weborigin/KURL.h" 46 #include "platform/weborigin/KURL.h"
46 #include "skia/ext/image_operations.h" 47 #include "skia/ext/image_operations.h"
47 #include "third_party/skia/include/core/SkCanvas.h" 48 #include "third_party/skia/include/core/SkCanvas.h"
48 #include "third_party/skia/include/core/SkMatrix.h" 49 #include "third_party/skia/include/core/SkMatrix.h"
49 #include "wtf/PassOwnPtr.h" 50 #include "wtf/PassOwnPtr.h"
50 #include "wtf/RefPtr.h" 51 #include "wtf/RefPtr.h"
51 #include "wtf/text/WTFString.h" 52 #include "wtf/text/WTFString.h"
52 53
53 #include <algorithm> 54 #include <algorithm>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 imageSize.setWidth(kMaxDragLabelWidth); 157 imageSize.setWidth(kMaxDragLabelWidth);
157 clipURLString = true; 158 clipURLString = true;
158 } else 159 } else
159 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width() ) + kDragLabelBorderX * 2); 160 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width() ) + kDragLabelBorderX * 2);
160 } 161 }
161 162
162 // We now know how big the image needs to be, so we create and 163 // We now know how big the image needs to be, so we create and
163 // fill the background 164 // fill the background
164 IntSize scaledImageSize = imageSize; 165 IntSize scaledImageSize = imageSize;
165 scaledImageSize.scale(deviceScaleFactor); 166 scaledImageSize.scale(deviceScaleFactor);
166 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize, deviceScaleF actor)); 167 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(scaledImageSize, NonOpaque, deviceScaleFactor));
167 if (!buffer) 168 if (!surface->isValid())
Stephen White 2013/12/04 21:18:40 Same here.
168 return nullptr; 169 return nullptr;
170 ImageBuffer buffer(surface.release());
169 171
170 const float DragLabelRadius = 5; 172 const float DragLabelRadius = 5;
171 const IntSize radii(DragLabelRadius, DragLabelRadius); 173 const IntSize radii(DragLabelRadius, DragLabelRadius);
172 IntRect rect(IntPoint(), imageSize); 174 IntRect rect(IntPoint(), imageSize);
173 const Color backgroundColor(140, 140, 140); 175 const Color backgroundColor(140, 140, 140);
174 buffer->context()->fillRoundedRect(rect, radii, radii, radii, radii, backgro undColor); 176 buffer.context()->fillRoundedRect(rect, radii, radii, radii, radii, backgrou ndColor);
175 177
176 // Draw the text 178 // Draw the text
177 if (drawURLString) { 179 if (drawURLString) {
178 if (clipURLString) 180 if (clipURLString)
179 urlString = StringTruncator::centerTruncate(urlString, imageSize.wid th() - (kDragLabelBorderX * 2.0f), urlFont, StringTruncator::EnableRoundingHacks ); 181 urlString = StringTruncator::centerTruncate(urlString, imageSize.wid th() - (kDragLabelBorderX * 2.0f), urlFont, StringTruncator::EnableRoundingHacks );
180 IntPoint textPos(kDragLabelBorderX, imageSize.height() - (kLabelBorderYO ffset + urlFont.fontMetrics().descent())); 182 IntPoint textPos(kDragLabelBorderX, imageSize.height() - (kLabelBorderYO ffset + urlFont.fontMetrics().descent()));
181 TextRun textRun(urlString); 183 TextRun textRun(urlString);
182 buffer->context()->drawText(urlFont, TextRunPaintInfo(textRun), textPos) ; 184 buffer.context()->drawText(urlFont, TextRunPaintInfo(textRun), textPos);
183 } 185 }
184 186
185 if (clipLabelString) 187 if (clipLabelString)
186 label = StringTruncator::rightTruncate(label, imageSize.width() - (kDrag LabelBorderX * 2.0f), labelFont, StringTruncator::EnableRoundingHacks); 188 label = StringTruncator::rightTruncate(label, imageSize.width() - (kDrag LabelBorderX * 2.0f), labelFont, StringTruncator::EnableRoundingHacks);
187 189
188 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.pixelSize( )); 190 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.pixelSize( ));
189 TextRun textRun(label); 191 TextRun textRun(label);
190 buffer->context()->drawText(urlFont, TextRunPaintInfo(textRun), textPos); 192 buffer.context()->drawText(urlFont, TextRunPaintInfo(textRun), textPos);
191 193
192 RefPtr<Image> image = buffer->copyImage(); 194 RefPtr<Image> image = buffer.copyImage();
193 return DragImage::create(image.get()); 195 return DragImage::create(image.get());
194 } 196 }
195 197
196 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale) 198 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale)
197 : m_bitmap(bitmap) 199 : m_bitmap(bitmap)
198 , m_resolutionScale(resolutionScale) 200 , m_resolutionScale(resolutionScale)
199 { 201 {
200 } 202 }
201 203
202 DragImage::~DragImage() 204 DragImage::~DragImage()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 *pixel = SkPreMultiplyARGB( 259 *pixel = SkPreMultiplyARGB(
258 SkColorGetA(*pixel) * fraction, 260 SkColorGetA(*pixel) * fraction,
259 SkColorGetR(*pixel), 261 SkColorGetR(*pixel),
260 SkColorGetG(*pixel), 262 SkColorGetG(*pixel),
261 SkColorGetB(*pixel)); 263 SkColorGetB(*pixel));
262 } 264 }
263 } 265 }
264 } 266 }
265 267
266 } // namespace WebCore 268 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698