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

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: Sync and rebase 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
« no previous file with comments | « Source/platform/DragImage.h ('k') | Source/platform/DragImageTest.cpp » ('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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Keep border_y in synch with DragController::LinkDragBorderInset. 63 // Keep border_y in synch with DragController::LinkDragBorderInset.
64 const float kDragLabelBorderY = 2; 64 const float kDragLabelBorderY = 2;
65 const float kLabelBorderYOffset = 2; 65 const float kLabelBorderYOffset = 2;
66 66
67 const float kMaxDragLabelWidth = 300; 67 const float kMaxDragLabelWidth = 300;
68 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX); 68 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX);
69 69
70 const float kDragLinkLabelFontSize = 11; 70 const float kDragLinkLabelFontSize = 11;
71 const float kDragLinkUrlFontSize = 10; 71 const float kDragLinkUrlFontSize = 10;
72 72
73 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor) 73 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor, InterpolationQuality i nterpolationQuality)
74 { 74 {
75 if (!image) 75 if (!image)
76 return nullptr; 76 return nullptr;
77 77
78 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame(); 78 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame();
79 if (!bitmap) 79 if (!bitmap)
80 return nullptr; 80 return nullptr;
81 81
82 if (image->isBitmapImage()) { 82 if (image->isBitmapImage()) {
83 ImageOrientation orientation = DefaultImageOrientation; 83 ImageOrientation orientation = DefaultImageOrientation;
(...skipping 10 matching lines...) Expand all
94 94
95 SkBitmap skBitmap; 95 SkBitmap skBitmap;
96 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height())) 96 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height()))
97 return nullptr; 97 return nullptr;
98 98
99 skBitmap.eraseColor(SK_ColorTRANSPARENT); 99 skBitmap.eraseColor(SK_ColorTRANSPARENT);
100 SkCanvas canvas(skBitmap); 100 SkCanvas canvas(skBitmap);
101 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation))); 101 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation)));
102 canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect); 102 canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect);
103 103
104 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor)); 104 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpola tionQuality));
105 } 105 }
106 } 106 }
107 107
108 SkBitmap skBitmap; 108 SkBitmap skBitmap;
109 if (!bitmap->bitmap().copyTo(&skBitmap, kN32_SkColorType)) 109 if (!bitmap->bitmap().copyTo(&skBitmap, kN32_SkColorType))
110 return nullptr; 110 return nullptr;
111 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor)); 111 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpolationQual ity));
112 } 112 }
113 113
114 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont) 114 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont)
115 { 115 {
116 FontDescription description = systemFont; 116 FontDescription description = systemFont;
117 description.setWeight(fontWeight); 117 description.setWeight(fontWeight);
118 description.setSpecifiedSize(size); 118 description.setSpecifiedSize(size);
119 description.setComputedSize(size); 119 description.setComputedSize(size);
120 Font result(description); 120 Font result(description);
121 result.update(nullptr); 121 result.update(nullptr);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 context->drawBidiText(labelFont, TextRunPaintInfo(textRun), FloatPoint(t extPos)); 216 context->drawBidiText(labelFont, TextRunPaintInfo(textRun), FloatPoint(t extPos));
217 } 217 }
218 218
219 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) 219 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
220 displayItemList->replay(buffer->context()); 220 displayItemList->replay(buffer->context());
221 221
222 RefPtr<Image> image = buffer->copyImage(); 222 RefPtr<Image> image = buffer->copyImage();
223 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor); 223 return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceSc aleFactor);
224 } 224 }
225 225
226 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale) 226 DragImage::DragImage(const SkBitmap& bitmap, float resolutionScale, Interpolatio nQuality interpolationQuality)
227 : m_bitmap(bitmap) 227 : m_bitmap(bitmap)
228 , m_resolutionScale(resolutionScale) 228 , m_resolutionScale(resolutionScale)
229 , m_interpolationQuality(interpolationQuality)
229 { 230 {
230 } 231 }
231 232
232 DragImage::~DragImage() 233 DragImage::~DragImage()
233 { 234 {
234 } 235 }
235 236
236 void DragImage::fitToMaxSize(const IntSize& srcSize, const IntSize& maxSize) 237 void DragImage::fitToMaxSize(const IntSize& srcSize, const IntSize& maxSize)
237 { 238 {
238 float heightResizeRatio = 0.0f; 239 float heightResizeRatio = 0.0f;
(...skipping 24 matching lines...) Expand all
263 if (resizeRatio > 0.0f) { 264 if (resizeRatio > 0.0f) {
264 scaleX *= resizeRatio; 265 scaleX *= resizeRatio;
265 scaleY *= resizeRatio; 266 scaleY *= resizeRatio;
266 } 267 }
267 268
268 scale(scaleX, scaleY); 269 scale(scaleX, scaleY);
269 } 270 }
270 271
271 void DragImage::scale(float scaleX, float scaleY) 272 void DragImage::scale(float scaleX, float scaleY)
272 { 273 {
274 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality == InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations:: RESIZE_LANCZOS3;
273 int imageWidth = scaleX * m_bitmap.width(); 275 int imageWidth = scaleX * m_bitmap.width();
274 int imageHeight = scaleY * m_bitmap.height(); 276 int imageHeight = scaleY * m_bitmap.height();
275 m_bitmap = skia::ImageOperations::Resize( 277 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, imageHeight);
276 m_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, imageWidth, imageHeigh t);
277 } 278 }
278 279
279 void DragImage::dissolveToFraction(float fraction) 280 void DragImage::dissolveToFraction(float fraction)
280 { 281 {
281 m_bitmap.setAlphaType(kPremul_SkAlphaType); 282 m_bitmap.setAlphaType(kPremul_SkAlphaType);
282 SkAutoLockPixels lock(m_bitmap); 283 SkAutoLockPixels lock(m_bitmap);
283 284
284 for (int row = 0; row < m_bitmap.height(); ++row) { 285 for (int row = 0; row < m_bitmap.height(); ++row) {
285 for (int column = 0; column < m_bitmap.width(); ++column) { 286 for (int column = 0; column < m_bitmap.width(); ++column) {
286 uint32_t* pixel = m_bitmap.getAddr32(column, row); 287 uint32_t* pixel = m_bitmap.getAddr32(column, row);
287 *pixel = SkPreMultiplyARGB( 288 *pixel = SkPreMultiplyARGB(
288 SkColorGetA(*pixel) * fraction, 289 SkColorGetA(*pixel) * fraction,
289 SkColorGetR(*pixel), 290 SkColorGetR(*pixel),
290 SkColorGetG(*pixel), 291 SkColorGetG(*pixel),
291 SkColorGetB(*pixel)); 292 SkColorGetB(*pixel));
292 } 293 }
293 } 294 }
294 } 295 }
295 296
296 } // namespace blink 297 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/DragImage.h ('k') | Source/platform/DragImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698