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

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

Issue 886323005: Pass InterpolationQuality into DragImage to respect image-rendering:pixelated. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« Source/platform/DragImage.h ('K') | « Source/platform/DragImage.h ('k') | no next file » | 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // Keep border_y in synch with DragController::LinkDragBorderInset. 62 // Keep border_y in synch with DragController::LinkDragBorderInset.
63 const float kDragLabelBorderY = 2; 63 const float kDragLabelBorderY = 2;
64 const float kLabelBorderYOffset = 2; 64 const float kLabelBorderYOffset = 2;
65 65
66 const float kMaxDragLabelWidth = 300; 66 const float kMaxDragLabelWidth = 300;
67 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX); 67 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX);
68 68
69 const float kDragLinkLabelFontSize = 11; 69 const float kDragLinkLabelFontSize = 11;
70 const float kDragLinkUrlFontSize = 10; 70 const float kDragLinkUrlFontSize = 10;
71 71
72 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor) 72 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor, ResizeMethod resizeMet hod)
73 { 73 {
74 if (!image) 74 if (!image)
75 return nullptr; 75 return nullptr;
76 76
77 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame(); 77 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame();
78 if (!bitmap) 78 if (!bitmap)
79 return nullptr; 79 return nullptr;
80 80
81 if (image->isBitmapImage()) { 81 if (image->isBitmapImage()) {
82 ImageOrientation orientation = DefaultImageOrientation; 82 ImageOrientation orientation = DefaultImageOrientation;
83 BitmapImage* bitmapImage = toBitmapImage(image); 83 BitmapImage* bitmapImage = toBitmapImage(image);
84 IntSize sizeRespectingOrientation = bitmapImage->sizeRespectingOrientati on(); 84 IntSize sizeRespectingOrientation = bitmapImage->sizeRespectingOrientati on();
85 85
86 if (shouldRespectImageOrientation == RespectImageOrientation) 86 if (shouldRespectImageOrientation == RespectImageOrientation)
87 orientation = bitmapImage->currentFrameOrientation(); 87 orientation = bitmapImage->currentFrameOrientation();
88 88
89 if (orientation != DefaultImageOrientation) { 89 if (orientation != DefaultImageOrientation) {
90 FloatRect destRect(FloatPoint(), sizeRespectingOrientation); 90 FloatRect destRect(FloatPoint(), sizeRespectingOrientation);
91 if (orientation.usesWidthAsHeight()) 91 if (orientation.usesWidthAsHeight())
92 destRect = destRect.transposedRect(); 92 destRect = destRect.transposedRect();
93 93
94 SkBitmap skBitmap; 94 SkBitmap skBitmap;
95 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height())) 95 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height()))
96 return nullptr; 96 return nullptr;
97 97
98 SkCanvas canvas(skBitmap); 98 SkCanvas canvas(skBitmap);
99 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation))); 99 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation)));
100 canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect); 100 canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect);
101 101
102 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor)); 102 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, resizeMet hod));
103 } 103 }
104 } 104 }
105 105
106 SkBitmap skBitmap; 106 SkBitmap skBitmap;
107 if (!bitmap->bitmap().copyTo(&skBitmap, kN32_SkColorType)) 107 if (!bitmap->bitmap().copyTo(&skBitmap, kN32_SkColorType))
108 return nullptr; 108 return nullptr;
109 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor)); 109 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, resizeMethod));
110 } 110 }
111 111
112 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont) 112 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont)
113 { 113 {
114 FontDescription description = systemFont; 114 FontDescription description = systemFont;
115 description.setWeight(fontWeight); 115 description.setWeight(fontWeight);
116 description.setSpecifiedSize(size); 116 description.setSpecifiedSize(size);
117 description.setComputedSize(size); 117 description.setComputedSize(size);
118 Font result(description); 118 Font result(description);
119 result.update(nullptr); 119 result.update(nullptr);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 context->drawBidiText(labelFont, TextRunPaintInfo(textRun), FloatPoint(t extPos)); 214 context->drawBidiText(labelFont, TextRunPaintInfo(textRun), FloatPoint(t extPos));
215 } 215 }
216 216
217 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) 217 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
218 displayItemList->replay(buffer->context()); 218 displayItemList->replay(buffer->context());
219 219
220 RefPtr<Image> image = buffer->copyImage(); 220 RefPtr<Image> image = buffer->copyImage();
221 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor); 221 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor);
222 } 222 }
223 223
224 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale) 224 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, ResizeMethod resizeMethod)
225 : m_bitmap(bitmap) 225 : m_bitmap(bitmap)
226 , m_resolutionScale(resolutionScale) 226 , m_resolutionScale(resolutionScale)
227 , m_resizeMethod(resizeMethod)
227 { 228 {
228 } 229 }
229 230
230 DragImage::~DragImage() 231 DragImage::~DragImage()
231 { 232 {
232 } 233 }
233 234
234 void DragImage::fitToMaxSize(const IntSize& srcSize, const IntSize& maxSize) 235 void DragImage::fitToMaxSize(const IntSize& srcSize, const IntSize& maxSize)
235 { 236 {
236 float heightResizeRatio = 0.0f; 237 float heightResizeRatio = 0.0f;
(...skipping 27 matching lines...) Expand all
264 } 265 }
265 266
266 scale(scaleX, scaleY); 267 scale(scaleX, scaleY);
267 } 268 }
268 269
269 void DragImage::scale(float scaleX, float scaleY) 270 void DragImage::scale(float scaleX, float scaleY)
270 { 271 {
271 int imageWidth = scaleX * m_bitmap.width(); 272 int imageWidth = scaleX * m_bitmap.width();
272 int imageHeight = scaleY * m_bitmap.height(); 273 int imageHeight = scaleY * m_bitmap.height();
273 m_bitmap = skia::ImageOperations::Resize( 274 m_bitmap = skia::ImageOperations::Resize(
274 m_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, imageWidth, imageHeigh t); 275 m_bitmap, m_resizeMethod, imageWidth, imageHeight);
275 } 276 }
276 277
277 void DragImage::dissolveToFraction(float fraction) 278 void DragImage::dissolveToFraction(float fraction)
278 { 279 {
279 m_bitmap.setAlphaType(kPremul_SkAlphaType); 280 m_bitmap.setAlphaType(kPremul_SkAlphaType);
280 SkAutoLockPixels lock(m_bitmap); 281 SkAutoLockPixels lock(m_bitmap);
281 282
282 for (int row = 0; row < m_bitmap.height(); ++row) { 283 for (int row = 0; row < m_bitmap.height(); ++row) {
283 for (int column = 0; column < m_bitmap.width(); ++column) { 284 for (int column = 0; column < m_bitmap.width(); ++column) {
284 uint32_t* pixel = m_bitmap.getAddr32(column, row); 285 uint32_t* pixel = m_bitmap.getAddr32(column, row);
285 *pixel = SkPreMultiplyARGB( 286 *pixel = SkPreMultiplyARGB(
286 SkColorGetA(*pixel) * fraction, 287 SkColorGetA(*pixel) * fraction,
287 SkColorGetR(*pixel), 288 SkColorGetR(*pixel),
288 SkColorGetG(*pixel), 289 SkColorGetG(*pixel),
289 SkColorGetB(*pixel)); 290 SkColorGetB(*pixel));
290 } 291 }
291 } 292 }
292 } 293 }
293 294
294 } // namespace blink 295 } // namespace blink
OLDNEW
« Source/platform/DragImage.h ('K') | « Source/platform/DragImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698