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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 2144733011: Use SkCanvas transform instead of flipSkImageVertically (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "platform/graphics/skia/SkiaUtils.h" 10 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return nullptr; 248 return nullptr;
249 if (srcRect.isEmpty()) 249 if (srcRect.isEmpty())
250 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())) ; 250 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())) ;
251 251
252 SkScalar dstLeft = std::min(0, -parsedOptions.cropRect.x()); 252 SkScalar dstLeft = std::min(0, -parsedOptions.cropRect.x());
253 SkScalar dstTop = std::min(0, -parsedOptions.cropRect.y()); 253 SkScalar dstTop = std::min(0, -parsedOptions.cropRect.y());
254 if (parsedOptions.cropRect.x() < 0) 254 if (parsedOptions.cropRect.x() < 0)
255 dstLeft = -parsedOptions.cropRect.x(); 255 dstLeft = -parsedOptions.cropRect.x();
256 if (parsedOptions.cropRect.y() < 0) 256 if (parsedOptions.cropRect.y() < 0)
257 dstTop = -parsedOptions.cropRect.y(); 257 dstTop = -parsedOptions.cropRect.y();
258 if (parsedOptions.flipY) {
259 surface->getCanvas()->translate(0, surface->height());
260 surface->getCanvas()->scale(1, -1);
261 }
258 if (parsedOptions.shouldScaleInput) { 262 if (parsedOptions.shouldScaleInput) {
259 SkRect drawDstRect = SkRect::MakeXYWH(dstLeft, dstTop, parsedOptions.res izeWidth, parsedOptions.resizeHeight); 263 SkRect drawDstRect = SkRect::MakeXYWH(dstLeft, dstTop, parsedOptions.res izeWidth, parsedOptions.resizeHeight);
260 SkPaint paint; 264 SkPaint paint;
261 paint.setFilterQuality(parsedOptions.resizeQuality); 265 paint.setFilterQuality(parsedOptions.resizeQuality);
262 surface->getCanvas()->drawImageRect(skiaImage.get(), drawDstRect, &paint ); 266 surface->getCanvas()->drawImageRect(skiaImage.get(), drawDstRect, &paint );
263 } else { 267 } else {
264 surface->getCanvas()->drawImage(skiaImage.get(), dstLeft, dstTop); 268 surface->getCanvas()->drawImage(skiaImage.get(), dstLeft, dstTop);
265 } 269 }
266 skiaImage = fromSkSp(surface->makeImageSnapshot()); 270 skiaImage = fromSkSp(surface->makeImageSnapshot());
267 if (parsedOptions.flipY)
268 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha);
269 271
270 if (parsedOptions.premultiplyAlpha) { 272 if (parsedOptions.premultiplyAlpha) {
271 if (imageFormat == PremultiplyAlpha) 273 if (imageFormat == PremultiplyAlpha)
272 return StaticBitmapImage::create(unPremulSkImageToPremul(skiaImage.g et())); 274 return StaticBitmapImage::create(unPremulSkImageToPremul(skiaImage.g et()));
273 return StaticBitmapImage::create(skiaImage.release()); 275 return StaticBitmapImage::create(skiaImage.release());
274 } 276 }
275 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get())); 277 return StaticBitmapImage::create(premulSkImageToUnPremul(skiaImage.get()));
276 } 278 }
277 279
278 ImageBitmap::ImageBitmap(HTMLImageElement* image, Optional<IntRect> cropRect, Do cument* document, const ImageBitmapOptions& options) 280 ImageBitmap::ImageBitmap(HTMLImageElement* image, Optional<IntRect> cropRect, Do cument* document, const ImageBitmapOptions& options)
(...skipping 28 matching lines...) Expand all
307 309
308 // TODO(xidachen); implement the resize option. 310 // TODO(xidachen); implement the resize option.
309 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS ourceSize()); 311 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS ourceSize());
310 312
311 IntRect videoRect = IntRect(IntPoint(), playerSize); 313 IntRect videoRect = IntRect(IntPoint(), playerSize);
312 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect); 314 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect);
313 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(parsedOptions.crop Rect.size(), NonOpaque, DoNotInitializeImagePixels); 315 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(parsedOptions.crop Rect.size(), NonOpaque, DoNotInitializeImagePixels);
314 if (!buffer) 316 if (!buffer)
315 return; 317 return;
316 318
319 if (parsedOptions.flipY) {
320 buffer->canvas()->translate(0, buffer->size().height());
321 buffer->canvas()->scale(1, -1);
322 }
317 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std:: max(0, -parsedOptions.cropRect.y())); 323 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std:: max(0, -parsedOptions.cropRect.y()));
318 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr); 324 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr);
319 325
320 if (parsedOptions.flipY || !parsedOptions.premultiplyAlpha) { 326 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown);
321 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAccelerat ion, SnapshotReasonUnknown); 327 if (!parsedOptions.premultiplyAlpha)
322 if (parsedOptions.flipY) 328 skiaImage = premulSkImageToUnPremul(skiaImage.get());
323 skiaImage = flipSkImageVertically(skiaImage.get(), PremultiplyAlpha) ; 329 m_image = StaticBitmapImage::create(skiaImage.release());
324 if (!parsedOptions.premultiplyAlpha)
325 skiaImage = premulSkImageToUnPremul(skiaImage.get());
326 m_image = StaticBitmapImage::create(skiaImage.release());
327 } else {
328 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown));
329 }
330 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ())); 330 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ()));
331 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); 331 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
332 } 332 }
333 333
334 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect, const ImageBitmapOptions& options) 334 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect, const ImageBitmapOptions& options)
335 { 335 {
336 ASSERT(canvas->isPaintable()); 336 ASSERT(canvas->isPaintable());
337 RefPtr<Image> input = canvas->copiedImage(BackBuffer, PreferAcceleration); 337 RefPtr<Image> input = canvas->copiedImage(BackBuffer, PreferAcceleration);
338 ParsedOptions parsedOptions = parseOptions(options, cropRect, canvas->bitmap SourceSize()); 338 ParsedOptions parsedOptions = parseOptions(options, cropRect, canvas->bitmap SourceSize());
339 339
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 FloatSize ImageBitmap::elementSize(const FloatSize&) const 605 FloatSize ImageBitmap::elementSize(const FloatSize&) const
606 { 606 {
607 return FloatSize(width(), height()); 607 return FloatSize(width(), height());
608 } 608 }
609 609
610 DEFINE_TRACE(ImageBitmap) 610 DEFINE_TRACE(ImageBitmap)
611 { 611 {
612 } 612 }
613 613
614 } // namespace blink 614 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698