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

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

Issue 2290903002: Change (Pass)RefPtr<SkXxx> into sk_sp<SkXxx>. (Closed)
Patch Set: Self-review. Created 4 years, 3 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 const float kLabelBorderYOffset = 2; 66 const float kLabelBorderYOffset = 2;
67 67
68 const float kMaxDragLabelWidth = 300; 68 const float kMaxDragLabelWidth = 300;
69 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX); 69 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX);
70 70
71 const float kDragLinkLabelFontSize = 11; 71 const float kDragLinkLabelFontSize = 11;
72 const float kDragLinkUrlFontSize = 10; 72 const float kDragLinkUrlFontSize = 10;
73 73
74 } // anonymous namespace 74 } // anonymous namespace
75 75
76 PassRefPtr<SkImage> DragImage::resizeAndOrientImage(PassRefPtr<SkImage> image, I mageOrientation orientation, 76 sk_sp<SkImage> DragImage::resizeAndOrientImage(sk_sp<SkImage> image, ImageOrient ation orientation,
77 FloatSize imageScale, float opacity, InterpolationQuality interpolationQuali ty) 77 FloatSize imageScale, float opacity, InterpolationQuality interpolationQuali ty)
78 { 78 {
79 IntSize size(image->width(), image->height()); 79 IntSize size(image->width(), image->height());
80 size.scale(imageScale.width(), imageScale.height()); 80 size.scale(imageScale.width(), imageScale.height());
81 AffineTransform transform; 81 AffineTransform transform;
82 if (orientation != DefaultImageOrientation) { 82 if (orientation != DefaultImageOrientation) {
83 if (orientation.usesWidthAsHeight()) 83 if (orientation.usesWidthAsHeight())
84 size = size.transposedSize(); 84 size = size.transposedSize();
85 transform *= orientation.transformFromDefault(FloatSize(size)); 85 transform *= orientation.transformFromDefault(FloatSize(size));
86 } 86 }
(...skipping 14 matching lines...) Expand all
101 return nullptr; 101 return nullptr;
102 102
103 SkPaint paint; 103 SkPaint paint;
104 ASSERT(opacity >= 0 && opacity <= 1); 104 ASSERT(opacity >= 0 && opacity <= 1);
105 paint.setAlpha(opacity * 255); 105 paint.setAlpha(opacity * 255);
106 paint.setFilterQuality(interpolationQuality == InterpolationNone 106 paint.setFilterQuality(interpolationQuality == InterpolationNone
107 ? kNone_SkFilterQuality : kHigh_SkFilterQuality); 107 ? kNone_SkFilterQuality : kHigh_SkFilterQuality);
108 108
109 SkCanvas* canvas = surface->getCanvas(); 109 SkCanvas* canvas = surface->getCanvas();
110 canvas->concat(affineTransformToSkMatrix(transform)); 110 canvas->concat(affineTransformToSkMatrix(transform));
111 canvas->drawImage(image.get(), 0, 0, &paint); 111 canvas->drawImage(image.get(), 0, 0, &paint);
f(malita) 2016/09/01 03:55:38 Ditto.
Łukasz Anforowicz 2016/09/01 20:50:57 Done.
112 112
113 return fromSkSp(surface->makeImageSnapshot()); 113 return surface->makeImageSnapshot();
114 } 114 }
115 115
116 FloatSize DragImage::clampedImageScale(const IntSize& imageSize, const IntSize& size, 116 FloatSize DragImage::clampedImageScale(const IntSize& imageSize, const IntSize& size,
117 const IntSize& maxSize) 117 const IntSize& maxSize)
118 { 118 {
119 // Non-uniform scaling for size mapping. 119 // Non-uniform scaling for size mapping.
120 FloatSize imageScale( 120 FloatSize imageScale(
121 static_cast<float>(size.width()) / imageSize.width(), 121 static_cast<float>(size.width()) / imageSize.width(),
122 static_cast<float>(size.height()) / imageSize.height()); 122 static_cast<float>(size.height()) / imageSize.height());
123 123
124 // Uniform scaling for clamping. 124 // Uniform scaling for clamping.
125 const float clampScaleX = size.width() > maxSize.width() 125 const float clampScaleX = size.width() > maxSize.width()
126 ? static_cast<float>(maxSize.width()) / size.width() : 1; 126 ? static_cast<float>(maxSize.width()) / size.width() : 1;
127 const float clampScaleY = size.height() > maxSize.height() 127 const float clampScaleY = size.height() > maxSize.height()
128 ? static_cast<float>(maxSize.height()) / size.height() : 1; 128 ? static_cast<float>(maxSize.height()) / size.height() : 1;
129 imageScale.scale(std::min(clampScaleX, clampScaleY)); 129 imageScale.scale(std::min(clampScaleX, clampScaleY));
130 130
131 return imageScale; 131 return imageScale;
132 } 132 }
133 133
134 std::unique_ptr<DragImage> DragImage::create(Image* image, 134 std::unique_ptr<DragImage> DragImage::create(Image* image,
135 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale Factor, 135 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale Factor,
136 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca le) 136 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca le)
137 { 137 {
138 if (!image) 138 if (!image)
139 return nullptr; 139 return nullptr;
140 140
141 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); 141 sk_sp<SkImage> skImage = image->imageForCurrentFrame();
142 if (!skImage) 142 if (!skImage)
143 return nullptr; 143 return nullptr;
144 144
145 ImageOrientation orientation; 145 ImageOrientation orientation;
146 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage()) 146 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage())
147 orientation = toBitmapImage(image)->currentFrameOrientation(); 147 orientation = toBitmapImage(image)->currentFrameOrientation();
148 148
149 SkBitmap bm; 149 SkBitmap bm;
150 RefPtr<SkImage> resizedImage = 150 sk_sp<SkImage> resizedImage =
151 resizeAndOrientImage(skImage.release(), orientation, imageScale, opacity , interpolationQuality); 151 resizeAndOrientImage(std::move(skImage), orientation, imageScale, opacit y, interpolationQuality);
152 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB itmapMode)) 152 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB itmapMode))
153 return nullptr; 153 return nullptr;
154 154
155 return wrapUnique(new DragImage(bm, deviceScaleFactor, interpolationQuality) ); 155 return wrapUnique(new DragImage(bm, deviceScaleFactor, interpolationQuality) );
156 } 156 }
157 157
158 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont) 158 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont)
159 { 159 {
160 FontDescription description = systemFont; 160 FontDescription description = systemFont;
161 description.setWeight(fontWeight); 161 description.setWeight(fontWeight);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 void DragImage::scale(float scaleX, float scaleY) 268 void DragImage::scale(float scaleX, float scaleY)
269 { 269 {
270 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality == InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations:: RESIZE_LANCZOS3; 270 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality == InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations:: RESIZE_LANCZOS3;
271 int imageWidth = scaleX * m_bitmap.width(); 271 int imageWidth = scaleX * m_bitmap.width();
272 int imageHeight = scaleY * m_bitmap.height(); 272 int imageHeight = scaleY * m_bitmap.height();
273 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, imageHeight); 273 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, imageHeight);
274 } 274 }
275 275
276 } // namespace blink 276 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698