Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #if defined(_SKIA_SUPPORT_) | 5 #if defined(_SKIA_SUPPORT_) |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "core/fxcodec/include/fx_codec.h" | 9 #include "core/fxcodec/include/fx_codec.h" |
| 10 | 10 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 } | 619 } |
| 620 m_drawText = true; | 620 m_drawText = true; |
| 621 return true; | 621 return true; |
| 622 } | 622 } |
| 623 | 623 |
| 624 void FlushText(CFX_SkiaDeviceDriver* pDriver) { | 624 void FlushText(CFX_SkiaDeviceDriver* pDriver) { |
| 625 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix); | 625 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix); |
| 626 SkPaint skPaint; | 626 SkPaint skPaint; |
| 627 skPaint.setAntiAlias(true); | 627 skPaint.setAntiAlias(true); |
| 628 skPaint.setColor(m_fillColor); | 628 skPaint.setColor(m_fillColor); |
| 629 if (m_pFont->GetFace()) { // exclude placeholder test fonts | 629 if (m_pFont->GetFace() && m_pCache) { // exclude placeholder test fonts |
|
Lei Zhang
2016/06/29 18:19:23
Check |m_pCache| first because it's cheaper?
| |
| 630 sk_sp<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); | 630 sk_sp<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); |
| 631 skPaint.setTypeface(typeface); | 631 skPaint.setTypeface(typeface); |
| 632 } | 632 } |
| 633 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 633 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 634 skPaint.setTextSize(m_fontSize); | 634 skPaint.setTextSize(m_fontSize); |
| 635 skPaint.setSubpixelText(true); | 635 skPaint.setSubpixelText(true); |
| 636 SkCanvas* skCanvas = pDriver->SkiaCanvas(); | 636 SkCanvas* skCanvas = pDriver->SkiaCanvas(); |
| 637 skCanvas->save(); | 637 skCanvas->save(); |
| 638 skCanvas->concat(skMatrix); | 638 skCanvas->concat(skMatrix); |
| 639 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, | 639 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 const FXTEXT_CHARPOS* pCharPos, | 998 const FXTEXT_CHARPOS* pCharPos, |
| 999 CFX_Font* pFont, | 999 CFX_Font* pFont, |
| 1000 CFX_FontCache* pCache, | 1000 CFX_FontCache* pCache, |
| 1001 const CFX_Matrix* pObject2Device, | 1001 const CFX_Matrix* pObject2Device, |
| 1002 FX_FLOAT font_size, | 1002 FX_FLOAT font_size, |
| 1003 uint32_t color) { | 1003 uint32_t color) { |
| 1004 if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, | 1004 if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, |
| 1005 font_size, color, this)) { | 1005 font_size, color, this)) { |
| 1006 return TRUE; | 1006 return TRUE; |
| 1007 } | 1007 } |
| 1008 sk_sp<SkTypeface> typeface(SkSafeRef(pCache->GetDeviceCache(pFont))); | 1008 sk_sp<SkTypeface> typeface( |
| 1009 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); | |
| 1009 SkPaint paint; | 1010 SkPaint paint; |
| 1010 paint.setAntiAlias(true); | 1011 paint.setAntiAlias(true); |
| 1011 paint.setColor(color); | 1012 paint.setColor(color); |
| 1012 paint.setTypeface(typeface); | 1013 paint.setTypeface(typeface); |
| 1013 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1014 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 1014 paint.setTextSize(font_size); | 1015 paint.setTextSize(font_size); |
| 1015 paint.setSubpixelText(true); | 1016 paint.setSubpixelText(true); |
| 1016 m_pCanvas->save(); | 1017 m_pCanvas->save(); |
| 1017 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); | 1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); |
| 1018 m_pCanvas->concat(skMatrix); | 1019 m_pCanvas->concat(skMatrix); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1436 void*& handle, | 1437 void*& handle, |
| 1437 int blend_type) { | 1438 int blend_type) { |
| 1438 DebugValidate(m_pBitmap, m_pOriDevice); | 1439 DebugValidate(m_pBitmap, m_pOriDevice); |
| 1439 SkColorType colorType = pSource->IsAlphaMask() | 1440 SkColorType colorType = pSource->IsAlphaMask() |
| 1440 ? SkColorType::kAlpha_8_SkColorType | 1441 ? SkColorType::kAlpha_8_SkColorType |
| 1441 : SkColorType::kGray_8_SkColorType; | 1442 : SkColorType::kGray_8_SkColorType; |
| 1442 SkAlphaType alphaType = | 1443 SkAlphaType alphaType = |
| 1443 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; | 1444 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; |
| 1444 SkColorTable* ct = nullptr; | 1445 SkColorTable* ct = nullptr; |
| 1445 void* buffer = pSource->GetBuffer(); | 1446 void* buffer = pSource->GetBuffer(); |
| 1447 if (!buffer) | |
| 1448 return FALSE; | |
| 1446 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1449 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
| 1447 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; | 1450 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; |
| 1448 int width = pSource->GetWidth(); | 1451 int width = pSource->GetWidth(); |
| 1449 int height = pSource->GetHeight(); | 1452 int height = pSource->GetHeight(); |
| 1450 int rowBytes = pSource->GetPitch(); | 1453 int rowBytes = pSource->GetPitch(); |
| 1451 switch (pSource->GetBPP()) { | 1454 switch (pSource->GetBPP()) { |
| 1452 case 1: { | 1455 case 1: { |
| 1453 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height)); | 1456 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height)); |
| 1454 uint8_t* dst8Pixels = dst8Storage.get(); | 1457 uint8_t* dst8Pixels = dst8Storage.get(); |
| 1455 for (int y = 0; y < height; ++y) { | 1458 for (int y = 0; y < height; ++y) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1519 ct->unref(); | 1522 ct->unref(); |
| 1520 DebugValidate(m_pBitmap, m_pOriDevice); | 1523 DebugValidate(m_pBitmap, m_pOriDevice); |
| 1521 return TRUE; | 1524 return TRUE; |
| 1522 } | 1525 } |
| 1523 | 1526 |
| 1524 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1527 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
| 1525 return FALSE; | 1528 return FALSE; |
| 1526 } | 1529 } |
| 1527 | 1530 |
| 1528 void CFX_SkiaDeviceDriver::PreMultiply() { | 1531 void CFX_SkiaDeviceDriver::PreMultiply() { |
| 1529 void* buffer = m_pBitmap->GetBuffer(); | 1532 PreMultiply(m_pBitmap); |
| 1533 } | |
| 1534 | |
| 1535 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | |
| 1536 void* buffer = pDIBitmap->GetBuffer(); | |
| 1530 if (!buffer) | 1537 if (!buffer) |
| 1531 return; | 1538 return; |
| 1532 if (m_pBitmap->GetBPP() != 32) { | 1539 if (pDIBitmap->GetBPP() != 32) { |
| 1533 return; | 1540 return; |
| 1534 } | 1541 } |
| 1535 int height = m_pBitmap->GetHeight(); | 1542 int height = pDIBitmap->GetHeight(); |
| 1536 int width = m_pBitmap->GetWidth(); | 1543 int width = pDIBitmap->GetWidth(); |
| 1537 int rowBytes = m_pBitmap->GetPitch(); | 1544 int rowBytes = pDIBitmap->GetPitch(); |
| 1538 SkImageInfo unpremultipliedInfo = | 1545 SkImageInfo unpremultipliedInfo = |
| 1539 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); | 1546 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); |
| 1540 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); | 1547 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); |
| 1541 SkImageInfo premultipliedInfo = | 1548 SkImageInfo premultipliedInfo = |
| 1542 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); | 1549 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); |
| 1543 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); | 1550 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); |
| 1544 unpremultiplied.readPixels(premultiplied); | 1551 unpremultiplied.readPixels(premultiplied); |
| 1545 DebugVerifyBitmapIsPreMultiplied(buffer, width, height); | 1552 DebugVerifyBitmapIsPreMultiplied(buffer, width, height); |
| 1546 } | 1553 } |
| 1547 | 1554 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1601 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1608 CFX_FxgeDevice::~CFX_FxgeDevice() { |
| 1602 if (m_bOwnedBitmap && GetBitmap()) | 1609 if (m_bOwnedBitmap && GetBitmap()) |
| 1603 delete GetBitmap(); | 1610 delete GetBitmap(); |
| 1604 } | 1611 } |
| 1605 | 1612 |
| 1606 void CFX_FxgeDevice::PreMultiply() { | 1613 void CFX_FxgeDevice::PreMultiply() { |
| 1607 (static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()))->PreMultiply(); | 1614 (static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()))->PreMultiply(); |
| 1608 } | 1615 } |
| 1609 | 1616 |
| 1610 #endif | 1617 #endif |
| OLD | NEW |