Index: core/fxge/skia/fx_skia_device.cpp |
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp |
index fd4f73972f9bf9d0652985e150b3e9df09c20eac..1c99f978060f620fe2682bcb7a405a0793f44817 100644 |
--- a/core/fxge/skia/fx_skia_device.cpp |
+++ b/core/fxge/skia/fx_skia_device.cpp |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#if defined(_SKIA_SUPPORT_) |
+#ifdef _SKIA_SUPPORT_ |
#include <algorithm> |
#include <vector> |
@@ -15,25 +15,48 @@ |
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
#include "core/fxge/include/cfx_fontcache.h" |
+#endif |
+ |
#include "core/fxge/include/cfx_fxgedevice.h" |
+ |
+#ifdef _SKIA_SUPPORT_ |
dsinclair
2016/09/19 20:45:12
Let's consolidate all of these header if's into fe
|
#include "core/fxge/include/cfx_gemodule.h" |
+#endif |
+ |
#include "core/fxge/include/cfx_graphstatedata.h" |
#include "core/fxge/include/cfx_pathdata.h" |
+ |
+#ifdef _SKIA_SUPPORT_ |
#include "core/fxge/include/cfx_renderdevice.h" |
-#include "core/fxge/skia/fx_skia_device.h" |
+#else |
+#include "core/fxge/ge/cfx_cliprgn.h" |
+#endif |
+#include "core/fxge/skia/fx_skia_device.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
+ |
+#ifdef _SKIA_SUPPORT_ |
#include "third_party/skia/include/core/SkColorFilter.h" |
#include "third_party/skia/include/core/SkColorPriv.h" |
#include "third_party/skia/include/core/SkMaskFilter.h" |
+#endif |
+ |
#include "third_party/skia/include/core/SkPaint.h" |
#include "third_party/skia/include/core/SkPath.h" |
+ |
+#ifdef _SKIA_SUPPORT_ |
#include "third_party/skia/include/core/SkPictureRecorder.h" |
#include "third_party/skia/include/core/SkShader.h" |
#include "third_party/skia/include/core/SkStream.h" |
#include "third_party/skia/include/core/SkTypeface.h" |
+#endif |
+ |
#include "third_party/skia/include/effects/SkDashPathEffect.h" |
+ |
+#ifdef _SKIA_SUPPORT_ |
#include "third_party/skia/include/effects/SkGradientShader.h" |
+#endif |
+ |
#include "third_party/skia/include/pathops/SkPathOps.h" |
#ifdef SK_DEBUG |
@@ -95,6 +118,7 @@ void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
#undef SHOW_SKIA_PATH |
#undef DRAW_SKIA_CLIP |
+#ifdef _SKIA_SUPPORT_ |
static void DebugValidate(const CFX_DIBitmap* bitmap, |
const CFX_DIBitmap* device) { |
if (bitmap) { |
@@ -110,6 +134,7 @@ static void DebugValidate(const CFX_DIBitmap* bitmap, |
} |
} |
} |
+#endif |
SkPath BuildPath(const CFX_PathData* pPathData) { |
SkPath skPath; |
@@ -188,6 +213,7 @@ SkXfermode::Mode GetSkiaBlendMode(int blend_type) { |
} |
} |
+#ifdef _SKIA_SUPPORT_ |
bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { |
if (pFunc->CountInputs() != 1) |
return false; |
@@ -277,6 +303,7 @@ bool AddStitching(const CPDF_StitchFunc* pFunc, |
} |
return true; |
} |
+#endif |
// see https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line |
SkScalar LineSide(const SkPoint line[2], const SkPoint& pt) { |
@@ -301,6 +328,7 @@ SkPoint IntersectSides(const SkPoint& parallelPt, |
return result; |
} |
+#ifdef _SKIA_SUPPORT_ |
void ClipAngledGradient(const SkPoint pts[2], |
SkPoint rectPts[4], |
bool clipStart, |
@@ -471,6 +499,56 @@ bool Upsample(const CFX_DIBSource* pSource, |
*heightPtr = height; |
return true; |
} |
+#else |
+ |
+void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, |
+ int dest_left, |
+ int dest_top, |
+ int width, |
+ int height, |
+ const CFX_DIBSource* pSrcBitmap, |
+ int src_left, |
+ int src_top) { |
+ if (!pBitmap) |
+ return; |
+ |
+ pBitmap->GetOverlapRect(dest_left, dest_top, width, height, |
+ pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), |
+ src_left, src_top, nullptr); |
+ if (width == 0 || height == 0) |
+ return; |
+ |
+ int Bpp = pBitmap->GetBPP() / 8; |
+ FXDIB_Format dest_format = pBitmap->GetFormat(); |
+ FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
+ int pitch = pBitmap->GetPitch(); |
+ uint8_t* buffer = pBitmap->GetBuffer(); |
+ if (dest_format == src_format) { |
+ for (int row = 0; row < height; row++) { |
+ uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; |
+ uint8_t* src_scan = |
+ (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
+ if (Bpp == 4) { |
+ for (int col = 0; col < width; col++) { |
+ FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], |
+ src_scan[1], src_scan[2])); |
+ 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; |
+ } |
+ } |
+ } |
+ return; |
+ } |
+} |
+ |
+#endif |
} // namespace |
@@ -509,8 +587,10 @@ class SkiaState { |
return false; |
if (m_commandIndex < m_commands.count()) |
FlushCommands(pDriver); |
+#if _SKIA_SUPPORT_ |
if (m_drawText) |
FlushText(pDriver); |
+#endif |
if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, |
fill_mode, blend_type)) { |
FlushPath(pDriver); |
@@ -577,6 +657,7 @@ class SkiaState { |
m_drawPath = false; |
} |
+#ifdef _SKIA_SUPPORT_ |
bool DrawText(int nChars, |
const FXTEXT_CHARPOS* pCharPos, |
CFX_Font* pFont, |
@@ -642,6 +723,7 @@ class SkiaState { |
skCanvas->restore(); |
m_drawText = false; |
} |
+#endif |
bool SetClipFill(const CFX_PathData* pPathData, |
const CFX_Matrix* pMatrix, |
@@ -833,8 +915,10 @@ class SkiaState { |
void Flush(CFX_SkiaDeviceDriver* pDriver) { |
if (m_drawPath) |
FlushPath(pDriver); |
+#ifdef _SKIA_SUPPORT_ |
if (m_drawText) |
FlushText(pDriver); |
+#endif |
} |
#ifdef SK_DEBUG |
@@ -972,6 +1056,7 @@ CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' |
} |
+#ifdef _SKIA_SUPPORT_ |
CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
: m_pBitmap(nullptr), |
m_pOriDevice(nullptr), |
@@ -990,6 +1075,7 @@ CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
m_bGroupKnockout(FALSE) { |
m_pCanvas = m_pRecorder->getRecordingCanvas(); |
} |
+#endif |
CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
Flush(); |
@@ -1009,6 +1095,7 @@ FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
const CFX_Matrix* pObject2Device, |
FX_FLOAT font_size, |
uint32_t color) { |
+#ifdef _SKIA_SUPPORT_ |
if (!pCache) |
pCache = CFX_GEModule::Get()->GetFontCache(); |
if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, |
@@ -1041,6 +1128,9 @@ FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); |
m_pCanvas->restore(); |
return TRUE; |
+#else |
+ return FALSE; |
+#endif |
} |
int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { |
@@ -1215,6 +1305,7 @@ FX_BOOL CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, |
return TRUE; |
} |
+#ifdef _SKIA_SUPPORT_ |
FX_BOOL CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
const CFX_Matrix* pMatrix, |
const FX_RECT& clip_rect, |
@@ -1348,6 +1439,7 @@ FX_BOOL CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
m_pCanvas->restore(); |
return true; |
} |
+#endif |
uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { |
return m_pBitmap->GetBuffer(); |
@@ -1371,6 +1463,7 @@ FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
if (!srcBuffer) |
return TRUE; |
+#ifdef _SKIA_SUPPORT_ |
int srcWidth = m_pBitmap->GetWidth(); |
int srcHeight = m_pBitmap->GetHeight(); |
int srcRowBytes = srcWidth * sizeof(uint32_t); |
@@ -1393,6 +1486,36 @@ FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
SkCanvas canvas(skDstBitmap); |
canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
return TRUE; |
+#else |
+ FX_RECT rect(left, top, left + pBitmap->GetWidth(), |
+ top + pBitmap->GetHeight()); |
+ CFX_DIBitmap* pBack = nullptr; |
+ if (m_pOriDevice) { |
+ pBack = m_pOriDevice->Clone(&rect); |
+ if (!pBack) |
+ return TRUE; |
+ |
+ pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), |
+ m_pBitmap, 0, 0); |
+ } else { |
+ pBack = m_pBitmap->Clone(&rect); |
+ if (!pBack) |
+ return TRUE; |
+ } |
+ |
+ FX_BOOL bRet = TRUE; |
+ left = std::min(left, 0); |
+ top = std::min(top, 0); |
+ if (m_bRgbByteOrder) { |
+ RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), |
+ pBack, left, top); |
+ } else { |
+ bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, |
+ left, top); |
+ } |
+ delete pBack; |
+ return bRet; |
+#endif |
} |
CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
@@ -1408,10 +1531,22 @@ FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
return TRUE; |
+#ifdef _SKIA_SUPPORT |
CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
top + pBitmap->GetHeight()); |
void* dummy; |
return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
+#else |
+ if (pBitmap->IsAlphaMask()) { |
+ return m_pBitmap->CompositeMask( |
+ left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, |
+ pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), |
+ m_bRgbByteOrder, 0, nullptr); |
+ } |
+ return m_pBitmap->CompositeBitmap( |
+ left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, |
+ pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); |
+#endif |
} |
FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
@@ -1423,6 +1558,7 @@ FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
const FX_RECT* pClipRect, |
uint32_t flags, |
int blend_type) { |
+#ifdef _SKIA_SUPPORT |
if (!m_pBitmap->GetBuffer()) |
return TRUE; |
CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
@@ -1437,6 +1573,27 @@ FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
m_pCanvas->restore(); |
return result; |
+#else |
+ 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); |
+ } |
+ 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, 0, nullptr, blend_type); |
+ dest_clip.Offset(-dest_rect.left, -dest_rect.top); |
+ CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, |
+ dest_clip, flags); |
+ if (stretcher.Start()) |
+ stretcher.Continue(nullptr); |
+ return TRUE; |
+#endif |
} |
FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
@@ -1446,6 +1603,7 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
uint32_t render_flags, |
void*& handle, |
int blend_type) { |
+#ifdef _SKIA_SUPPORT |
DebugValidate(m_pBitmap, m_pOriDevice); |
SkColorTable* ct = nullptr; |
std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
@@ -1485,12 +1643,27 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
ct->unref(); |
DebugValidate(m_pBitmap, m_pOriDevice); |
return TRUE; |
+#else |
+ CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; |
+ pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, |
+ pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); |
+ handle = pRenderer; |
+ return TRUE; |
+#endif |
} |
-FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
+FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
+#ifdef _SKIA_SUPPORT |
return FALSE; |
+#else |
+ if (!m_pBitmap->GetBuffer()) { |
+ return TRUE; |
+ } |
+ return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); |
dsinclair
2016/09/19 20:45:12
nit: static_cast.
|
+#endif |
} |
+#ifdef _SKIA_SUPPORT |
void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
void* buffer = pDIBitmap->GetBuffer(); |
if (!buffer) |
@@ -1572,6 +1745,7 @@ bool CFX_SkiaDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap, |
void CFX_SkiaDeviceDriver::Clear(uint32_t color) { |
m_pCanvas->clear(color); |
} |
+#endif |
void CFX_SkiaDeviceDriver::Dump() const { |
#ifdef SK_DEBUG |
@@ -1580,15 +1754,20 @@ void CFX_SkiaDeviceDriver::Dump() const { |
#endif |
} |
+#ifdef _SKIA_SUPPORT_ |
void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
if (m_pOriDevice) |
m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
} |
+#endif |
CFX_FxgeDevice::CFX_FxgeDevice() { |
+#ifdef _SKIA_SUPPORT_ |
m_bOwnedBitmap = FALSE; |
+#endif |
} |
+#ifdef _SKIA_SUPPORT_ |
void CFX_FxgeDevice::Clear(uint32_t color) { |
CFX_SkiaDeviceDriver* skDriver = |
static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
@@ -1600,6 +1779,7 @@ SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
SetDeviceDriver(WrapUnique(skDriver)); |
return skDriver->GetRecorder(); |
} |
+#endif |
bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
bool bRgbByteOrder, |
@@ -1613,12 +1793,14 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
return true; |
} |
+#ifdef _SKIA_SUPPORT_ |
bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { |
if (!recorder) |
return false; |
SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver(recorder))); |
return true; |
} |
+#endif |
bool CFX_FxgeDevice::Create(int width, |
int height, |
@@ -1637,12 +1819,15 @@ bool CFX_FxgeDevice::Create(int width, |
} |
CFX_FxgeDevice::~CFX_FxgeDevice() { |
+#ifdef _SKIA_SUPPORT_ |
Flush(); |
// call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately |
if (m_bOwnedBitmap && GetBitmap()) |
delete GetBitmap(); |
+#endif |
} |
+#ifdef _SKIA_SUPPORT_ |
void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { |
#ifdef SK_DEBUG |
CFX_SkiaDeviceDriver* skDriver = |