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 #include "core/include/fxge/fx_ge.h" | 5 #include "core/include/fxge/fx_ge.h" |
| 6 | 6 |
| 7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
| 8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
| 9 | 9 |
| 10 #include "core/src/fxge/agg/fx_agg_driver.h" | 10 #include "core/src/fxge/agg/fx_agg_driver.h" |
| 11 #include "core/src/fxge/skia/fx_skia_device.h" | 11 #include "core/src/fxge/skia/fx_skia_device.h" |
| 12 | 12 |
| 13 #include "SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "SkDashPathEffect.h" | 14 #include "third_party/skia/include/core/SkColorPriv.h" |
| 15 #include "SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 18 #include "third_party/skia/include/core/SkStream.h" | |
| 19 #include "third_party/skia/include/core/SkTypeface.h" | |
| 20 #include "third_party/skia/include/effects/SkDashPathEffect.h" | |
| 21 | |
| 22 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents | |
| 23 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip | |
| 24 | |
| 25 static void DebugShowSkiaPath(const SkPath& path) { | |
| 26 #if SHOW_SKIA_PATH | |
| 27 char buffer[4096]; | |
| 28 sk_bzero(buffer, sizeof(buffer)); | |
| 29 SkMemoryWStream stream(buffer, sizeof(buffer)); | |
| 30 path.dump(&stream, false, false); | |
| 31 printf("%s\n", buffer); | |
| 32 #endif // SHOW_SKIA_PATH | |
| 33 } | |
| 34 | |
| 35 #if DRAW_SKIA_CLIP | |
| 36 | |
| 37 static SkPaint DebugClipPaint() { | |
| 38 SkPaint paint; | |
| 39 paint.setAntiAlias(TRUE); | |
| 40 paint.setColor(SK_ColorGREEN); | |
| 41 paint.setStyle(SkPaint::kStroke_Style); | |
| 42 return paint; | |
| 43 } | |
| 44 | |
| 45 static void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) { | |
| 46 SkPaint paint = DebugClipPaint(); | |
| 47 canvas->drawRect(rect, paint); | |
| 48 } | |
| 49 | |
| 50 static void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) { | |
| 51 SkPaint paint = DebugClipPaint(); | |
| 52 canvas->drawPath(path, paint); | |
| 53 } | |
| 54 | |
| 55 #else // DRAW_SKIA_CLIP | |
| 56 | |
| 57 static void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | |
| 58 static void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | |
| 59 | |
| 60 #endif // DRAW_SKIA_CLIP | |
| 61 | |
| 62 #undef SHOW_SKIA_PATH | |
| 63 #undef DRAW_SKIA_CLIP | |
| 17 | 64 |
| 18 static SkPath BuildPath(const CFX_PathData* pPathData, | 65 static SkPath BuildPath(const CFX_PathData* pPathData, |
| 19 const CFX_Matrix* pObject2Device) { | 66 const CFX_Matrix* pObject2Device) { |
| 20 SkPath skPath; | 67 SkPath skPath; |
| 21 const CFX_PathData* pFPath = pPathData; | 68 const CFX_PathData* pFPath = pPathData; |
| 22 int nPoints = pFPath->GetPointCount(); | 69 int nPoints = pFPath->GetPointCount(); |
| 23 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 70 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
| 24 for (int i = 0; i < nPoints; i++) { | 71 for (int i = 0; i < nPoints; i++) { |
| 25 FX_FLOAT x = pPoints[i].m_PointX; | 72 FX_FLOAT x = pPoints[i].m_PointX; |
| 26 FX_FLOAT y = pPoints[i].m_PointY; | 73 FX_FLOAT y = pPoints[i].m_PointY; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 pOriDevice, bGroupKnockout); | 161 pOriDevice, bGroupKnockout); |
| 115 SkBitmap skBitmap; | 162 SkBitmap skBitmap; |
| 116 const CFX_DIBitmap* bitmap = m_pAggDriver->m_pBitmap; | 163 const CFX_DIBitmap* bitmap = m_pAggDriver->m_pBitmap; |
| 117 SkImageInfo imageInfo = | 164 SkImageInfo imageInfo = |
| 118 SkImageInfo::Make(bitmap->GetWidth(), bitmap->GetHeight(), | 165 SkImageInfo::Make(bitmap->GetWidth(), bitmap->GetHeight(), |
| 119 kN32_SkColorType, kOpaque_SkAlphaType); | 166 kN32_SkColorType, kOpaque_SkAlphaType); |
| 120 skBitmap.installPixels(imageInfo, bitmap->GetBuffer(), bitmap->GetPitch(), | 167 skBitmap.installPixels(imageInfo, bitmap->GetBuffer(), bitmap->GetPitch(), |
| 121 nullptr, /* to do : set color table */ | 168 nullptr, /* to do : set color table */ |
| 122 nullptr, nullptr); | 169 nullptr, nullptr); |
| 123 m_canvas = new SkCanvas(skBitmap); | 170 m_canvas = new SkCanvas(skBitmap); |
| 171 m_ditherBits = dither_bits; | |
| 172 m_recorder = nullptr; | |
| 124 } | 173 } |
| 125 | 174 |
| 175 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y, void* recorde r) { | |
| 176 m_pAggDriver = nullptr; | |
| 177 m_recorder = recorder ? (SkPictureRecorder*) recorder : new SkPictureRecorder; | |
| 178 m_recorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | |
| 179 m_canvas = m_recorder->getRecordingCanvas(); | |
| 180 m_ditherBits = 0; | |
| 181 } | |
| 182 | |
| 183 | |
| 126 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 184 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
| 127 #if 0 // TODO(caryclark) : mismatch on allocator ? | 185 #if 0 // TODO(caryclark) : mismatch on allocator ? |
| 128 delete m_canvas; | 186 delete m_canvas; |
| 129 #endif | 187 #endif |
| 130 delete m_pAggDriver; | 188 delete m_pAggDriver; |
| 131 } | 189 } |
| 132 | 190 |
| 133 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 191 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
| 134 const FXTEXT_CHARPOS* pCharPos, | 192 const FXTEXT_CHARPOS* pCharPos, |
| 135 CFX_Font* pFont, | 193 CFX_Font* pFont, |
| 136 CFX_FontCache* pCache, | 194 CFX_FontCache* pCache, |
| 137 const CFX_Matrix* pObject2Device, | 195 const CFX_Matrix* pObject2Device, |
| 138 FX_FLOAT font_size, | 196 FX_FLOAT font_size, |
| 139 FX_DWORD color, | 197 FX_DWORD color, |
| 140 int alpha_flag, | 198 int alpha_flag, |
| 141 void* pIccTransform) { | 199 void* pIccTransform) { |
| 142 return m_pAggDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | 200 SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( |
| 143 pObject2Device, font_size, color, | 201 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); |
| 144 alpha_flag, pIccTransform); | 202 SkPaint paint; |
| 203 paint.setAntiAlias(TRUE); | |
| 204 paint.setColor(color); | |
| 205 paint.setTypeface(typeface); | |
| 206 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
| 207 paint.setTextSize(font_size); | |
| 208 m_canvas->save(); | |
| 209 SkMatrix skMatrix; | |
| 210 const CFX_Matrix& m = *pObject2Device; | |
| 211 // note that PDF's y-axis goes up; Skia's y-axis goes down | |
|
dsinclair
2016/03/10 14:38:54
In the long run, should we add a toSkia on the CFX
caryclark
2016/03/10 20:44:55
It's not so clear to me what the correct solution
dsinclair
2016/03/10 20:47:12
Figuring it out later is fine, just something we s
| |
| 212 skMatrix.setAll(m.a, m.b, m.e, -m.c, -m.d, m.f, 0, 0, 1); | |
| 213 m_canvas->concat(skMatrix); | |
| 214 for (int index = 0; index < nChars; ++index) { | |
| 215 const FXTEXT_CHARPOS& cp = pCharPos[index]; | |
| 216 uint16_t glyph = (uint16_t)cp.m_GlyphIndex; | |
| 217 m_canvas->drawText(&glyph, 2, cp.m_OriginX, cp.m_OriginY, paint); | |
| 218 } | |
| 219 m_canvas->restore(); | |
| 220 return TRUE; | |
| 145 } | 221 } |
| 146 | 222 |
| 147 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) { | 223 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) { |
| 148 return m_pAggDriver->GetDeviceCaps(caps_id); | 224 switch (caps_id) { |
| 225 case FXDC_DEVICE_CLASS: | |
| 226 return FXDC_DISPLAY; | |
| 227 case FXDC_PIXEL_WIDTH: | |
| 228 return m_canvas->getBaseLayerSize().fWidth; | |
| 229 case FXDC_PIXEL_HEIGHT: | |
| 230 return m_canvas->getBaseLayerSize().fHeight; | |
| 231 case FXDC_BITS_PIXEL: | |
| 232 return 32; | |
| 233 case FXDC_HORZ_SIZE: | |
| 234 case FXDC_VERT_SIZE: | |
| 235 return 0; | |
| 236 case FXDC_RENDER_CAPS: | |
| 237 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | | |
| 238 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT; | |
| 239 case FXDC_DITHER_BITS: | |
| 240 return m_ditherBits; | |
| 241 } | |
| 242 return 0; | |
| 149 } | 243 } |
| 150 | 244 |
| 151 void CFX_SkiaDeviceDriver::SaveState() { | 245 void CFX_SkiaDeviceDriver::SaveState() { |
| 152 m_canvas->save(); | 246 m_canvas->save(); |
| 153 m_pAggDriver->SaveState(); | 247 if (m_pAggDriver) |
| 248 m_pAggDriver->SaveState(); | |
| 154 } | 249 } |
| 155 | 250 |
| 156 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { | 251 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved) { |
| 157 m_pAggDriver->RestoreState(bKeepSaved); | 252 if (m_pAggDriver) |
| 253 m_pAggDriver->RestoreState(bKeepSaved); | |
| 158 m_canvas->restore(); | 254 m_canvas->restore(); |
| 255 if (bKeepSaved) | |
| 256 m_canvas->save(); | |
| 159 } | 257 } |
| 160 | 258 |
| 161 void CFX_SkiaDeviceDriver::SetClipMask( | 259 void CFX_SkiaDeviceDriver::SetClipMask( |
| 162 agg::rasterizer_scanline_aa& rasterizer) { | 260 agg::rasterizer_scanline_aa& rasterizer) { |
| 163 m_pAggDriver->SetClipMask(rasterizer); | 261 if (m_pAggDriver) |
| 262 m_pAggDriver->SetClipMask(rasterizer); | |
| 164 } | 263 } |
| 165 | 264 |
| 166 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( | 265 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( |
| 167 const CFX_PathData* pPathData, // path info | 266 const CFX_PathData* pPathData, // path info |
| 168 const CFX_Matrix* pObject2Device, // optional transformation | 267 const CFX_Matrix* pObject2Device, // flips object's y-axis |
| 169 int fill_mode // fill mode, WINDING or ALTERNATE | 268 int fill_mode // fill mode, WINDING or ALTERNATE |
| 170 ) { | 269 ) { |
| 171 if (!m_pAggDriver->m_pClipRgn) { | 270 if (m_pAggDriver && !m_pAggDriver->m_pClipRgn) { |
| 172 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 271 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
| 173 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 272 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 174 } | 273 } |
| 175 | |
| 176 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 274 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
| 177 CFX_FloatRect rectf; | 275 CFX_FloatRect rectf; |
| 178 if (pPathData->IsRect(pObject2Device, &rectf)) { | 276 if (pPathData->IsRect(pObject2Device, &rectf)) { |
| 179 rectf.Intersect( | 277 rectf.Intersect( |
| 180 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 278 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 181 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 279 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 182 FX_RECT rect = rectf.GetOutterRect(); | 280 FX_RECT rect = rectf.GetOutterRect(); |
| 183 m_pAggDriver->m_pClipRgn->IntersectRect(rect); | 281 if (m_pAggDriver) |
| 282 m_pAggDriver->m_pClipRgn->IntersectRect(rect); | |
| 283 // note that PDF's y-axis goes up; Skia's y-axis goes down | |
| 284 SkRect skClipRect = | |
| 285 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); | |
| 286 DebugDrawSkiaClipRect(m_canvas, skClipRect); | |
| 287 m_canvas->clipRect(skClipRect); | |
| 184 return TRUE; | 288 return TRUE; |
| 185 } | 289 } |
| 186 } | 290 } |
| 187 SkPath clip = BuildPath(pPathData, pObject2Device); | 291 SkPath skClipPath = BuildPath(pPathData, pObject2Device); |
| 188 clip.setFillType((fill_mode & 3) == FXFILL_WINDING | 292 skClipPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
| 189 ? SkPath::kWinding_FillType | 293 ? SkPath::kWinding_FillType |
| 190 : SkPath::kEvenOdd_FillType); | 294 : SkPath::kEvenOdd_FillType); |
| 191 const CFX_Matrix& m = *pObject2Device; | 295 DebugShowSkiaPath(skClipPath); |
| 192 #if 0 | 296 DebugDrawSkiaClipPath(m_canvas, skClipPath); |
| 193 // TODO(caryclark) : don't clip quite yet | 297 m_canvas->clipPath(skClipPath); |
| 194 // need to understand how to save/restore to balance the clip | |
| 195 printf("m:(%g,%g,%g) (%g,%g,%g)\n", m.a, m.b, m.c, m.d, m.e, m.f); | |
| 196 clip.dump(); | |
| 197 SkMatrix skMatrix; | |
| 198 skMatrix.setAll(m.a, m.b, m.c, m.d, m.e, m.f, 0, 0, 1); | |
| 199 m_canvas->setMatrix(skMatrix); | |
| 200 m_canvas->clipPath(clip, SkRegion::kReplace_Op); | |
| 201 #endif | |
| 202 | 298 |
| 203 return TRUE; | 299 return TRUE; |
| 204 } | 300 } |
| 205 | 301 |
| 206 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( | 302 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( |
| 207 const CFX_PathData* pPathData, // path info | 303 const CFX_PathData* pPathData, // path info |
| 208 const CFX_Matrix* pObject2Device, // optional transformation | 304 const CFX_Matrix* pObject2Device, // optional transformation |
| 209 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 305 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
| 210 ) { | 306 ) { |
| 211 if (!m_pAggDriver->m_pClipRgn) { | 307 if (m_pAggDriver && !m_pAggDriver->m_pClipRgn) { |
| 212 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 308 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
| 213 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 309 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 214 } | 310 } |
| 215 | 311 |
| 216 // build path data | 312 // build path data |
| 217 SkPath skPath = BuildPath(pPathData, NULL); | 313 SkPath skPath = BuildPath(pPathData, NULL); |
| 218 skPath.setFillType(SkPath::kWinding_FillType); | 314 skPath.setFillType(SkPath::kWinding_FillType); |
| 219 | 315 |
| 220 SkPaint spaint; | 316 SkPaint spaint; |
| 221 PaintStroke(&spaint, pGraphState); | 317 PaintStroke(&spaint, pGraphState); |
| 222 SkPath dst_path; | 318 SkPath dst_path; |
| 223 spaint.getFillPath(skPath, &dst_path); | 319 spaint.getFillPath(skPath, &dst_path); |
| 224 #if 01 | 320 DebugDrawSkiaClipPath(m_canvas, dst_path); |
| 225 SkMatrix skMatrix; | 321 m_canvas->clipPath(dst_path); |
| 226 const CFX_Matrix& m = *pObject2Device; | |
| 227 skMatrix.setAll(m.a, m.b, m.c, m.d, m.e, m.f, 0, 0, 1); | |
| 228 m_canvas->setMatrix(skMatrix); | |
| 229 // TODO(caryclark) : don't clip quite yet | |
| 230 // need to understand how to save/restore so that clip is later undone | |
| 231 m_canvas->clipPath(dst_path, SkRegion::kReplace_Op); | |
| 232 #endif | |
| 233 return TRUE; | 322 return TRUE; |
| 234 } | 323 } |
| 235 | 324 |
| 236 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer( | 325 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer( |
| 237 agg::rasterizer_scanline_aa& rasterizer, | 326 agg::rasterizer_scanline_aa& rasterizer, |
| 238 FX_DWORD color, | 327 FX_DWORD color, |
| 239 FX_BOOL bFullCover, | 328 FX_BOOL bFullCover, |
| 240 FX_BOOL bGroupKnockout, | 329 FX_BOOL bGroupKnockout, |
| 241 int alpha_flag, | 330 int alpha_flag, |
| 242 void* pIccTransform) { | 331 void* pIccTransform) { |
| 243 return m_pAggDriver->RenderRasterizer( | 332 return m_pAggDriver && m_pAggDriver->RenderRasterizer( |
| 244 rasterizer, color, bFullCover, bGroupKnockout, alpha_flag, pIccTransform); | 333 rasterizer, color, bFullCover, bGroupKnockout, alpha_flag, pIccTransform); |
| 245 } | 334 } |
| 246 | 335 |
| 247 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 336 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
| 248 const CFX_PathData* pPathData, // path info | 337 const CFX_PathData* pPathData, // path info |
| 249 const CFX_Matrix* pObject2Device, // optional transformation | 338 const CFX_Matrix* pObject2Device, // optional transformation |
| 250 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 339 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
| 251 FX_DWORD fill_color, // fill color | 340 FX_DWORD fill_color, // fill color |
| 252 FX_DWORD stroke_color, // stroke color | 341 FX_DWORD stroke_color, // stroke color |
| 253 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 342 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
| 254 int alpha_flag, | 343 int alpha_flag, |
| 255 void* pIccTransform, | 344 void* pIccTransform, |
| 256 int blend_type) { | 345 int blend_type) { |
| 257 if (!GetBuffer()) | |
| 258 return TRUE; | |
| 259 SkIRect rect; | 346 SkIRect rect; |
| 260 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 347 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 261 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 348 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 262 SkPath skPath = BuildPath(pPathData, pObject2Device); | 349 SkPath skPath = BuildPath(pPathData, pObject2Device); |
| 263 SkPaint spaint; | 350 SkPaint spaint; |
| 264 spaint.setAntiAlias(TRUE); | 351 spaint.setAntiAlias(TRUE); |
| 265 if ((fill_mode & 3) && fill_color) { | 352 if ((fill_mode & 3) && fill_color) { |
| 266 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING | 353 skPath.setFillType((fill_mode & 3) == FXFILL_WINDING |
| 267 ? SkPath::kWinding_FillType | 354 ? SkPath::kWinding_FillType |
| 268 : SkPath::kEvenOdd_FillType); | 355 : SkPath::kEvenOdd_FillType); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 282 } | 369 } |
| 283 | 370 |
| 284 return TRUE; | 371 return TRUE; |
| 285 } | 372 } |
| 286 | 373 |
| 287 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, | 374 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, |
| 288 int y, | 375 int y, |
| 289 FX_DWORD color, | 376 FX_DWORD color, |
| 290 int alpha_flag, | 377 int alpha_flag, |
| 291 void* pIccTransform) { | 378 void* pIccTransform) { |
| 292 return m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTransform); | 379 return m_pAggDriver && m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTra nsform); |
| 293 } | 380 } |
| 294 | 381 |
| 295 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, | 382 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, |
| 296 FX_DWORD fill_color, | 383 FX_DWORD fill_color, |
| 297 int alpha_flag, | 384 int alpha_flag, |
| 298 void* pIccTransform, | 385 void* pIccTransform, |
| 299 int blend_type) { | 386 int blend_type) { |
| 300 SkPaint spaint; | 387 SkPaint spaint; |
| 301 spaint.setAntiAlias(true); | 388 spaint.setAntiAlias(TRUE); |
|
dsinclair
2016/03/10 14:38:54
If setAntiAlias takes a bool, you can leave this a
caryclark
2016/03/10 20:44:55
Done.
| |
| 302 spaint.setColor(fill_color); | 389 spaint.setColor(fill_color); |
| 303 | 390 |
| 304 m_canvas->drawRect( | 391 m_canvas->drawRect( |
| 305 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 392 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
| 306 spaint); | 393 spaint); |
| 307 return TRUE; | 394 return TRUE; |
| 308 } | 395 } |
| 309 | 396 |
| 310 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 397 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
| 311 return m_pAggDriver->GetClipBox(pRect); | 398 pRect->left = 0; |
|
dsinclair
2016/03/10 14:38:54
Does this need a todo to take the pRect into accou
caryclark
2016/03/10 20:44:55
Done.
| |
| 399 pRect->top = 0; | |
| 400 const SkISize& canvasSize = m_canvas->getBaseLayerSize(); | |
| 401 pRect->right = canvasSize.fWidth; | |
| 402 pRect->bottom = canvasSize.fHeight; | |
| 403 return TRUE; | |
| 312 } | 404 } |
| 313 | 405 |
| 314 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 406 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
| 315 int left, | 407 int left, |
| 316 int top, | 408 int top, |
| 317 void* pIccTransform, | 409 void* pIccTransform, |
| 318 FX_BOOL bDEdge) { | 410 FX_BOOL bDEdge) { |
| 319 return m_pAggDriver->GetDIBits(pBitmap, left, top, pIccTransform, bDEdge); | 411 return m_pAggDriver && m_pAggDriver->GetDIBits(pBitmap, left, top, pIccTransfo rm, bDEdge); |
| 320 } | 412 } |
| 321 | 413 |
| 322 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 414 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
| 323 FX_DWORD argb, | 415 FX_DWORD argb, |
| 324 const FX_RECT* pSrcRect, | 416 const FX_RECT* pSrcRect, |
| 325 int left, | 417 int left, |
| 326 int top, | 418 int top, |
| 327 int blend_type, | 419 int blend_type, |
| 328 int alpha_flag, | 420 int alpha_flag, |
| 329 void* pIccTransform) { | 421 void* pIccTransform) { |
| 330 return m_pAggDriver->SetDIBits(pBitmap, argb, pSrcRect, left, top, blend_type, | 422 return m_pAggDriver && m_pAggDriver->SetDIBits(pBitmap, argb, pSrcRect, left, top, blend_type, |
| 331 alpha_flag, pIccTransform); | 423 alpha_flag, pIccTransform); |
| 332 } | 424 } |
| 333 | 425 |
| 334 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 426 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
| 335 FX_DWORD argb, | 427 FX_DWORD argb, |
| 336 int dest_left, | 428 int dest_left, |
| 337 int dest_top, | 429 int dest_top, |
| 338 int dest_width, | 430 int dest_width, |
| 339 int dest_height, | 431 int dest_height, |
| 340 const FX_RECT* pClipRect, | 432 const FX_RECT* pClipRect, |
| 341 FX_DWORD flags, | 433 FX_DWORD flags, |
| 342 int alpha_flag, | 434 int alpha_flag, |
| 343 void* pIccTransform, | 435 void* pIccTransform, |
| 344 int blend_type) { | 436 int blend_type) { |
| 345 return m_pAggDriver->StretchDIBits(pSource, argb, dest_left, dest_top, | 437 return m_pAggDriver && m_pAggDriver->StretchDIBits(pSource, argb, dest_left, d est_top, |
| 346 dest_width, dest_height, pClipRect, flags, | 438 dest_width, dest_height, pClipRect, flags, |
| 347 alpha_flag, pIccTransform, blend_type); | 439 alpha_flag, pIccTransform, blend_type); |
| 348 } | 440 } |
| 349 | 441 |
| 350 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 442 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
| 351 int bitmap_alpha, | 443 int bitmap_alpha, |
| 352 FX_DWORD argb, | 444 FX_DWORD argb, |
| 353 const CFX_Matrix* pMatrix, | 445 const CFX_Matrix* pMatrix, |
| 354 FX_DWORD render_flags, | 446 FX_DWORD render_flags, |
| 355 void*& handle, | 447 void*& handle, |
| 356 int alpha_flag, | 448 int alpha_flag, |
| 357 void* pIccTransform, | 449 void* pIccTransform, |
| 358 int blend_type) { | 450 int blend_type) { |
| 359 return m_pAggDriver->StartDIBits(pSource, bitmap_alpha, argb, pMatrix, | 451 SkColorType colorType; |
| 360 render_flags, handle, alpha_flag, | 452 const uint8_t* buffer = pSource->GetBuffer(); |
| 361 pIccTransform, blend_type); | 453 uint8_t* dstStorage = nullptr; |
|
dsinclair
2016/03/10 14:38:54
std::unique_ptr then we can drop the if/free at th
caryclark
2016/03/10 20:44:55
Done.
| |
| 454 int width = pSource->GetWidth(); | |
| 455 int height = pSource->GetHeight(); | |
| 456 int rowBytes = pSource->GetPitch(); | |
| 457 switch (pSource->GetBPP()) { | |
| 458 case 1: { | |
| 459 dstStorage = (uint8_t*) malloc(width * height); | |
| 460 uint8_t* dst8Pixels = dstStorage; | |
| 461 for (int y = 0; y < height; ++y) { | |
| 462 const uint8_t* srcRow = buffer + y * rowBytes; | |
| 463 uint8_t* dstRow = dst8Pixels + y * width; | |
| 464 for (int x = 0; x < width; ++x) | |
| 465 dstRow[x] = srcRow[x >> 3] & (1 << (~x & 0x07)) ? 0xFF : 0x00; | |
| 466 } | |
| 467 buffer = const_cast<const uint8_t*>(dstStorage); | |
| 468 rowBytes = width; | |
| 469 colorType = SkColorType::kGray_8_SkColorType; | |
| 470 } break; | |
| 471 case 24: { | |
| 472 dstStorage = (uint8_t*) malloc(width * height * sizeof(uint32_t)); | |
| 473 uint32_t* dst32Pixels = (uint32_t*) dstStorage; | |
| 474 for (int y = 0; y < height; ++y) { | |
| 475 const uint8_t* srcRow = buffer + y * rowBytes; | |
| 476 uint32_t* dstRow = dst32Pixels + y * width; | |
| 477 for (int x = 0; x < width; ++x) | |
| 478 dstRow[x] = SkPackARGB32(0xFF, srcRow[x * 3 + 2], srcRow[x * 3 + 1], s rcRow[x * 3 + 0]); | |
| 479 } | |
| 480 buffer = const_cast<const uint8_t*>(dstStorage); | |
| 481 rowBytes = width * sizeof(uint32_t); | |
| 482 colorType = SkColorType::kN32_SkColorType; | |
| 483 } break; | |
| 484 case 32: | |
| 485 colorType = SkColorType::kN32_SkColorType; | |
| 486 break; | |
| 487 default: | |
| 488 colorType = SkColorType::kUnknown_SkColorType; | |
| 489 } | |
| 490 SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, kOpaque_Sk AlphaType); | |
| 491 SkBitmap skBitmap; | |
| 492 skBitmap.installPixels(imageInfo, (void*)buffer, rowBytes, | |
| 493 nullptr, /* TODO(caryclark) : set color table */ | |
| 494 nullptr, nullptr); | |
| 495 m_canvas->save(); | |
| 496 bool landscape = !pMatrix->a; | |
| 497 if (landscape) | |
| 498 m_canvas->translate(m_canvas->getBaseLayerSize().fWidth, 0); | |
| 499 else | |
| 500 m_canvas->translate(pMatrix->e, pMatrix->f + pMatrix->d); | |
| 501 SkMatrix skMatrix = SkMatrix::MakeScale(1.f / width, 1.f / height); | |
|
dsinclair
2016/03/10 14:38:54
nit: we try to leave 1 blank line after un-{}'d bo
caryclark
2016/03/10 20:44:55
Done.
| |
| 502 m_canvas->concat(skMatrix); | |
| 503 const CFX_Matrix& m = *pMatrix; | |
| 504 // note that PDF's y-axis goes up; Skia's y-axis goes down | |
| 505 if (landscape) | |
| 506 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | |
| 507 else | |
| 508 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1); | |
| 509 m_canvas->concat(skMatrix); | |
| 510 SkPaint paint; | |
| 511 paint.setAntiAlias(TRUE); | |
| 512 paint.setFilterQuality(kHigh_SkFilterQuality); | |
| 513 m_canvas->drawBitmap(skBitmap, 0, 0, &paint); | |
| 514 m_canvas->restore(); | |
| 515 if (dstStorage) | |
| 516 free(dstStorage); | |
| 517 return TRUE; | |
| 362 } | 518 } |
| 363 | 519 |
| 364 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { | 520 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
| 365 return m_pAggDriver->ContinueDIBits(pHandle, pPause); | 521 return m_pAggDriver && m_pAggDriver->ContinueDIBits(pHandle, pPause); |
| 366 } | 522 } |
| 367 | 523 |
| 368 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { | 524 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { |
| 369 m_pAggDriver->CancelDIBits(pHandle); | 525 if (m_pAggDriver) |
| 526 m_pAggDriver->CancelDIBits(pHandle); | |
| 370 } | 527 } |
| 371 | 528 |
| 372 CFX_SkiaDevice::CFX_SkiaDevice() { | 529 CFX_SkiaDevice::CFX_SkiaDevice() { |
| 373 m_bOwnedBitmap = FALSE; | 530 m_bOwnedBitmap = FALSE; |
| 531 m_recorder = nullptr; | |
| 532 } | |
| 533 | |
| 534 CFX_SkiaDevice::CFX_SkiaDevice(int size_x, int size_y, void* recorder) { | |
| 535 CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver(size_x, size_y, recor der); | |
| 536 SetDeviceDriver(pDriver); | |
| 537 m_bOwnedBitmap = FALSE; | |
| 538 m_recorder = pDriver->GetRecorder(); | |
| 374 } | 539 } |
| 375 | 540 |
| 376 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, | 541 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, |
| 377 int dither_bits, | 542 int dither_bits, |
| 378 FX_BOOL bRgbByteOrder, | 543 FX_BOOL bRgbByteOrder, |
| 379 CFX_DIBitmap* pOriDevice, | 544 CFX_DIBitmap* pOriDevice, |
| 380 FX_BOOL bGroupKnockout) { | 545 FX_BOOL bGroupKnockout) { |
| 381 if (!pBitmap) | 546 if (!pBitmap) |
| 382 return FALSE; | 547 return FALSE; |
| 383 SetBitmap(pBitmap); | 548 SetBitmap(pBitmap); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 void SkDebugf(const char format[], ...) { | 582 void SkDebugf(const char format[], ...) { |
| 418 va_list args; | 583 va_list args; |
| 419 va_start(args, format); | 584 va_start(args, format); |
| 420 vfprintf(stderr, format, args); | 585 vfprintf(stderr, format, args); |
| 421 va_end(args); | 586 va_end(args); |
| 422 } | 587 } |
| 423 | 588 |
| 424 #endif | 589 #endif |
| 425 | 590 |
| 426 #endif | 591 #endif |
| OLD | NEW |