| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Keep border_y in synch with DragController::LinkDragBorderInset. | 65 // Keep border_y in synch with DragController::LinkDragBorderInset. |
| 66 const float kDragLabelBorderY = 2; | 66 const float kDragLabelBorderY = 2; |
| 67 const float kLabelBorderYOffset = 2; | 67 const float kLabelBorderYOffset = 2; |
| 68 | 68 |
| 69 const float kMaxDragLabelWidth = 300; | 69 const float kMaxDragLabelWidth = 300; |
| 70 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde
rX); | 70 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde
rX); |
| 71 | 71 |
| 72 const float kDragLinkLabelFontSize = 11; | 72 const float kDragLinkLabelFontSize = 11; |
| 73 const float kDragLinkUrlFontSize = 10; | 73 const float kDragLinkUrlFontSize = 10; |
| 74 | 74 |
| 75 } // anonymous namespace |
| 76 |
| 75 PassRefPtr<SkImage> adjustedImage(PassRefPtr<SkImage> image, const IntSize& size
, | 77 PassRefPtr<SkImage> adjustedImage(PassRefPtr<SkImage> image, const IntSize& size
, |
| 76 const AffineTransform& transform, float opacity, InterpolationQuality interp
olationQuality) | 78 const AffineTransform& transform, float opacity, InterpolationQuality interp
olationQuality) |
| 77 { | 79 { |
| 78 if (transform.isIdentity() && opacity == 1) { | 80 if (transform.isIdentity() && opacity == 1) { |
| 79 // Nothing to adjust, just use the original. | 81 // Nothing to adjust, just use the original. |
| 80 ASSERT(image->width() == size.width()); | 82 ASSERT(image->width() == size.width()); |
| 81 ASSERT(image->height() == size.height()); | 83 ASSERT(image->height() == size.height()); |
| 82 return image; | 84 return image; |
| 83 } | 85 } |
| 84 | 86 |
| 85 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt
h(), size.height())); | 87 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt
h(), size.height())); |
| 86 if (!surface) | 88 if (!surface) |
| 87 return nullptr; | 89 return nullptr; |
| 88 | 90 |
| 89 SkPaint paint; | 91 SkPaint paint; |
| 90 ASSERT(opacity >= 0 && opacity <= 1); | 92 ASSERT(opacity >= 0 && opacity <= 1); |
| 91 paint.setAlpha(opacity * 255); | 93 paint.setAlpha(opacity * 255); |
| 92 paint.setFilterQuality(interpolationQuality == InterpolationNone | 94 paint.setFilterQuality(interpolationQuality == InterpolationNone |
| 93 ? kNone_SkFilterQuality : kHigh_SkFilterQuality); | 95 ? kNone_SkFilterQuality : kHigh_SkFilterQuality); |
| 94 | 96 |
| 95 SkCanvas* canvas = surface->getCanvas(); | 97 SkCanvas* canvas = surface->getCanvas(); |
| 96 canvas->clear(SK_ColorTRANSPARENT); | 98 canvas->clear(SK_ColorTRANSPARENT); |
| 97 canvas->concat(affineTransformToSkMatrix(transform)); | 99 canvas->concat(affineTransformToSkMatrix(transform)); |
| 98 canvas->drawImage(image.get(), 0, 0, &paint); | 100 canvas->drawImage(image.get(), 0, 0, &paint); |
| 99 | 101 |
| 100 return adoptRef(surface->newImageSnapshot()); | 102 return adoptRef(surface->newImageSnapshot()); |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // anonymous namespace | 105 FloatSize DragImage::clampedImageScale(const IntSize& imageSize, const IntSize&
size, |
| 104 | |
| 105 FloatSize DragImage::clampedImageScale(const Image& image, const IntSize& size, | |
| 106 const IntSize& maxSize) | 106 const IntSize& maxSize) |
| 107 { | 107 { |
| 108 // Non-uniform scaling for size mapping. | 108 // Non-uniform scaling for size mapping. |
| 109 FloatSize imageScale( | 109 FloatSize imageScale( |
| 110 static_cast<float>(size.width()) / image.width(), | 110 static_cast<float>(size.width()) / imageSize.width(), |
| 111 static_cast<float>(size.height()) / image.height()); | 111 static_cast<float>(size.height()) / imageSize.height()); |
| 112 | 112 |
| 113 // Uniform scaling for clamping. | 113 // Uniform scaling for clamping. |
| 114 const float clampScaleX = size.width() > maxSize.width() | 114 const float clampScaleX = size.width() > maxSize.width() |
| 115 ? static_cast<float>(maxSize.width()) / size.width() : 1; | 115 ? static_cast<float>(maxSize.width()) / size.width() : 1; |
| 116 const float clampScaleY = size.height() > maxSize.height() | 116 const float clampScaleY = size.height() > maxSize.height() |
| 117 ? static_cast<float>(maxSize.height()) / size.height() : 1; | 117 ? static_cast<float>(maxSize.height()) / size.height() : 1; |
| 118 imageScale.scale(std::min(clampScaleX, clampScaleY)); | 118 imageScale.scale(std::min(clampScaleX, clampScaleY)); |
| 119 | 119 |
| 120 return imageScale; | 120 return imageScale; |
| 121 } | 121 } |
| 122 | 122 |
| 123 PassOwnPtr<DragImage> DragImage::create(Image* image, | 123 PassOwnPtr<DragImage> DragImage::create(Image* image, |
| 124 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale
Factor, | 124 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale
Factor, |
| 125 InterpolationQuality interpolationQuality, float opacity, const FloatSize& i
mageScale) | 125 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca
le) |
| 126 { | 126 { |
| 127 if (!image) | 127 if (!image) |
| 128 return nullptr; | 128 return nullptr; |
| 129 | 129 |
| 130 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); | 130 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); |
| 131 if (!skImage) | 131 if (!skImage) |
| 132 return nullptr; | 132 return nullptr; |
| 133 | 133 |
| 134 IntSize size = image->size(); | 134 IntSize size = image->size(); |
| 135 size.scale(imageScale.width(), imageScale.height()); | 135 size.scale(imageScale.width(), imageScale.height()); |
| 136 if (size.isEmpty()) | 136 if (size.isEmpty()) |
| 137 return nullptr; | 137 return nullptr; |
| 138 | 138 |
| 139 AffineTransform transform; | 139 AffineTransform transform; |
| 140 transform.scaleNonUniform(imageScale.width(), imageScale.height()); | |
| 141 | |
| 142 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit
mapImage()) { | 140 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit
mapImage()) { |
| 143 BitmapImage* bitmapImage = toBitmapImage(image); | 141 BitmapImage* bitmapImage = toBitmapImage(image); |
| 144 ImageOrientation orientation = bitmapImage->currentFrameOrientation(); | 142 ImageOrientation orientation = bitmapImage->currentFrameOrientation(); |
| 145 | 143 |
| 146 if (orientation != DefaultImageOrientation) { | 144 if (orientation != DefaultImageOrientation) { |
| 147 size = bitmapImage->sizeRespectingOrientation(); | 145 size = bitmapImage->sizeRespectingOrientation(); |
| 148 if (orientation.usesWidthAsHeight()) | 146 size.scale(imageScale.width(), imageScale.height()); |
| 149 size.scale(imageScale.height(), imageScale.width()); | |
| 150 else | |
| 151 size.scale(imageScale.width(), imageScale.height()); | |
| 152 | |
| 153 transform *= orientation.transformFromDefault(size); | 147 transform *= orientation.transformFromDefault(size); |
| 154 } | 148 } |
| 155 } | 149 } |
| 150 transform.scaleNonUniform(imageScale.width(), imageScale.height()); |
| 156 | 151 |
| 157 SkBitmap bm; | 152 SkBitmap bm; |
| 158 RefPtr<SkImage> resizedImage = | 153 RefPtr<SkImage> resizedImage = |
| 159 adjustedImage(skImage.release(), size, transform, opacity, interpolation
Quality); | 154 adjustedImage(skImage.release(), size, transform, opacity, interpolation
Quality); |
| 160 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB
itmapMode)) | 155 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB
itmapMode)) |
| 161 return nullptr; | 156 return nullptr; |
| 162 | 157 |
| 163 return adoptPtr(new DragImage(bm, deviceScaleFactor, interpolationQuality)); | 158 return adoptPtr(new DragImage(bm, deviceScaleFactor, interpolationQuality)); |
| 164 } | 159 } |
| 165 | 160 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 269 |
| 275 void DragImage::scale(float scaleX, float scaleY) | 270 void DragImage::scale(float scaleX, float scaleY) |
| 276 { | 271 { |
| 277 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality ==
InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations::
RESIZE_LANCZOS3; | 272 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality ==
InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations::
RESIZE_LANCZOS3; |
| 278 int imageWidth = scaleX * m_bitmap.width(); | 273 int imageWidth = scaleX * m_bitmap.width(); |
| 279 int imageHeight = scaleY * m_bitmap.height(); | 274 int imageHeight = scaleY * m_bitmap.height(); |
| 280 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth,
imageHeight); | 275 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth,
imageHeight); |
| 281 } | 276 } |
| 282 | 277 |
| 283 } // namespace blink | 278 } // namespace blink |
| OLD | NEW |