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

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

Issue 1361413004: Fix directly composited image path for CSS image-orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 5 years, 2 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PassRefPtr<SkImage> adjustedImage(PassRefPtr<SkImage> image, const IntSize& size , 75 } // anonymous namespace
76 const AffineTransform& transform, float opacity, InterpolationQuality interp olationQuality) 76
77 PassRefPtr<SkImage> DragImage::resizeAndOrientImage(PassRefPtr<SkImage> image, I mageOrientation orientation,
78 FloatSize imageScale, float opacity, InterpolationQuality interpolationQuali ty)
77 { 79 {
80 IntSize size(image->width(), image->height());
81 size.scale(imageScale.width(), imageScale.height());
82 AffineTransform transform;
83 if (orientation != DefaultImageOrientation) {
84 if (orientation.usesWidthAsHeight())
85 size = size.transposedSize();
86 transform *= orientation.transformFromDefault(size);
87 }
88 transform.scaleNonUniform(imageScale.width(), imageScale.height());
89
90 if (size.isEmpty())
91 return nullptr;
92
78 if (transform.isIdentity() && opacity == 1) { 93 if (transform.isIdentity() && opacity == 1) {
79 // Nothing to adjust, just use the original. 94 // Nothing to adjust, just use the original.
80 ASSERT(image->width() == size.width()); 95 ASSERT(image->width() == size.width());
81 ASSERT(image->height() == size.height()); 96 ASSERT(image->height() == size.height());
82 return image; 97 return image;
83 } 98 }
84 99
85 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt h(), size.height())); 100 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt h(), size.height()));
86 if (!surface) 101 if (!surface)
87 return nullptr; 102 return nullptr;
88 103
89 SkPaint paint; 104 SkPaint paint;
90 ASSERT(opacity >= 0 && opacity <= 1); 105 ASSERT(opacity >= 0 && opacity <= 1);
91 paint.setAlpha(opacity * 255); 106 paint.setAlpha(opacity * 255);
92 paint.setFilterQuality(interpolationQuality == InterpolationNone 107 paint.setFilterQuality(interpolationQuality == InterpolationNone
93 ? kNone_SkFilterQuality : kHigh_SkFilterQuality); 108 ? kNone_SkFilterQuality : kHigh_SkFilterQuality);
94 109
95 SkCanvas* canvas = surface->getCanvas(); 110 SkCanvas* canvas = surface->getCanvas();
96 canvas->clear(SK_ColorTRANSPARENT); 111 canvas->clear(SK_ColorTRANSPARENT);
97 canvas->concat(affineTransformToSkMatrix(transform)); 112 canvas->concat(affineTransformToSkMatrix(transform));
98 canvas->drawImage(image.get(), 0, 0, &paint); 113 canvas->drawImage(image.get(), 0, 0, &paint);
99 114
100 return adoptRef(surface->newImageSnapshot()); 115 return adoptRef(surface->newImageSnapshot());
101 } 116 }
102 117
103 } // anonymous namespace 118 FloatSize DragImage::clampedImageScale(const IntSize& imageSize, const IntSize& size,
104
105 FloatSize DragImage::clampedImageScale(const Image& image, const IntSize& size,
106 const IntSize& maxSize) 119 const IntSize& maxSize)
107 { 120 {
108 // Non-uniform scaling for size mapping. 121 // Non-uniform scaling for size mapping.
109 FloatSize imageScale( 122 FloatSize imageScale(
110 static_cast<float>(size.width()) / image.width(), 123 static_cast<float>(size.width()) / imageSize.width(),
111 static_cast<float>(size.height()) / image.height()); 124 static_cast<float>(size.height()) / imageSize.height());
112 125
113 // Uniform scaling for clamping. 126 // Uniform scaling for clamping.
114 const float clampScaleX = size.width() > maxSize.width() 127 const float clampScaleX = size.width() > maxSize.width()
115 ? static_cast<float>(maxSize.width()) / size.width() : 1; 128 ? static_cast<float>(maxSize.width()) / size.width() : 1;
116 const float clampScaleY = size.height() > maxSize.height() 129 const float clampScaleY = size.height() > maxSize.height()
117 ? static_cast<float>(maxSize.height()) / size.height() : 1; 130 ? static_cast<float>(maxSize.height()) / size.height() : 1;
118 imageScale.scale(std::min(clampScaleX, clampScaleY)); 131 imageScale.scale(std::min(clampScaleX, clampScaleY));
119 132
120 return imageScale; 133 return imageScale;
121 } 134 }
122 135
123 PassOwnPtr<DragImage> DragImage::create(Image* image, 136 PassOwnPtr<DragImage> DragImage::create(Image* image,
124 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale Factor, 137 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale Factor,
125 InterpolationQuality interpolationQuality, float opacity, const FloatSize& i mageScale) 138 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca le)
126 { 139 {
127 if (!image) 140 if (!image)
128 return nullptr; 141 return nullptr;
129 142
130 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); 143 RefPtr<SkImage> skImage = image->imageForCurrentFrame();
131 if (!skImage) 144 if (!skImage)
132 return nullptr; 145 return nullptr;
133 146
134 IntSize size = image->size(); 147 ImageOrientation orientation;
135 size.scale(imageScale.width(), imageScale.height()); 148 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage())
136 if (size.isEmpty()) 149 orientation = toBitmapImage(image)->currentFrameOrientation();
137 return nullptr;
138
139 AffineTransform transform;
140 transform.scaleNonUniform(imageScale.width(), imageScale.height());
141
142 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage()) {
143 BitmapImage* bitmapImage = toBitmapImage(image);
144 ImageOrientation orientation = bitmapImage->currentFrameOrientation();
145
146 if (orientation != DefaultImageOrientation) {
147 size = bitmapImage->sizeRespectingOrientation();
148 if (orientation.usesWidthAsHeight())
149 size.scale(imageScale.height(), imageScale.width());
150 else
151 size.scale(imageScale.width(), imageScale.height());
152
153 transform *= orientation.transformFromDefault(size);
154 }
155 }
156 150
157 SkBitmap bm; 151 SkBitmap bm;
158 RefPtr<SkImage> resizedImage = 152 RefPtr<SkImage> resizedImage =
159 adjustedImage(skImage.release(), size, transform, opacity, interpolation Quality); 153 resizeAndOrientImage(skImage.release(), orientation, imageScale, opacity , interpolationQuality);
160 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB itmapMode)) 154 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB itmapMode))
161 return nullptr; 155 return nullptr;
162 156
163 return adoptPtr(new DragImage(bm, deviceScaleFactor, interpolationQuality)); 157 return adoptPtr(new DragImage(bm, deviceScaleFactor, interpolationQuality));
164 } 158 }
165 159
166 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont) 160 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont)
167 { 161 {
168 FontDescription description = systemFont; 162 FontDescription description = systemFont;
169 description.setWeight(fontWeight); 163 description.setWeight(fontWeight);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 268
275 void DragImage::scale(float scaleX, float scaleY) 269 void DragImage::scale(float scaleX, float scaleY)
276 { 270 {
277 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality == InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations:: RESIZE_LANCZOS3; 271 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality == InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations:: RESIZE_LANCZOS3;
278 int imageWidth = scaleX * m_bitmap.width(); 272 int imageWidth = scaleX * m_bitmap.width();
279 int imageHeight = scaleY * m_bitmap.height(); 273 int imageHeight = scaleY * m_bitmap.height();
280 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, imageHeight); 274 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, imageHeight);
281 } 275 }
282 276
283 } // namespace blink 277 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/DragImage.h ('k') | third_party/WebKit/Source/platform/graphics/GraphicsLayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698