Assume pdf_use_skia=true in //core/fxge/skia Assumes sources in //core/fxge/skia only are used when pdf_use_skia=true (that is, _SKIA_SUPPORT_ is defined). This means that any code conditional on _SKIA_SUPPORT_ can be made unconditional, and any code conditional on _SKIA_SUPPORT_PATHS_ can be removed. Bug: pdfium:1941 Change-Id: I609c81014e7a9fbab7120a6b8f2aec877b9991d1 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/101831 Reviewed-by: Nigi <nigi@chromium.org> Commit-Queue: K. Moon <kmoon@chromium.org>
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index da644fc..8d41381 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn
@@ -142,7 +142,7 @@ ] } - if (pdf_use_skia || pdf_use_skia_paths) { + if (pdf_use_skia) { sources += [ "skia/fx_skia_device.cpp" ] deps += [ "//skia" ] } @@ -239,7 +239,7 @@ deps = [] pdfium_root_dir = "../../" - if (pdf_use_skia || pdf_use_skia_paths) { + if (pdf_use_skia) { sources += [ "skia/fx_skia_device_embeddertest.cpp" ] deps += [ ":fxge",
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 39ffdae..ef51a8f 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp
@@ -26,6 +26,7 @@ #include "core/fxcrt/cfx_bitstream.h" #include "core/fxcrt/data_vector.h" #include "core/fxcrt/fx_2d_size.h" +#include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_memory_wrappers.h" #include "core/fxcrt/fx_system.h" #include "core/fxcrt/stl_util.h" @@ -36,10 +37,10 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/cfx_textrenderoptions.h" -#include "core/fxge/dib/cfx_bitmapcomposer.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/dib/cfx_imagerenderer.h" #include "core/fxge/dib/cfx_imagestretcher.h" +#include "core/fxge/dib/cstretchengine.h" #include "core/fxge/dib/fx_dib.h" #include "core/fxge/text_char_pos.h" #include "third_party/base/check.h" @@ -51,12 +52,15 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkClipOp.h" +#include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkColorType.h" #include "third_party/skia/include/core/SkImage.h" +#include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPathEffect.h" +#include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkRSXform.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkSamplingOptions.h" @@ -68,129 +72,8 @@ #include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/pathops/SkPathOps.h" -#if defined(_SKIA_SUPPORT_PATHS_) -#include "core/fxge/cfx_cliprgn.h" -#endif - -#if defined(_SKIA_SUPPORT_) -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxge/dib/cstretchengine.h" -#include "third_party/skia/include/core/SkColorFilter.h" -#include "third_party/skia/include/core/SkMaskFilter.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" -#endif - namespace { -#if defined(_SKIA_SUPPORT_PATHS_) -void RgbByteOrderTransferBitmap(const RetainPtr<CFX_DIBitmap>& pBitmap, - int width, - int height, - const RetainPtr<CFX_DIBBase>& pSrcBitmap, - int src_left, - int src_top) { - if (!pBitmap) - return; - - int dest_left = 0; - int dest_top = 0; - if (!pBitmap->GetOverlapRect(dest_left, dest_top, width, height, - pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), - src_left, src_top, nullptr)) { - return; - } - - const int Bpp = pBitmap->GetBPP() / 8; - const FXDIB_Format dest_format = pBitmap->GetFormat(); - const FXDIB_Format src_format = pSrcBitmap->GetFormat(); - const int dest_pitch = pBitmap->GetPitch(); - - const size_t dest_x_offset = Fx2DSizeOrDie(dest_left, Bpp); - const size_t dest_y_offset = Fx2DSizeOrDie(dest_top, dest_pitch); - - pdfium::span<uint8_t> dest_span = - pBitmap->GetBuffer().subspan(dest_y_offset).subspan(dest_x_offset); - if (dest_format == src_format) { - const size_t src_x_offset = Fx2DSizeOrDie(src_left, Bpp); - for (int row = 0; row < height; row++) { - uint8_t* dest_scan = dest_span.data(); - const uint8_t* src_scan = - pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data(); - if (Bpp == 4) { - for (int col = 0; col < width; col++) { - FXARGB_SETRGBORDERDIB(dest_scan, - *reinterpret_cast<const uint32_t*>(src_scan)); - dest_scan += 4; - src_scan += 4; - } - } else { - for (int col = 0; col < width; col++) { - *dest_scan++ = src_scan[2]; - *dest_scan++ = src_scan[1]; - *dest_scan++ = src_scan[0]; - src_scan += 3; - } - } - dest_span = dest_span.subspan(dest_pitch); - } - return; - } - - if (dest_format == FXDIB_Format::kRgb) { - DCHECK_EQ(src_format, FXDIB_Format::kRgb32); - const size_t src_x_offset = Fx2DSizeOrDie(src_left, 4); - for (int row = 0; row < height; row++) { - uint8_t* dest_scan = dest_span.data(); - const uint8_t* src_scan = - pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data(); - for (int col = 0; col < width; col++) { - *dest_scan++ = src_scan[2]; - *dest_scan++ = src_scan[1]; - *dest_scan++ = src_scan[0]; - src_scan += 4; - } - dest_span = dest_span.subspan(dest_pitch); - } - return; - } - - DCHECK(dest_format == FXDIB_Format::kArgb || - dest_format == FXDIB_Format::kRgb32); - if (src_format == FXDIB_Format::kRgb) { - const size_t src_x_offset = Fx2DSizeOrDie(src_left, 3); - for (int row = 0; row < height; row++) { - uint8_t* dest_scan = dest_span.data(); - const uint8_t* src_scan = - pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data(); - for (int col = 0; col < width; col++) { - FXARGB_SETDIB(dest_scan, - ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); - dest_scan += 4; - src_scan += 3; - } - dest_span = dest_span.subspan(dest_pitch); - } - return; - } - if (src_format != FXDIB_Format::kRgb32) - return; - DCHECK_EQ(dest_format, FXDIB_Format::kArgb); - const size_t src_x_offset = Fx2DSizeOrDie(src_left, 4); - for (int row = 0; row < height; row++) { - uint8_t* dest_scan = dest_span.data(); - const uint8_t* src_scan = - pSrcBitmap->GetScanline(src_top + row).subspan(src_x_offset).data(); - for (int col = 0; col < width; col++) { - FXARGB_SETDIB(dest_scan, - ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); - src_scan += 4; - dest_scan += 4; - } - dest_span = dest_span.subspan(dest_pitch); - } -} -#endif // defined(_SKIA_SUPPORT_PATHS_) - #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents #if SHOW_SKIA_PATH #define SHOW_SKIA_PATH_SHORTHAND 0 // set to 1 for abbreviated path contents @@ -295,7 +178,6 @@ #endif // DRAW_SKIA_CLIP -#if defined(_SKIA_SUPPORT_) bool IsRGBColorGrayScale(uint32_t color) { return FXARGB_R(color) == FXARGB_G(color) && FXARGB_R(color) == FXARGB_B(color); @@ -343,7 +225,6 @@ } } } -#endif // defined(_SKIA_SUPPORT_) SkColorType Get32BitSkColorType(bool is_rgb_byte_order) { return is_rgb_byte_order ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType; @@ -673,7 +554,6 @@ clip->lineTo(IntersectSides(rectPts[maxBounds], slope, startEdgePt)); } -#if defined(_SKIA_SUPPORT_) void SetBitmapMatrix(const CFX_Matrix& m, int width, int height, @@ -838,7 +718,6 @@ bitmap->Clear(color); return bitmap; } -#endif // defined(_SKIA_SUPPORT_) } // namespace @@ -870,7 +749,6 @@ BlendMode blend_type) { if (m_debugDisable) return false; - Dump(__func__); int drawIndex = std::min(m_drawIndex, m_commands.size()); if (Accumulator::kText == m_type || drawIndex != m_commandIndex || (Accumulator::kPath == m_type && @@ -906,7 +784,6 @@ } void FlushPath() { - Dump(__func__); SkMatrix skMatrix = ToSkMatrix(m_drawMatrix); SkPaint skPaint; skPaint.setAntiAlias(!m_fillOptions.aliased_path); @@ -938,18 +815,12 @@ } skPaint.setStyle(SkPaint::kFill_Style); skPaint.setColor(m_fillColor); -#if defined(_SKIA_SUPPORT_PATHS_) - m_pDriver->PreMultiply(); -#endif DebugShowSkiaDrawPath(m_pDriver, skCanvas, skPaint, *fillPath); skCanvas->drawPath(*fillPath, skPaint); } if (stroke_alpha && do_stroke) { skPaint.setStyle(SkPaint::kStroke_Style); skPaint.setColor(m_strokeColor); -#if defined(_SKIA_SUPPORT_PATHS_) - m_pDriver->PreMultiply(); -#endif if (!m_skPath.isLastContourClosed() && IsPathAPoint(m_skPath)) { DCHECK_GE(m_skPath.countPoints(), 1); skCanvas->drawPoint(m_skPath.getPoint(0), skPaint); @@ -1004,7 +875,6 @@ const CFX_TextRenderOptions& options) { if (m_debugDisable) return false; - Dump(__func__); float scaleX = 1; bool oneAtATime = false; bool hasRSX = HasRSX(nChars, pCharPos, &scaleX, &oneAtATime); @@ -1090,7 +960,6 @@ } void FlushText() { - Dump(__func__); SkPaint skPaint; skPaint.setAntiAlias(true); skPaint.setColor(m_fillColor); @@ -1113,9 +982,6 @@ SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix, flip); skCanvas->concat(skMatrix); const SkTDArray<uint16_t>& glyphs = m_charDetails.GetGlyphs(); -#if defined(_SKIA_SUPPORT_PATHS_) - m_pDriver->PreMultiply(); -#endif if (m_rsxform.size()) { sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromRSXform( glyphs.begin(), glyphs.size_bytes(), m_rsxform.begin(), font, @@ -1146,7 +1012,6 @@ const CFX_FillRenderOptions& fill_options) { if (m_debugDisable) return false; - Dump(__func__); SkPath skClipPath; if (path.GetPoints().size() == 5 || path.GetPoints().size() == 4) { absl::optional<CFX_FloatRect> maybe_rectf = path.GetRect(pMatrix); @@ -1204,7 +1069,6 @@ const CFX_GraphStateData* pGraphState) { if (m_debugDisable) return false; - Dump(__func__); SkPath skPath = BuildPath(path); SkMatrix skMatrix = ToSkMatrix(*pMatrix); SkPaint skPaint; @@ -1241,7 +1105,6 @@ bool ClipSave() { if (m_debugDisable) return false; - Dump(__func__); int count = m_commands.size(); if (m_commandIndex < count) { if (Clip::kSave == m_commands[m_commandIndex]) { @@ -1264,7 +1127,6 @@ bool ClipRestore() { if (m_debugDisable) return false; - Dump(__func__); for (int i = m_commandIndex - 1; i > 0; --i) { if (m_commands[i] == Clip::kSave) { @@ -1357,7 +1219,6 @@ void Flush() { if (m_debugDisable) return; - Dump(__func__); if (Accumulator::kPath == m_type || Accumulator::kText == m_type) { AdjustClip(std::min(m_drawIndex, m_commands.size())); Accumulator::kPath == m_type ? FlushPath() : FlushText(); @@ -1371,213 +1232,6 @@ AdjustClip(m_commandIndex); // set up clip stack with any pending state } -#if SHOW_SKIA_PATH - void DumpPrefix(int index) const { - if (index != m_commandIndex && index != m_drawIndex && - index != m_clipIndex) { - printf(" "); - return; - } - printf("%c%c%c> ", index == m_commandIndex ? 'x' : '-', - index == m_drawIndex ? 'd' : '-', index == m_clipIndex ? 'c' : '-'); - } - - void DumpEndPrefix() const { - int index = m_commands.size(); - if (index != m_commandIndex && index > m_drawIndex && index != m_clipIndex) - return; - printf("%c%c%c>\n", index == m_commandIndex ? 'x' : '-', - index <= m_drawIndex ? 'd' : '-', index == m_clipIndex ? 'c' : '-'); - } -#endif // SHOW_SKIA_PATH - - void Dump(const char* where) const { -#if SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - if (m_debugDisable) - return; - printf( - "\n%s\nSkia Save Count %d Agg Save Stack/Count %d/%d" - " Cache Save Index/Count %d/%d\n", - where, m_pDriver->SkiaCanvas()->getSaveCount(), - (int)m_pDriver->stack().size(), AggSaveCount(m_pDriver), m_commandIndex, - CacheSaveCount(m_commands, m_commandIndex)); - printf("Cache:\n"); -#if SHOW_SKIA_PATH_SHORTHAND - bool dumpedPath = false; -#endif - for (int index = 0; index < m_commands.size(); ++index) { -#if SHOW_SKIA_PATH_SHORTHAND - if (Clip::kSave == m_commands[index] && dumpedPath) { - printf("\n"); - dumpedPath = false; - } -#endif - DumpPrefix(index); - switch (m_commands[index]) { - case Clip::kSave: - printf("Save %d\n", ++m_debugSaveCounter); - break; - case Clip::kPath: -#if SHOW_SKIA_PATH_SHORTHAND - printf("*"); - dumpedPath = true; -#else - m_clips[index].dump(); -#endif - break; - default: - printf("unknown\n"); - } - } -#if SHOW_SKIA_PATH_SHORTHAND - if (dumpedPath) - printf("\n"); -#endif - DumpEndPrefix(); - int skCanvasSaveCount = m_pDriver->SkiaCanvas()->getSaveCount(); - int cacheSaveCount = 1; - DCHECK(m_clipIndex <= m_commands.size()); - for (int index = 0; index < m_clipIndex; ++index) - cacheSaveCount += Clip::kSave == m_commands[index]; - DCHECK_EQ(skCanvasSaveCount, cacheSaveCount); -#endif // SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - } - -#if SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - static int AggSaveCount(const UnownedPtr<CFX_SkiaDeviceDriver> driver) { - FX_RECT last; - int aggSaveCount = 0; - bool foundLast = false; - for (int index = 0; index < (int)driver->stack().size(); ++index) { - if (!driver->stack()[index]) { - continue; - } - if (driver->stack()[index]->GetType() != CFX_ClipRgn::kRectI) { - aggSaveCount += 1; - foundLast = false; - continue; - } - if (!foundLast || - memcmp(&last, &driver->stack()[index]->GetBox(), sizeof(FX_RECT))) { - aggSaveCount += 1; - foundLast = true; - last = driver->stack()[index]->GetBox(); - } - } - if (driver->clip_region()) { - CFX_ClipRgn::ClipType clipType = driver->clip_region()->GetType(); - if (clipType != CFX_ClipRgn::kRectI || !foundLast || - memcmp(&last, &driver->clip_region()->GetBox(), sizeof(FX_RECT))) { - aggSaveCount += 1; - } - } - return aggSaveCount; - } - - static int CacheSaveCount(const SkTDArray<SkiaState::Clip>& commands, - int commandIndex) { - int cacheSaveCount = 0; - bool newPath = false; - for (int index = 0; index < commandIndex; ++index) { - if (Clip::kSave == commands[index]) { - newPath = true; - } else if (newPath) { - ++cacheSaveCount; - newPath = false; - } - } - return cacheSaveCount; - } -#endif // SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - - void DebugCheckClip() { -#if SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - if (m_debugDisable) - return; - int aggSaveCount = AggSaveCount(m_pDriver); - int cacheSaveCount = CacheSaveCount(m_commands, m_commandIndex); - DCHECK(m_clipIndex <= m_commands.size()); - if (aggSaveCount != cacheSaveCount) { - // may not signify a bug if counts don't match - printf("aggSaveCount %d != cacheSaveCount %d\n", aggSaveCount, - cacheSaveCount); - DumpClipStacks(); - } - for (int aggIndex = 0; aggIndex < (int)m_pDriver->stack().size(); - ++aggIndex) { - if (!m_pDriver->stack()[aggIndex]) - continue; - if (m_pDriver->stack()[aggIndex]->GetType() != CFX_ClipRgn::kRectI) - continue; - const FX_RECT& aggRect = m_pDriver->stack()[aggIndex]->GetBox(); - SkRect skRect = SkRect::MakeLTRB(aggRect.left, aggRect.top, aggRect.right, - aggRect.bottom); - bool foundMatch = false; - for (int skIndex = 0; skIndex < m_commandIndex; ++skIndex) { - if (Clip::kPath != m_commands[skIndex]) - continue; - const SkPath& clip = m_clips[skIndex]; - SkRect bounds; - if (!clip.isRect(&bounds)) - continue; - bounds.roundOut(&bounds); - if (skRect == bounds) { - foundMatch = true; - break; - } - } - if (!foundMatch) { - DumpClipStacks(); - NOTREACHED(); - } - } -#endif // SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - } - -#if SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - void DumpClipStacks() const { - if (m_debugDisable) - return; - printf("\ncache\n"); - for (int index = 0; index < m_commandIndex; ++index) { - DumpPrefix(index); - switch (m_commands[index]) { - case Clip::kSave: - printf("Save\n"); - break; - case Clip::kPath: - m_clips[index].dump(); - break; - default: - printf("unknown\n"); - } - } - printf("\nagg\n"); - for (int index = 0; index < (int)m_pDriver->stack().size(); ++index) { - if (!m_pDriver->stack()[index]) { - printf("null\n"); - continue; - } - CFX_ClipRgn::ClipType clipType = m_pDriver->stack()[index]->GetType(); - const FX_RECT& box = m_pDriver->stack()[index]->GetBox(); - printf("stack rect: %d,%d,%d,%d mask=%s\n", box.left, box.top, box.right, - box.bottom, - CFX_ClipRgn::kMaskF == clipType - ? "1" - : CFX_ClipRgn::kRectI == clipType ? "0" : "?"); - } - if (m_pDriver->clip_region()) { - const FX_RECT& box = m_pDriver->clip_region()->GetBox(); - CFX_ClipRgn::ClipType clipType = m_pDriver->clip_region()->GetType(); - printf("clip rect: %d,%d,%d,%d mask=%s\n", box.left, box.top, box.right, - box.bottom, - CFX_ClipRgn::kMaskF == clipType - ? "1" - : CFX_ClipRgn::kRectI == clipType ? "0" : "?"); - } - } -#endif // SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_PATHS_) - private: class CharDetail { public: @@ -1646,17 +1300,8 @@ bool m_groupKnockout = false; bool m_isSubstFontBold = false; bool m_debugDisable = false; // turn off cache for debugging -#if SHOW_SKIA_PATH - public: - mutable int m_debugSaveCounter = 0; - static int m_debugInitCounter; -#endif }; -#if SHOW_SKIA_PATH -int SkiaState::m_debugInitCounter; -#endif - // convert a stroking path to scanlines void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, const CFX_GraphStateData* pGraphState, @@ -1731,9 +1376,6 @@ m_pBackdropBitmap(pBackdropBitmap), m_pRecorder(nullptr), m_pCache(std::make_unique<SkiaState>(this)), -#if defined(_SKIA_SUPPORT_PATHS_) - m_pClipRgn(nullptr), -#endif m_bRgbByteOrder(bRgbByteOrder), m_bGroupKnockout(bGroupKnockout) { SkBitmap skBitmap; @@ -1756,7 +1398,6 @@ m_pCanvas = new SkCanvas(skBitmap); } -#if defined(_SKIA_SUPPORT_) CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) : m_pRecorder(recorder), m_pCache(std::make_unique<SkiaState>(this)), @@ -1771,7 +1412,6 @@ m_pBitmap = MakeDebugBitmap(width, height, kMagenta); m_pBackdropBitmap = MakeDebugBitmap(width, height, kGreen); } -#endif // defined(_SKIA_SUPPORT_) CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { Flush(); @@ -1864,9 +1504,6 @@ } if (oneAtATime) useRSXform = false; -#if defined(_SKIA_SUPPORT_PATHS_) - m_pBitmap->PreMultiply(); -#endif if (useRSXform) { SkTDArray<SkRSXform> xforms; xforms.resize(nChars); @@ -1947,7 +1584,6 @@ int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { switch (caps_id) { -#if defined(_SKIA_SUPPORT_) case FXDC_PIXEL_WIDTH: return m_pCanvas->imageInfo().width(); case FXDC_PIXEL_HEIGHT: @@ -1961,34 +1597,6 @@ return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT | FXRC_FILLSTROKE_PATH | FXRC_SHADING; -#endif // defined(_SKIA_SUPPORT_) - -#if defined(_SKIA_SUPPORT_PATHS_) - case FXDC_PIXEL_WIDTH: - return m_pBitmap->GetWidth(); - case FXDC_PIXEL_HEIGHT: - return m_pBitmap->GetHeight(); - case FXDC_BITS_PIXEL: - return m_pBitmap->GetBPP(); - case FXDC_HORZ_SIZE: - case FXDC_VERT_SIZE: - return 0; - case FXDC_RENDER_CAPS: { - int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | - FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_SHADING; - if (m_pBitmap->IsAlphaFormat()) { - flags |= FXRC_ALPHA_OUTPUT; - } else if (m_pBitmap->IsMaskFormat()) { - if (m_pBitmap->GetBPP() == 1) { - flags |= FXRC_BITMASK_OUTPUT; - } else { - flags |= FXRC_BYTEMASK_OUTPUT; - } - } - return flags; - } -#endif // defined(_SKIA_SUPPORT_PATHS_) - default: NOTREACHED(); return 0; @@ -1996,80 +1604,19 @@ } void CFX_SkiaDeviceDriver::SaveState() { - m_pCache->DebugCheckClip(); if (!m_pCache->ClipSave()) m_pCanvas->save(); - -#if defined(_SKIA_SUPPORT_PATHS_) -#if SHOW_SKIA_PATH - printf("SaveState %zd\n", stack().size()); -#endif - std::unique_ptr<CFX_ClipRgn> pClip; - if (m_pClipRgn) - pClip = std::make_unique<CFX_ClipRgn>(*m_pClipRgn); - m_StateStack.push_back(std::move(pClip)); -#endif // defined(_SKIA_SUPPORT_PATHS_) } void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { -#if defined(_SKIA_SUPPORT_PATHS_) - m_pClipRgn.reset(); - - if (m_StateStack.empty()) - return; -#else if (m_pCache->IsEmpty()) return; -#endif if (!m_pCache->ClipRestore()) m_pCanvas->restore(); if (bKeepSaved && !m_pCache->ClipSave()) m_pCanvas->save(); -#if defined(_SKIA_SUPPORT_PATHS_) -#if SHOW_SKIA_PATH - printf("RestoreState %zd %s\n", m_StateStack.size(), - bKeepSaved ? "bKeepSaved" : ""); -#endif - if (bKeepSaved) { - if (m_StateStack.back()) - m_pClipRgn = std::make_unique<CFX_ClipRgn>(*m_StateStack.back()); - } else { - m_pClipRgn = std::move(m_StateStack.back()); - m_StateStack.pop_back(); - } - m_pCache->DebugCheckClip(); -#endif // defined(_SKIA_SUPPORT_PATHS_) } -#if defined(_SKIA_SUPPORT_PATHS_) -void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, - const SkPath& path) { - FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1, - clipBox.bottom + 1); - path_rect.Intersect(m_pClipRgn->GetBox()); - auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>(); - pThisLayer->Create(path_rect.Width(), path_rect.Height(), - FXDIB_Format::k8bppMask); - pThisLayer->Clear(0); - - SkImageInfo imageInfo = - SkImageInfo::Make(pThisLayer->GetWidth(), pThisLayer->GetHeight(), - SkColorType::kAlpha_8_SkColorType, kOpaque_SkAlphaType); - SkBitmap bitmap; - bitmap.installPixels(imageInfo, pThisLayer->GetBuffer().data(), - pThisLayer->GetPitch()); - auto canvas = std::make_unique<SkCanvas>(bitmap); - canvas->translate( - -path_rect.left, - -path_rect.top); // FIXME(caryclark) wrong sign(s)? upside down? - SkPaint paint; - paint.setAntiAlias(!m_FillOptions.aliased_path); - canvas->drawPath(path, paint); - m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, - std::move(pThisLayer)); -} -#endif // defined(_SKIA_SUPPORT_PATHS_) - bool CFX_SkiaDeviceDriver::SetClip_PathFill( const CFX_Path& path, // path info const CFX_Matrix* pObject2Device, // flips object's y-axis @@ -2078,12 +1625,6 @@ CFX_Matrix identity; const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; bool cached = m_pCache->SetClipFill(path, deviceMatrix, fill_options); -#if defined(_SKIA_SUPPORT_PATHS_) - if (!m_pClipRgn) { - m_pClipRgn = std::make_unique<CFX_ClipRgn>( - GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); - } -#endif if (path.GetPoints().size() == 5 || path.GetPoints().size() == 4) { absl::optional<CFX_FloatRect> maybe_rectf = path.GetRect(deviceMatrix); if (maybe_rectf.has_value()) { @@ -2099,10 +1640,6 @@ m_pCanvas->clipRect(skClipRect, SkClipOp::kIntersect, true); } -#if defined(_SKIA_SUPPORT_PATHS_) - FX_RECT rect = rectf.GetOuterRect(); - m_pClipRgn->IntersectRect(rect); -#endif DebugShowCanvasClip(this, m_pCanvas); return true; } @@ -2116,11 +1653,6 @@ DebugDrawSkiaClipPath(m_pCanvas, skClipPath); m_pCanvas->clipPath(skClipPath, SkClipOp::kIntersect, true); } -#if defined(_SKIA_SUPPORT_PATHS_) - FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT)); - SetClipMask(clipBox, skClipPath); -#endif DebugShowCanvasClip(this, m_pCanvas); return true; } @@ -2132,12 +1664,6 @@ ) { bool cached = m_pCache->SetClipStroke(path, pObject2Device, pGraphState); -#if defined(_SKIA_SUPPORT_PATHS_) - if (!m_pClipRgn) { - m_pClipRgn = std::make_unique<CFX_ClipRgn>( - GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); - } -#endif // build path data SkPath skPath = BuildPath(path); SkMatrix skMatrix = ToSkMatrix(*pObject2Device); @@ -2150,11 +1676,6 @@ DebugDrawSkiaClipPath(m_pCanvas, dst_path); m_pCanvas->clipPath(dst_path, SkClipOp::kIntersect, true); } -#if defined(_SKIA_SUPPORT_PATHS_) - FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT)); - SetClipMask(clipBox, dst_path); -#endif DebugShowCanvasClip(this, m_pCanvas); return true; } @@ -2209,18 +1730,12 @@ } skPaint.setStyle(SkPaint::kFill_Style); skPaint.setColor(fill_color); -#if defined(_SKIA_SUPPORT_PATHS_) - m_pBitmap->PreMultiply(); -#endif DebugShowSkiaDrawPath(this, m_pCanvas, skPaint, *fillPath); m_pCanvas->drawPath(*fillPath, skPaint); } if (is_paint_stroke && do_stroke) { skPaint.setStyle(SkPaint::kStroke_Style); skPaint.setColor(stroke_color); -#if defined(_SKIA_SUPPORT_PATHS_) - m_pBitmap->PreMultiply(); -#endif if (!skPath.isLastContourClosed() && IsPathAPoint(skPath)) { DCHECK_GE(skPath.countPoints(), 1); m_pCanvas->drawPoint(skPath.getPoint(0), skPaint); @@ -2446,22 +1961,12 @@ } bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { -#if defined(_SKIA_SUPPORT_PATHS_) - if (!m_pClipRgn) { - pRect->left = pRect->top = 0; - pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH); - pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT); - return true; - } - *pRect = m_pClipRgn->GetBox(); -#else // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead pRect->left = 0; pRect->top = 0; const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); pRect->right = canvasSize.width(); pRect->bottom = canvasSize.height(); -#endif return true; } @@ -2473,7 +1978,6 @@ uint8_t* srcBuffer = m_pBitmap->GetBuffer().data(); if (!srcBuffer) return true; -#if defined(_SKIA_SUPPORT_) m_pCache->FlushForDraw(); int srcWidth = m_pBitmap->GetWidth(); int srcHeight = m_pBitmap->GetHeight(); @@ -2497,39 +2001,6 @@ SkRect::MakeXYWH(left, top, dstWidth, dstHeight), SkSamplingOptions(), /*paint=*/nullptr); return true; -#endif // defined(_SKIA_SUPPORT_) - -#if defined(_SKIA_SUPPORT_PATHS_) - Flush(); - m_pBitmap->UnPreMultiply(); - FX_RECT rect(left, top, left + pBitmap->GetWidth(), - top + pBitmap->GetHeight()); - RetainPtr<CFX_DIBitmap> pBack; - if (m_pBackdropBitmap) { - pBack = m_pBackdropBitmap->ClipTo(rect); - if (!pBack) - return true; - - pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), - m_pBitmap, 0, 0, BlendMode::kNormal, nullptr, false); - } else { - pBack = m_pBitmap->ClipTo(rect); - if (!pBack) - return true; - } - - bool bRet = true; - left = std::min(left, 0); - top = std::min(top, 0); - if (m_bRgbByteOrder) { - RgbByteOrderTransferBitmap(pBitmap, rect.Width(), rect.Height(), pBack, - left, top); - } else { - bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, - left, top); - } - return bRet; -#endif // defined(_SKIA_SUPPORT_PATHS_) } RetainPtr<CFX_DIBitmap> CFX_SkiaDeviceDriver::GetBackDrop() { @@ -2545,7 +2016,6 @@ if (!m_pBitmap || m_pBitmap->GetBuffer().empty()) return true; -#if defined(_SKIA_SUPPORT_) CFX_Matrix m = CFX_RenderDevice::GetFlipMatrix( pBitmap->GetWidth(), pBitmap->GetHeight(), left, top); @@ -2554,20 +2024,6 @@ sampling_options.bNoSmoothing = true; return StartDIBitsSkia(pBitmap, 0xFF, argb, m, sampling_options, blend_type); -#endif - -#if defined(_SKIA_SUPPORT_PATHS_) - Flush(); - if (pBitmap->IsMaskFormat()) { - return m_pBitmap->CompositeMask(left, top, src_rect.Width(), - src_rect.Height(), pBitmap, argb, - src_rect.left, src_rect.top, blend_type, - m_pClipRgn.get(), m_bRgbByteOrder); - } - return m_pBitmap->CompositeBitmap( - left, top, src_rect.Width(), src_rect.Height(), pBitmap, src_rect.left, - src_rect.top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder); -#endif // defined(_SKIA_SUPPORT_PATHS_) } bool CFX_SkiaDeviceDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, @@ -2579,7 +2035,6 @@ const FX_RECT* pClipRect, const FXDIB_ResampleOptions& options, BlendMode blend_type) { -#if defined(_SKIA_SUPPORT_) m_pCache->FlushForDraw(); if (m_pBitmap->GetBuffer().empty()) return true; @@ -2596,30 +2051,6 @@ sampling_options.bNoSmoothing = true; return StartDIBitsSkia(pSource, 0xFF, argb, m, sampling_options, blend_type); -#endif // defined(_SKIA_SUPPORT_) - -#if defined(_SKIA_SUPPORT_PATHS_) - if (dest_width == pSource->GetWidth() && - dest_height == pSource->GetHeight()) { - FX_RECT rect(0, 0, dest_width, dest_height); - return SetDIBits(pSource, argb, rect, dest_left, dest_top, blend_type); - } - Flush(); - FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, - dest_top + dest_height); - dest_rect.Normalize(); - FX_RECT dest_clip = dest_rect; - dest_clip.Intersect(*pClipRect); - CFX_BitmapComposer composer; - composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false, - false, false, m_bRgbByteOrder, blend_type); - dest_clip.Offset(-dest_rect.left, -dest_rect.top); - CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, - dest_clip, options); - if (stretcher.Start()) - stretcher.Continue(nullptr); - return true; -#endif // defined(_SKIA_SUPPORT_PATHS_) } bool CFX_SkiaDeviceDriver::StartDIBits( @@ -2630,45 +2061,20 @@ const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { -#if defined(_SKIA_SUPPORT_) return StartDIBitsSkia(pSource, bitmap_alpha, argb, matrix, options, blend_type); -#endif // defined(_SKIA_SUPPORT_) - -#if defined(_SKIA_SUPPORT_PATHS_) - Flush(); - if (m_pBitmap->GetBuffer().empty()) - return true; - - *handle = std::make_unique<CFX_ImageRenderer>( - m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, matrix, options, - m_bRgbByteOrder); - return true; -#endif // defined(_SKIA_SUPPORT_PATHS_) } bool CFX_SkiaDeviceDriver::ContinueDIBits(CFX_ImageRenderer* handle, PauseIndicatorIface* pPause) { -#if defined(_SKIA_SUPPORT_) m_pCache->FlushForDraw(); return false; -#endif - -#if defined(_SKIA_SUPPORT_PATHS_) - Flush(); - if (m_pBitmap->GetBuffer().empty()) { - return true; - } - return handle->Continue(pPause); -#endif } -#if defined(_SKIA_SUPPORT_) void CFX_SkiaDeviceDriver::PreMultiply( const RetainPtr<CFX_DIBitmap>& pDIBitmap) { pDIBitmap->PreMultiply(); } -#endif void CFX_DIBitmap::PreMultiply() { if (this->GetBPP() != 32) @@ -2723,7 +2129,6 @@ premultiplied.readPixels(unpremultiplied); } -#if defined(_SKIA_SUPPORT_) bool CFX_SkiaDeviceDriver::DrawBitsWithMask( const RetainPtr<CFX_DIBBase>& pSource, const RetainPtr<CFX_DIBBase>& pMask, @@ -2801,16 +2206,7 @@ void CFX_SkiaDeviceDriver::Clear(uint32_t color) { m_pCanvas->clear(color); } -#endif // defined(_SKIA_SUPPORT_) -void CFX_SkiaDeviceDriver::Dump() const { -#if SHOW_SKIA_PATH && defined(_SKIA_SUPPORT_) - if (m_pCache) - m_pCache->Dump(__func__); -#endif -} - -#if defined(_SKIA_SUPPORT_) void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { if (m_pBackdropBitmap) m_pBackdropBitmap->DebugVerifyBitmapIsPreMultiplied(); @@ -2888,9 +2284,7 @@ DebugValidate(m_pBitmap, m_pBackdropBitmap); return true; } -#endif -#if defined(_SKIA_SUPPORT_) void CFX_DefaultRenderDevice::Clear(uint32_t color) { CFX_SkiaDeviceDriver* skDriver = static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); @@ -2905,7 +2299,6 @@ SetDeviceDriver(std::make_unique<CFX_SkiaDeviceDriver>(recorder.get())); return recorder; } -#endif // defined(_SKIA_SUPPORT_) bool CFX_DefaultRenderDevice::AttachSkiaImpl( RetainPtr<CFX_DIBitmap> pBitmap, @@ -2921,14 +2314,12 @@ return true; } -#if defined(_SKIA_SUPPORT_) bool CFX_DefaultRenderDevice::AttachRecorder(SkPictureRecorder* recorder) { if (!recorder) return false; SetDeviceDriver(std::make_unique<CFX_SkiaDeviceDriver>(recorder)); return true; } -#endif bool CFX_DefaultRenderDevice::CreateSkia( int width, @@ -2945,7 +2336,6 @@ return true; } -#if defined(_SKIA_SUPPORT_) void CFX_DefaultRenderDevice::DebugVerifyBitmapIsPreMultiplied() const { #ifdef SK_DEBUG CFX_SkiaDeviceDriver* skDriver = @@ -2972,7 +2362,6 @@ } return false; } -#endif // defined(_SKIA_SUPPORT_) void CFX_DIBBase::DebugVerifyBufferIsPreMultiplied(void* arg) const { #ifdef SK_DEBUG
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index 3a8fca6..8ddee6c 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h
@@ -5,21 +5,16 @@ #ifndef CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_ #define CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_ -#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) - #include <memory> -#include <vector> #include "core/fxcrt/retain_ptr.h" #include "core/fxge/cfx_fillrenderoptions.h" #include "core/fxge/cfx_path.h" #include "core/fxge/renderdevicedriver_iface.h" -class CFX_ClipRgn; class SkCanvas; class SkMatrix; class SkPaint; -class SkPath; class SkPictureRecorder; class SkiaState; class TextCharPos; @@ -30,9 +25,7 @@ bool bRgbByteOrder, RetainPtr<CFX_DIBitmap> pBackdropBitmap, bool bGroupKnockout); -#if defined(_SKIA_SUPPORT_) explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder); -#endif ~CFX_SkiaDeviceDriver() override; /** Options */ @@ -92,7 +85,6 @@ int dest_left, int dest_top, BlendMode blend_type) override; -#if defined(_SKIA_SUPPORT_) bool SetBitsWithMask(const RetainPtr<CFX_DIBBase>& pBitmap, const RetainPtr<CFX_DIBBase>& pMask, int dest_left, @@ -100,11 +92,6 @@ int bitmap_alpha, BlendMode blend_type) override; void SetGroupKnockout(bool group_knockout) override; -#endif - -#if defined(_SKIA_SUPPORT_PATHS_) - void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath); -#endif bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, uint32_t color, @@ -163,36 +150,22 @@ bool GetGroupKnockout() const { return m_bGroupKnockout; } -#if defined(_SKIA_SUPPORT_PATHS_) - const CFX_ClipRgn* clip_region() const { return m_pClipRgn.get(); } - const std::vector<std::unique_ptr<CFX_ClipRgn>>& stack() const { - return m_StateStack; - } -#endif - private: -#if defined(_SKIA_SUPPORT_) bool StartDIBitsSkia(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, const FXDIB_ResampleOptions& options, BlendMode blend_type); -#endif RetainPtr<CFX_DIBitmap> m_pBitmap; RetainPtr<CFX_DIBitmap> m_pBackdropBitmap; SkCanvas* m_pCanvas; SkPictureRecorder* const m_pRecorder; std::unique_ptr<SkiaState> m_pCache; -#if defined(_SKIA_SUPPORT_PATHS_) - std::unique_ptr<CFX_ClipRgn> m_pClipRgn; - std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; -#endif CFX_FillRenderOptions m_FillOptions; bool m_bRgbByteOrder; bool m_bGroupKnockout; }; -#endif // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) #endif // CORE_FXGE_SKIA_FX_SKIA_DEVICE_H_
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp index d6022db..b84f222 100644 --- a/core/fxge/skia/fx_skia_device_embeddertest.cpp +++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -166,7 +166,6 @@ State::Graphic::kPath, 0xFF112233}); } -#if defined(_SKIA_SUPPORT_) // TODO(crbug.com/pdfium/11): Fix this test and enable. TEST(fxge, DISABLED_SkiaStateText) { if (!CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) @@ -178,7 +177,6 @@ Harness(&CommonTest, {State::Change::kNo, State::Save::kYes, State::Clip::kSame, State::Graphic::kText, 0xFF445566}); } -#endif TEST(fxge, SkiaStateOOSClip) { if (!CFX_DefaultRenderDevice::SkiaVariantIsDefaultRenderer())