| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 SkPictureBuilder pictureBuilder(FloatRect(0, 0, scaledImageSize.width(), sca
ledImageSize.height())); |
| 173 { | 174 { |
| 174 DisplayItemListContextRecorder contextRecorder(*buffer->context()); | 175 GraphicsContext& paintContext = pictureBuilder.context(); |
| 175 GraphicsContext& paintContext = contextRecorder.context(); | |
| 176 | 176 |
| 177 IntRect rect(IntPoint(), imageSize); | 177 IntRect rect(IntPoint(), imageSize); |
| 178 DrawingRecorder drawingRecorder(paintContext, *buffer, DisplayItem::Drag
Image, rect); | 178 DrawingRecorder drawingRecorder(paintContext, *buffer, DisplayItem::Drag
Image, rect); |
| 179 if (!drawingRecorder.canUseCachedDrawing()) { | 179 if (!drawingRecorder.canUseCachedDrawing()) { |
| 180 paintContext.scale(deviceScaleFactor, deviceScaleFactor); | 180 paintContext.scale(deviceScaleFactor, deviceScaleFactor); |
| 181 | 181 |
| 182 const float DragLabelRadius = 5; | 182 const float DragLabelRadius = 5; |
| 183 const IntSize radii(DragLabelRadius, DragLabelRadius); | 183 const IntSize radii(DragLabelRadius, DragLabelRadius); |
| 184 | 184 |
| 185 const Color backgroundColor(140, 140, 140); | 185 const Color backgroundColor(140, 140, 140); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 201 TextRun textRun = textRunWithDirectionality(label, &hasStrongDirecti
onality); | 201 TextRun textRun = textRunWithDirectionality(label, &hasStrongDirecti
onality); |
| 202 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.fo
ntDescription().computedPixelSize()); | 202 IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.fo
ntDescription().computedPixelSize()); |
| 203 if (hasStrongDirectionality && textRun.direction() == RTL) { | 203 if (hasStrongDirectionality && textRun.direction() == RTL) { |
| 204 float textWidth = labelFont.width(textRun); | 204 float textWidth = labelFont.width(textRun); |
| 205 int availableWidth = imageSize.width() - kDragLabelBorderX * 2; | 205 int availableWidth = imageSize.width() - kDragLabelBorderX * 2; |
| 206 textPos.setX(availableWidth - ceilf(textWidth)); | 206 textPos.setX(availableWidth - ceilf(textWidth)); |
| 207 } | 207 } |
| 208 paintContext.drawBidiText(labelFont, TextRunPaintInfo(textRun), Floa
tPoint(textPos)); | 208 paintContext.drawBidiText(labelFont, TextRunPaintInfo(textRun), Floa
tPoint(textPos)); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 RefPtr<const SkPicture> recording = pictureBuilder.endRecording(); |
| 212 buffer->canvas()->drawPicture(recording.get()); |
| 211 | 213 |
| 212 RefPtr<Image> image = buffer->copyImage(); | 214 RefPtr<Image> image = buffer->copyImage(); |
| 213 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc
aleFactor); | 215 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc
aleFactor); |
| 214 } | 216 } |
| 215 | 217 |
| 216 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, Interpolatio
nQuality interpolationQuality) | 218 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, Interpolatio
nQuality interpolationQuality) |
| 217 : m_bitmap(bitmap) | 219 : m_bitmap(bitmap) |
| 218 , m_resolutionScale(resolutionScale) | 220 , m_resolutionScale(resolutionScale) |
| 219 , m_interpolationQuality(interpolationQuality) | 221 , m_interpolationQuality(interpolationQuality) |
| 220 { | 222 { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 *pixel = SkPreMultiplyARGB( | 280 *pixel = SkPreMultiplyARGB( |
| 279 SkColorGetA(*pixel) * fraction, | 281 SkColorGetA(*pixel) * fraction, |
| 280 SkColorGetR(*pixel), | 282 SkColorGetR(*pixel), |
| 281 SkColorGetG(*pixel), | 283 SkColorGetG(*pixel), |
| 282 SkColorGetB(*pixel)); | 284 SkColorGetB(*pixel)); |
| 283 } | 285 } |
| 284 } | 286 } |
| 285 } | 287 } |
| 286 | 288 |
| 287 } // namespace blink | 289 } // namespace blink |
| OLD | NEW |