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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 2659063003: Avoid non-opaque->opaque requests to SkCanvas::writePixels() (Closed)
Patch Set: Created 3 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 | « 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 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 int originY = sourceRect.y(); 460 int originY = sourceRect.y();
461 int destY = destPoint.y() + sourceRect.y(); 461 int destY = destPoint.y() + sourceRect.y();
462 DCHECK_GE(destY, 0); 462 DCHECK_GE(destY, 0);
463 DCHECK_LT(destY, m_surface->size().height()); 463 DCHECK_LT(destY, m_surface->size().height());
464 DCHECK_GE(originY, 0); 464 DCHECK_GE(originY, 0);
465 DCHECK_LT(originY, sourceRect.maxY()); 465 DCHECK_LT(originY, sourceRect.maxY());
466 466
467 const size_t srcBytesPerRow = bytesPerPixel * sourceSize.width(); 467 const size_t srcBytesPerRow = bytesPerPixel * sourceSize.width();
468 const void* srcAddr = 468 const void* srcAddr =
469 source + originY * srcBytesPerRow + originX * bytesPerPixel; 469 source + originY * srcBytesPerRow + originX * bytesPerPixel;
470 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType 470
471 : kUnpremul_SkAlphaType; 471 SkAlphaType alphaType;
472 if (Opaque == m_surface->getOpacityMode()) {
473 // If the surface is opaque, tell it that we are writing opaque
474 // pixels. Writing non-opaque pixels to opaque is undefined in
475 // Skia. There is some discussion about whether it should be
476 // defined in skbug.com/6157. For now, we can get the desired
477 // behavior (memcpy) by pretending the write is opaque.
478 alphaType = kOpaque_SkAlphaType;
479 } else {
480 alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
481 : kUnpremul_SkAlphaType;
482 }
483
472 SkImageInfo info; 484 SkImageInfo info;
473 if (m_surface->colorSpace()) { 485 if (m_surface->colorSpace()) {
474 info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(), 486 info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(),
475 m_surface->colorType(), alphaType, 487 m_surface->colorType(), alphaType,
476 m_surface->colorSpace()); 488 m_surface->colorSpace());
477 } else { 489 } else {
478 info = SkImageInfo::Make( 490 info = SkImageInfo::Make(
479 sourceRect.width(), sourceRect.height(), kRGBA_8888_SkColorType, 491 sourceRect.width(), sourceRect.height(), kRGBA_8888_SkColorType,
480 alphaType, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); 492 alphaType, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
481 } 493 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 609 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
598 610
599 Vector<unsigned char> result; 611 Vector<unsigned char> result;
600 if (!encodeImage(mimeType, quality, &result)) 612 if (!encodeImage(mimeType, quality, &result))
601 return "data:,"; 613 return "data:,";
602 614
603 return "data:" + mimeType + ";base64," + base64Encode(result); 615 return "data:" + mimeType + ";base64," + base64Encode(result);
604 } 616 }
605 617
606 } // namespace blink 618 } // 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