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

Side by Side Diff: Source/platform/DragImage.cpp

Issue 1170523002: Removing GraphicsContext from ImageBuffer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix for shape bug Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/ThemePainterMac.mm ('k') | Source/platform/graphics/GraphicsContext.h » ('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 (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 21 matching lines...) Expand all
32 #include "platform/fonts/FontDescription.h" 32 #include "platform/fonts/FontDescription.h"
33 #include "platform/fonts/FontMetrics.h" 33 #include "platform/fonts/FontMetrics.h"
34 #include "platform/geometry/FloatPoint.h" 34 #include "platform/geometry/FloatPoint.h"
35 #include "platform/geometry/FloatRect.h" 35 #include "platform/geometry/FloatRect.h"
36 #include "platform/geometry/IntPoint.h" 36 #include "platform/geometry/IntPoint.h"
37 #include "platform/graphics/BitmapImage.h" 37 #include "platform/graphics/BitmapImage.h"
38 #include "platform/graphics/Color.h" 38 #include "platform/graphics/Color.h"
39 #include "platform/graphics/GraphicsContext.h" 39 #include "platform/graphics/GraphicsContext.h"
40 #include "platform/graphics/Image.h" 40 #include "platform/graphics/Image.h"
41 #include "platform/graphics/ImageBuffer.h" 41 #include "platform/graphics/ImageBuffer.h"
42 #include "platform/graphics/paint/DisplayItemListContextRecorder.h"
43 #include "platform/graphics/paint/DrawingRecorder.h" 42 #include "platform/graphics/paint/DrawingRecorder.h"
43 #include "platform/graphics/paint/SkPictureBuilder.h"
44 #include "platform/text/BidiTextRun.h" 44 #include "platform/text/BidiTextRun.h"
45 #include "platform/text/StringTruncator.h" 45 #include "platform/text/StringTruncator.h"
46 #include "platform/text/TextRun.h" 46 #include "platform/text/TextRun.h"
47 #include "platform/transforms/AffineTransform.h" 47 #include "platform/transforms/AffineTransform.h"
48 #include "platform/weborigin/KURL.h" 48 #include "platform/weborigin/KURL.h"
49 #include "skia/ext/image_operations.h" 49 #include "skia/ext/image_operations.h"
50 #include "third_party/skia/include/core/SkCanvas.h" 50 #include "third_party/skia/include/core/SkCanvas.h"
51 #include "third_party/skia/include/core/SkColor.h" 51 #include "third_party/skia/include/core/SkColor.h"
52 #include "third_party/skia/include/core/SkMatrix.h" 52 #include "third_party/skia/include/core/SkMatrix.h"
53 #include "wtf/PassOwnPtr.h" 53 #include "wtf/PassOwnPtr.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 164
165 // We now know how big the image needs to be, so we create and 165 // We now know how big the image needs to be, so we create and
166 // fill the background 166 // fill the background
167 IntSize scaledImageSize = imageSize; 167 IntSize scaledImageSize = imageSize;
168 scaledImageSize.scale(deviceScaleFactor); 168 scaledImageSize.scale(deviceScaleFactor);
169 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); 169 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize));
170 if (!buffer) 170 if (!buffer)
171 return nullptr; 171 return nullptr;
172 172
173 { 173 buffer->canvas()->scale(deviceScaleFactor, deviceScaleFactor);
174 DisplayItemListContextRecorder contextRecorder(*buffer->context());
175 GraphicsContext& paintContext = contextRecorder.context();
176 174
177 IntRect rect(IntPoint(), imageSize); 175 const float DragLabelRadius = 5;
178 DrawingRecorder drawingRecorder(paintContext, *buffer, DisplayItem::Drag Image, rect);
179 if (!drawingRecorder.canUseCachedDrawing()) {
180 paintContext.scale(deviceScaleFactor, deviceScaleFactor);
181 176
182 const float DragLabelRadius = 5; 177 IntRect rect(IntPoint(), imageSize);
183 const IntSize radii(DragLabelRadius, DragLabelRadius); 178 SkPaint backgroundPaint;
179 backgroundPaint.setColor(SkColorSetRGB(140, 140, 140));
180 SkRRect rrect;
181 rrect.setRectXY(SkRect::MakeWH(imageSize.width(), imageSize.height()), DragL abelRadius, DragLabelRadius);
182 buffer->canvas()->drawRRect(rrect, backgroundPaint);
184 183
185 const Color backgroundColor(140, 140, 140); 184 // Draw the text
186 paintContext.fillRoundedRect(FloatRoundedRect(rect, radii, radii, ra dii, radii), backgroundColor); 185 SkPaint textPaint;
186 if (drawURLString) {
187 if (clipURLString)
188 urlString = StringTruncator::centerTruncate(urlString, imageSize.wid th() - (kDragLabelBorderX * 2.0f), urlFont);
189 IntPoint textPos(kDragLabelBorderX, imageSize.height() - (kLabelBorderYO ffset + urlFont.fontMetrics().descent()));
190 TextRun textRun(urlString);
191 urlFont.drawText(buffer->canvas(), TextRunPaintInfo(textRun), textPos, d eviceScaleFactor, textPaint);
192 }
187 193
188 // Draw the text 194 if (clipLabelString)
189 if (drawURLString) { 195 label = StringTruncator::rightTruncate(label, imageSize.width() - (kDrag LabelBorderX * 2.0f), labelFont);
190 if (clipURLString)
191 urlString = StringTruncator::centerTruncate(urlString, image Size.width() - (kDragLabelBorderX * 2.0f), urlFont);
192 IntPoint textPos(kDragLabelBorderX, imageSize.height() - (kLabel BorderYOffset + urlFont.fontMetrics().descent()));
193 TextRun textRun(urlString);
194 paintContext.drawText(urlFont, TextRunPaintInfo(textRun), textPo s);
195 }
196 196
197 if (clipLabelString) 197 bool hasStrongDirectionality;
198 label = StringTruncator::rightTruncate(label, imageSize.width() - (kDragLabelBorderX * 2.0f), labelFont); 198 TextRun textRun = textRunWithDirectionality(label, &hasStrongDirectionality) ;
199 199 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.fontDescri ption().computedPixelSize());
200 bool hasStrongDirectionality; 200 if (hasStrongDirectionality && textRun.direction() == RTL) {
201 TextRun textRun = textRunWithDirectionality(label, &hasStrongDirecti onality); 201 float textWidth = labelFont.width(textRun);
202 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.fo ntDescription().computedPixelSize()); 202 int availableWidth = imageSize.width() - kDragLabelBorderX * 2;
203 if (hasStrongDirectionality && textRun.direction() == RTL) { 203 textPos.setX(availableWidth - ceilf(textWidth));
204 float textWidth = labelFont.width(textRun);
205 int availableWidth = imageSize.width() - kDragLabelBorderX * 2;
206 textPos.setX(availableWidth - ceilf(textWidth));
207 }
208 paintContext.drawBidiText(labelFont, TextRunPaintInfo(textRun), Floa tPoint(textPos));
209 }
210 } 204 }
205 labelFont.drawBidiText(buffer->canvas(), TextRunPaintInfo(textRun), FloatPoi nt(textPos), Font::DoNotPaintIfFontNotReady, deviceScaleFactor, textPaint);
211 206
212 RefPtr<Image> image = buffer->copyImage(); 207 RefPtr<Image> image = buffer->copyImage();
213 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor); 208 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor);
214 } 209 }
215 210
216 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, Interpolatio nQuality interpolationQuality) 211 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, Interpolatio nQuality interpolationQuality)
217 : m_bitmap(bitmap) 212 : m_bitmap(bitmap)
218 , m_resolutionScale(resolutionScale) 213 , m_resolutionScale(resolutionScale)
219 , m_interpolationQuality(interpolationQuality) 214 , m_interpolationQuality(interpolationQuality)
220 { 215 {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 *pixel = SkPreMultiplyARGB( 273 *pixel = SkPreMultiplyARGB(
279 SkColorGetA(*pixel) * fraction, 274 SkColorGetA(*pixel) * fraction,
280 SkColorGetR(*pixel), 275 SkColorGetR(*pixel),
281 SkColorGetG(*pixel), 276 SkColorGetG(*pixel),
282 SkColorGetB(*pixel)); 277 SkColorGetB(*pixel));
283 } 278 }
284 } 279 }
285 } 280 }
286 281
287 } // namespace blink 282 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/ThemePainterMac.mm ('k') | Source/platform/graphics/GraphicsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698