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

Side by Side Diff: core/fxge/skia/fx_skia_device.cpp

Issue 2520073003: handle antialiased rendering as premultiplied (Closed)
Patch Set: more work on premultiplied mismatch Created 4 years 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 | « core/fxge/skia/fx_skia_device.h ('k') | fpdfsdk/fpdfformfill.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 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 <algorithm> 5 #include <algorithm>
6 #include <utility> 6 #include <utility>
7 #include <vector> 7 #include <vector>
8 8
9 #include "core/fxcodec/fx_codec.h" 9 #include "core/fxcodec/fx_codec.h"
10 #include "core/fxcrt/fx_memory.h" 10 #include "core/fxcrt/fx_memory.h"
(...skipping 16 matching lines...) Expand all
27 27
28 #include "third_party/base/ptr_util.h" 28 #include "third_party/base/ptr_util.h"
29 29
30 #include "third_party/skia/include/core/SkCanvas.h" 30 #include "third_party/skia/include/core/SkCanvas.h"
31 #include "third_party/skia/include/core/SkPaint.h" 31 #include "third_party/skia/include/core/SkPaint.h"
32 #include "third_party/skia/include/core/SkPath.h" 32 #include "third_party/skia/include/core/SkPath.h"
33 #include "third_party/skia/include/core/SkStream.h" 33 #include "third_party/skia/include/core/SkStream.h"
34 #include "third_party/skia/include/core/SkTypeface.h" 34 #include "third_party/skia/include/core/SkTypeface.h"
35 #include "third_party/skia/include/effects/SkDashPathEffect.h" 35 #include "third_party/skia/include/effects/SkDashPathEffect.h"
36 #include "third_party/skia/include/pathops/SkPathOps.h" 36 #include "third_party/skia/include/pathops/SkPathOps.h"
37 #include "third_party/skia/include/core/SkShader.h"
38 #include "third_party/skia/include/effects/SkGradientShader.h"
37 39
38 #ifdef _SKIA_SUPPORT_ 40 #ifdef _SKIA_SUPPORT_
39 #include "third_party/skia/include/core/SkColorFilter.h" 41 #include "third_party/skia/include/core/SkColorFilter.h"
40 #include "third_party/skia/include/core/SkColorPriv.h" 42 #include "third_party/skia/include/core/SkColorPriv.h"
41 #include "third_party/skia/include/core/SkMaskFilter.h" 43 #include "third_party/skia/include/core/SkMaskFilter.h"
42 #include "third_party/skia/include/core/SkPictureRecorder.h" 44 #include "third_party/skia/include/core/SkPictureRecorder.h"
43 #include "third_party/skia/include/core/SkShader.h"
44 #include "third_party/skia/include/effects/SkGradientShader.h"
45 #endif // _SKIA_SUPPORT_ 45 #endif // _SKIA_SUPPORT_
46 46
47 #ifdef SK_DEBUG 47 #ifdef SK_DEBUG
48 #include "third_party/skia/include/core/SkClipStack.h" 48 #include "third_party/skia/include/core/SkClipStack.h"
49 #endif // SK_DEBUG 49 #endif // SK_DEBUG
50 50
51 namespace { 51 namespace {
52 52
53 #ifdef _SKIA_SUPPORT_PATHS_ 53 #ifdef _SKIA_SUPPORT_PATHS_
54 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, 54 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 case FXDIB_BLEND_COLOR: 306 case FXDIB_BLEND_COLOR:
307 return SkBlendMode::kColor; 307 return SkBlendMode::kColor;
308 case FXDIB_BLEND_LUMINOSITY: 308 case FXDIB_BLEND_LUMINOSITY:
309 return SkBlendMode::kLuminosity; 309 return SkBlendMode::kLuminosity;
310 case FXDIB_BLEND_NORMAL: 310 case FXDIB_BLEND_NORMAL:
311 default: 311 default:
312 return SkBlendMode::kSrcOver; 312 return SkBlendMode::kSrcOver;
313 } 313 }
314 } 314 }
315 315
316 #ifdef _SKIA_SUPPORT_
317 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { 316 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) {
318 if (pFunc->CountInputs() != 1) 317 if (pFunc->CountInputs() != 1)
319 return false; 318 return false;
320 if (pFunc->m_Exponent != 1) 319 if (pFunc->m_Exponent != 1)
321 return false; 320 return false;
322 if (pFunc->m_nOrigOutputs != 3) 321 if (pFunc->m_nOrigOutputs != 3)
323 return false; 322 return false;
324 skColors->push( 323 skColors->push(
325 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), 324 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]),
326 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), 325 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]),
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ASSERT(maxBounds != minBounds && maxBounds >= 0); 489 ASSERT(maxBounds != minBounds && maxBounds >= 0);
491 // construct a clip parallel to the gradient that goes through 490 // construct a clip parallel to the gradient that goes through
492 // rectPts[minBounds] and rectPts[maxBounds] and perpendicular to the 491 // rectPts[minBounds] and rectPts[maxBounds] and perpendicular to the
493 // gradient that goes through startEdgePt, endEdgePt. 492 // gradient that goes through startEdgePt, endEdgePt.
494 clip->moveTo(IntersectSides(rectPts[minBounds], slope, startEdgePt)); 493 clip->moveTo(IntersectSides(rectPts[minBounds], slope, startEdgePt));
495 clip->lineTo(IntersectSides(rectPts[minBounds], slope, endEdgePt)); 494 clip->lineTo(IntersectSides(rectPts[minBounds], slope, endEdgePt));
496 clip->lineTo(IntersectSides(rectPts[maxBounds], slope, endEdgePt)); 495 clip->lineTo(IntersectSides(rectPts[maxBounds], slope, endEdgePt));
497 clip->lineTo(IntersectSides(rectPts[maxBounds], slope, startEdgePt)); 496 clip->lineTo(IntersectSides(rectPts[maxBounds], slope, startEdgePt));
498 } 497 }
499 498
499 #ifdef _SKIA_SUPPORT_
500 void SetBitmapMatrix(const CFX_Matrix* pMatrix, 500 void SetBitmapMatrix(const CFX_Matrix* pMatrix,
501 int width, 501 int width,
502 int height, 502 int height,
503 SkMatrix* skMatrix) { 503 SkMatrix* skMatrix) {
504 const CFX_Matrix& m = *pMatrix; 504 const CFX_Matrix& m = *pMatrix;
505 skMatrix->setAll(m.a / width, -m.c / height, m.c + m.e, m.b / width, 505 skMatrix->setAll(m.a / width, -m.c / height, m.c + m.e, m.b / width,
506 -m.d / height, m.d + m.f, 0, 0, 1); 506 -m.d / height, m.d + m.f, 0, 0, 1);
507 } 507 }
508 508
509 void SetBitmapPaint(bool isAlphaMask, 509 void SetBitmapPaint(bool isAlphaMask,
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 m_pCanvas->concat(skMatrix); 1164 m_pCanvas->concat(skMatrix);
1165 SkTDArray<SkPoint> positions; 1165 SkTDArray<SkPoint> positions;
1166 positions.setCount(nChars); 1166 positions.setCount(nChars);
1167 SkTDArray<uint16_t> glyphs; 1167 SkTDArray<uint16_t> glyphs;
1168 glyphs.setCount(nChars); 1168 glyphs.setCount(nChars);
1169 for (int index = 0; index < nChars; ++index) { 1169 for (int index = 0; index < nChars; ++index) {
1170 const FXTEXT_CHARPOS& cp = pCharPos[index]; 1170 const FXTEXT_CHARPOS& cp = pCharPos[index];
1171 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * vFlip}; 1171 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * vFlip};
1172 glyphs[index] = (uint16_t)cp.m_GlyphIndex; 1172 glyphs[index] = (uint16_t)cp.m_GlyphIndex;
1173 } 1173 }
1174 #ifdef _SKIA_SUPPORT_PATHS_
1175 m_pBitmap->PreMultiply();
1176 #endif // _SKIA_SUPPORT_PATHS_
1174 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); 1177 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint);
1175 m_pCanvas->restore(); 1178 m_pCanvas->restore();
1176 1179
1177 #ifdef _SKIA_SUPPORT_PATHS_
1178 if (FXARGB_A(color) < 255) {
1179 m_pBitmap->MarkForUnPreMultiply(true);
1180 }
1181 #endif // _SKIA_SUPPORT_PATHS_
1182 return true; 1180 return true;
1183 } 1181 }
1184 1182
1185 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { 1183 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const {
1186 switch (caps_id) { 1184 switch (caps_id) {
1187 case FXDC_DEVICE_CLASS: 1185 case FXDC_DEVICE_CLASS:
1188 return FXDC_DISPLAY; 1186 return FXDC_DISPLAY;
1189 #ifdef _SKIA_SUPPORT_ 1187 #ifdef _SKIA_SUPPORT_
1190 case FXDC_PIXEL_WIDTH: 1188 case FXDC_PIXEL_WIDTH:
1191 return m_pCanvas->imageInfo().width(); 1189 return m_pCanvas->imageInfo().width();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 &strokePath)) { 1440 &strokePath)) {
1443 fillPath = &strokePath; 1441 fillPath = &strokePath;
1444 } 1442 }
1445 } 1443 }
1446 } 1444 }
1447 skPaint.setStyle(SkPaint::kFill_Style); 1445 skPaint.setStyle(SkPaint::kFill_Style);
1448 skPaint.setColor(fill_color); 1446 skPaint.setColor(fill_color);
1449 DebugShowSkiaPath(*fillPath); 1447 DebugShowSkiaPath(*fillPath);
1450 DebugShowCanvasMatrix(m_pCanvas); 1448 DebugShowCanvasMatrix(m_pCanvas);
1451 DebugShowCanvasClip(m_pCanvas); 1449 DebugShowCanvasClip(m_pCanvas);
1450 #ifdef _SKIA_SUPPORT_PATHS_
1451 m_pBitmap->PreMultiply();
1452 #endif // _SKIA_SUPPORT_PATHS_
1452 m_pCanvas->drawPath(*fillPath, skPaint); 1453 m_pCanvas->drawPath(*fillPath, skPaint);
1453 } 1454 }
1454 if (pGraphState && stroke_alpha) { 1455 if (pGraphState && stroke_alpha) {
1455 DebugShowSkiaPath(skPath); 1456 DebugShowSkiaPath(skPath);
1456 DebugShowCanvasMatrix(m_pCanvas); 1457 DebugShowCanvasMatrix(m_pCanvas);
1457 DebugShowCanvasClip(m_pCanvas); 1458 DebugShowCanvasClip(m_pCanvas);
1458 skPaint.setStyle(SkPaint::kStroke_Style); 1459 skPaint.setStyle(SkPaint::kStroke_Style);
1459 skPaint.setColor(stroke_color); 1460 skPaint.setColor(stroke_color);
1461 #ifdef _SKIA_SUPPORT_PATHS_
1462 m_pBitmap->PreMultiply();
1463 #endif // _SKIA_SUPPORT_PATHS_
1460 m_pCanvas->drawPath(skPath, skPaint); 1464 m_pCanvas->drawPath(skPath, skPaint);
1461 } 1465 }
1462 m_pCanvas->restore(); 1466 m_pCanvas->restore();
1463 #ifdef _SKIA_SUPPORT_PATHS_
1464 if ((fill_mode & 3 && FXARGB_A(fill_color) < 255) ||
1465 (pGraphState && stroke_alpha < 255)) {
1466 m_pBitmap->MarkForUnPreMultiply(true);
1467 }
1468 #endif // _SKIA_SUPPORT_PATHS_
1469 return true; 1467 return true;
1470 } 1468 }
1471 1469
1472 bool CFX_SkiaDeviceDriver::DrawCosmeticLine(FX_FLOAT x1, 1470 bool CFX_SkiaDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
1473 FX_FLOAT y1, 1471 FX_FLOAT y1,
1474 FX_FLOAT x2, 1472 FX_FLOAT x2,
1475 FX_FLOAT y2, 1473 FX_FLOAT y2,
1476 uint32_t color, 1474 uint32_t color,
1477 int blend_type) { 1475 int blend_type) {
1478 return false; 1476 return false;
(...skipping 12 matching lines...) Expand all
1491 SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom), 1489 SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom),
1492 pRect->right, SkTMax(pRect->bottom, pRect->top)); 1490 pRect->right, SkTMax(pRect->bottom, pRect->top));
1493 #if SHOW_SKIA_PATH 1491 #if SHOW_SKIA_PATH
1494 printf("fill rect = %g %g %g %g\n\n", rect.fLeft, rect.fTop, rect.fRight, 1492 printf("fill rect = %g %g %g %g\n\n", rect.fLeft, rect.fTop, rect.fRight,
1495 rect.fBottom); 1493 rect.fBottom);
1496 #endif // SHOW_SKIA_PATH 1494 #endif // SHOW_SKIA_PATH
1497 m_pCanvas->drawRect(rect, spaint); 1495 m_pCanvas->drawRect(rect, spaint);
1498 return true; 1496 return true;
1499 } 1497 }
1500 1498
1501 #ifdef _SKIA_SUPPORT_
1502 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, 1499 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
1503 const CFX_Matrix* pMatrix, 1500 const CFX_Matrix* pMatrix,
1504 const FX_RECT& clip_rect, 1501 const FX_RECT& clip_rect,
1505 int alpha, 1502 int alpha,
1506 bool bAlphaMode) { 1503 bool bAlphaMode) {
1507 if (kAxialShading != pPattern->GetShadingType() && 1504 if (kAxialShading != pPattern->GetShadingType() &&
1508 kRadialShading != pPattern->GetShadingType()) { 1505 kRadialShading != pPattern->GetShadingType()) {
1509 // TODO(caryclark) more types 1506 // TODO(caryclark) more types
1510 return false; 1507 return false;
1511 } 1508 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 skPath.transform(inverse); 1622 skPath.transform(inverse);
1626 } 1623 }
1627 m_pCanvas->save(); 1624 m_pCanvas->save();
1628 if (!skClip.isEmpty()) 1625 if (!skClip.isEmpty())
1629 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true); 1626 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true);
1630 m_pCanvas->concat(skMatrix); 1627 m_pCanvas->concat(skMatrix);
1631 m_pCanvas->drawPath(skPath, paint); 1628 m_pCanvas->drawPath(skPath, paint);
1632 m_pCanvas->restore(); 1629 m_pCanvas->restore();
1633 return true; 1630 return true;
1634 } 1631 }
1635 #endif // _SKIA_SUPPORT_
1636 1632
1637 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { 1633 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const {
1638 return m_pBitmap->GetBuffer(); 1634 return m_pBitmap->GetBuffer();
1639 } 1635 }
1640 1636
1641 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { 1637 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) {
1642 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead 1638 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead
1643 pRect->left = 0; 1639 pRect->left = 0;
1644 pRect->top = 0; 1640 pRect->top = 0;
1645 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); 1641 const SkImageInfo& canvasSize = m_pCanvas->imageInfo();
(...skipping 27 matching lines...) Expand all
1673 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); 1669 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
1674 SkBitmap skDstBitmap; 1670 SkBitmap skDstBitmap;
1675 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, 1671 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr,
1676 nullptr, nullptr); 1672 nullptr, nullptr);
1677 SkCanvas canvas(skDstBitmap); 1673 SkCanvas canvas(skDstBitmap);
1678 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); 1674 canvas.drawBitmap(skSrcBitmap, left, top, nullptr);
1679 return true; 1675 return true;
1680 #endif // _SKIA_SUPPORT_ 1676 #endif // _SKIA_SUPPORT_
1681 1677
1682 #ifdef _SKIA_SUPPORT_PATHS_ 1678 #ifdef _SKIA_SUPPORT_PATHS_
1679 m_pBitmap->UnPreMultiply();
1683 FX_RECT rect(left, top, left + pBitmap->GetWidth(), 1680 FX_RECT rect(left, top, left + pBitmap->GetWidth(),
1684 top + pBitmap->GetHeight()); 1681 top + pBitmap->GetHeight());
1685 CFX_DIBitmap* pBack = nullptr; 1682 CFX_DIBitmap* pBack = nullptr;
1686 if (m_pOriDevice) { 1683 if (m_pOriDevice) {
1687 pBack = m_pOriDevice->Clone(&rect); 1684 pBack = m_pOriDevice->Clone(&rect);
1688 if (!pBack) 1685 if (!pBack)
1689 return true; 1686 return true;
1690 1687
1691 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), 1688 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(),
1692 m_pBitmap, 0, 0); 1689 m_pBitmap, 0, 0);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 } 1834 }
1838 m_pCanvas->restore(); 1835 m_pCanvas->restore();
1839 if (ct) 1836 if (ct)
1840 ct->unref(); 1837 ct->unref();
1841 DebugValidate(m_pBitmap, m_pOriDevice); 1838 DebugValidate(m_pBitmap, m_pOriDevice);
1842 #endif // _SKIA_SUPPORT_ 1839 #endif // _SKIA_SUPPORT_
1843 1840
1844 #ifdef _SKIA_SUPPORT_PATHS_ 1841 #ifdef _SKIA_SUPPORT_PATHS_
1845 if (!m_pBitmap->GetBuffer()) 1842 if (!m_pBitmap->GetBuffer())
1846 return true; 1843 return true;
1847 1844 m_pBitmap->UnPreMultiply();
1848 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; 1845 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
1849 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, 1846 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
1850 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); 1847 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr);
1851 handle = pRenderer; 1848 handle = pRenderer;
1852 #endif // _SKIA_SUPPORT_PATHS_ 1849 #endif // _SKIA_SUPPORT_PATHS_
1853 return true; 1850 return true;
1854 } 1851 }
1855 1852
1856 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { 1853 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
1857 #ifdef _SKIA_SUPPORT_ 1854 #ifdef _SKIA_SUPPORT_
1858 return false; 1855 return false;
1859 #endif // _SKIA_SUPPORT_ 1856 #endif // _SKIA_SUPPORT_
1860 1857
1861 #ifdef _SKIA_SUPPORT_PATHS_ 1858 #ifdef _SKIA_SUPPORT_PATHS_
1862 if (!m_pBitmap->GetBuffer()) { 1859 if (!m_pBitmap->GetBuffer()) {
1863 return true; 1860 return true;
1864 } 1861 }
1865 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause); 1862 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause);
1866 #endif // _SKIA_SUPPORT_PATHS_ 1863 #endif // _SKIA_SUPPORT_PATHS_
1867 } 1864 }
1868 1865
1869 #ifdef _SKIA_SUPPORT_ 1866 #if defined _SKIA_SUPPORT_
1870 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { 1867 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) {
1871 void* buffer = pDIBitmap->GetBuffer(); 1868 pDIBitmap->PreMultiply();
1869 }
1870 #endif // _SKIA_SUPPORT_
1871
1872 void CFX_DIBitmap::PreMultiply() {
1873 if (this->GetBPP() != 32)
1874 return;
1875 void* buffer = this->GetBuffer();
1872 if (!buffer) 1876 if (!buffer)
1873 return; 1877 return;
1874 if (pDIBitmap->GetBPP() != 32) { 1878 #if defined _SKIA_SUPPORT_PATHS_
1879 Format priorFormat = m_nFormat;
1880 m_nFormat = Format::kPreMultiplied;
1881 if (priorFormat != Format::kUnPreMultiplied)
1875 return; 1882 return;
1876 } 1883 #endif
1877 int height = pDIBitmap->GetHeight(); 1884 int height = this->GetHeight();
1878 int width = pDIBitmap->GetWidth(); 1885 int width = this->GetWidth();
1879 int rowBytes = pDIBitmap->GetPitch(); 1886 int rowBytes = this->GetPitch();
1880 SkImageInfo unpremultipliedInfo = 1887 SkImageInfo unpremultipliedInfo =
1881 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); 1888 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType);
1882 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); 1889 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes);
1883 SkImageInfo premultipliedInfo = 1890 SkImageInfo premultipliedInfo =
1884 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); 1891 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1885 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); 1892 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes);
1886 unpremultiplied.readPixels(premultiplied); 1893 unpremultiplied.readPixels(premultiplied);
1887 pDIBitmap->DebugVerifyBitmapIsPreMultiplied(); 1894 this->DebugVerifyBitmapIsPreMultiplied();
1888 } 1895 }
1889 #endif // _SKIA_SUPPORT_
1890 1896
1891 #ifdef _SKIA_SUPPORT_PATHS_ 1897 #ifdef _SKIA_SUPPORT_PATHS_
1892 void CFX_SkiaDeviceDriver::UnPreMultiply(CFX_DIBitmap* pDIBitmap) { 1898 void CFX_DIBitmap::UnPreMultiply() {
1893 if (!pDIBitmap->IsMarkedForUnPreMultiply()) 1899 if (this->GetBPP() != 32)
1894 return; 1900 return;
1895 pDIBitmap->DebugVerifyBitmapIsPreMultiplied(); 1901 void* buffer = this->GetBuffer();
1896 void* buffer = pDIBitmap->GetBuffer();
1897 if (!buffer) 1902 if (!buffer)
1898 return; 1903 return;
1899 if (pDIBitmap->GetBPP() != 32) { 1904 Format priorFormat = m_nFormat;
1905 m_nFormat = Format::kUnPreMultiplied;
1906 if (priorFormat != Format::kPreMultiplied)
1900 return; 1907 return;
1901 } 1908 this->DebugVerifyBitmapIsPreMultiplied();
1902 int height = pDIBitmap->GetHeight(); 1909 int height = this->GetHeight();
1903 int width = pDIBitmap->GetWidth(); 1910 int width = this->GetWidth();
1904 int rowBytes = pDIBitmap->GetPitch(); 1911 int rowBytes = this->GetPitch();
1905 SkImageInfo premultipliedInfo = 1912 SkImageInfo premultipliedInfo =
1906 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); 1913 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
1907 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); 1914 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes);
1908 SkImageInfo unpremultipliedInfo = 1915 SkImageInfo unpremultipliedInfo =
1909 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); 1916 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType);
1910 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); 1917 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes);
1911 premultiplied.readPixels(unpremultiplied); 1918 premultiplied.readPixels(unpremultiplied);
1912 pDIBitmap->MarkForUnPreMultiply(false);
1913 } 1919 }
1914 #endif // _SKIA_SUPPORT_PATHS_ 1920 #endif // _SKIA_SUPPORT_PATHS_
1915 1921
1916 #ifdef _SKIA_SUPPORT_ 1922 #ifdef _SKIA_SUPPORT_
1917 bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource, 1923 bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
1918 const CFX_DIBSource* pMask, 1924 const CFX_DIBSource* pMask,
1919 int bitmap_alpha, 1925 int bitmap_alpha,
1920 const CFX_Matrix* pMatrix, 1926 const CFX_Matrix* pMatrix,
1921 int blend_type) { 1927 int blend_type) {
1922 DebugValidate(m_pBitmap, m_pOriDevice); 1928 DebugValidate(m_pBitmap, m_pOriDevice);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 dest_top + pBitmap->GetHeight()); 1976 dest_top + pBitmap->GetHeight());
1971 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); 1977 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type);
1972 } 1978 }
1973 1979
1974 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { 1980 void CFX_SkiaDeviceDriver::Clear(uint32_t color) {
1975 m_pCanvas->clear(color); 1981 m_pCanvas->clear(color);
1976 } 1982 }
1977 #endif // _SKIA_SUPPORT_ 1983 #endif // _SKIA_SUPPORT_
1978 1984
1979 void CFX_SkiaDeviceDriver::Dump() const { 1985 void CFX_SkiaDeviceDriver::Dump() const {
1980 #if SHOW_SKIA_PATH 1986 #if SHOW_SKIA_PATH && defined _SKIA_SUPPORT_
1981 if (m_pCache) 1987 if (m_pCache)
1982 m_pCache->Dump(this); 1988 m_pCache->Dump(this);
1983 #endif // SHOW_SKIA_PATH 1989 #endif // SHOW_SKIA_PATH && defined _SKIA_SUPPORT_
1984 } 1990 }
1985 1991
1986 #ifdef _SKIA_SUPPORT_ 1992 #ifdef _SKIA_SUPPORT_
1987 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { 1993 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const {
1988 if (m_pOriDevice) 1994 if (m_pOriDevice)
1989 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); 1995 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied();
1990 } 1996 }
1991 #endif // _SKIA_SUPPORT_ 1997 #endif // _SKIA_SUPPORT_
1992 1998
1993 #ifdef _SKIA_SUPPORT_PATHS_
1994 void CFX_SkiaDeviceDriver::UnPreMultiplyDevice() {
1995 UnPreMultiply(m_pBitmap);
1996 }
1997 #endif // _SKIA_SUPPORT_PATHS_
1998
1999 CFX_FxgeDevice::CFX_FxgeDevice() { 1999 CFX_FxgeDevice::CFX_FxgeDevice() {
2000 #ifdef _SKIA_SUPPORT_ 2000 #ifdef _SKIA_SUPPORT_
2001 m_bOwnedBitmap = false; 2001 m_bOwnedBitmap = false;
2002 #endif // _SKIA_SUPPORT_ 2002 #endif // _SKIA_SUPPORT_
2003 } 2003 }
2004 2004
2005 #ifdef _SKIA_SUPPORT_ 2005 #ifdef _SKIA_SUPPORT_
2006 void CFX_FxgeDevice::Clear(uint32_t color) { 2006 void CFX_FxgeDevice::Clear(uint32_t color) {
2007 CFX_SkiaDeviceDriver* skDriver = 2007 CFX_SkiaDeviceDriver* skDriver =
2008 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); 2008 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 int blend_type) { 2080 int blend_type) {
2081 CFX_SkiaDeviceDriver* skDriver = 2081 CFX_SkiaDeviceDriver* skDriver =
2082 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); 2082 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
2083 if (skDriver) 2083 if (skDriver)
2084 return skDriver->SetBitsWithMask(pBitmap, pMask, left, top, bitmap_alpha, 2084 return skDriver->SetBitsWithMask(pBitmap, pMask, left, top, bitmap_alpha,
2085 blend_type); 2085 blend_type);
2086 return false; 2086 return false;
2087 } 2087 }
2088 #endif // _SKIA_SUPPORT_ 2088 #endif // _SKIA_SUPPORT_
2089 2089
2090 #ifdef _SKIA_SUPPORT_PATHS_
2091 void CFX_FxgeDevice::UnPreMultiplyDevice() {
2092 CFX_SkiaDeviceDriver* skDriver =
2093 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
2094 if (skDriver)
2095 skDriver->UnPreMultiplyDevice();
2096 }
2097 #endif // _SKIA_SUPPORT_PATHS_
2098
2099 void CFX_DIBSource::DebugVerifyBitmapIsPreMultiplied(void* opt) const { 2090 void CFX_DIBSource::DebugVerifyBitmapIsPreMultiplied(void* opt) const {
2100 #ifdef SK_DEBUG 2091 #ifdef SK_DEBUG
2101 SkASSERT(32 == GetBPP()); 2092 SkASSERT(32 == GetBPP());
2102 const uint32_t* buffer = (const uint32_t*)(opt ? opt : GetBuffer()); 2093 const uint32_t* buffer = (const uint32_t*)(opt ? opt : GetBuffer());
2103 int width = GetWidth(); 2094 int width = GetWidth();
2104 int height = GetHeight(); 2095 int height = GetHeight();
2105 // verify that input is really premultiplied 2096 // verify that input is really premultiplied
2106 for (int y = 0; y < height; ++y) { 2097 for (int y = 0; y < height; ++y) {
2107 const uint32_t* srcRow = buffer + y * width; 2098 const uint32_t* srcRow = buffer + y * width;
2108 for (int x = 0; x < width; ++x) { 2099 for (int x = 0; x < width; ++x) {
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 } 2933 }
2943 } 2934 }
2944 if (m_pDevice->GetBPP() == 1) { 2935 if (m_pDevice->GetBPP() == 1) {
2945 composite_span = &CFX_Renderer::CompositeSpan1bpp; 2936 composite_span = &CFX_Renderer::CompositeSpan1bpp;
2946 } 2937 }
2947 return true; 2938 return true;
2948 } 2939 }
2949 }; 2940 };
2950 2941
2951 #endif // _SKIA_SUPPORT_PATHS_ 2942 #endif // _SKIA_SUPPORT_PATHS_
OLDNEW
« no previous file with comments | « core/fxge/skia/fx_skia_device.h ('k') | fpdfsdk/fpdfformfill.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698