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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #else // DRAW_SKIA_CLIP | 79 #else // DRAW_SKIA_CLIP |
80 | 80 |
81 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | 81 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} |
82 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | 82 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
83 | 83 |
84 #endif // DRAW_SKIA_CLIP | 84 #endif // DRAW_SKIA_CLIP |
85 | 85 |
86 #undef SHOW_SKIA_PATH | 86 #undef SHOW_SKIA_PATH |
87 #undef DRAW_SKIA_CLIP | 87 #undef DRAW_SKIA_CLIP |
88 | 88 |
89 static void DebugVerifyBitmapIsPreMultiplied(void* buffer, | |
90 int width, | |
91 int height) { | |
92 #ifdef SK_DEBUG | |
93 // verify that input is really premultiplied | |
94 for (int y = 0; y < height; ++y) { | |
95 const uint32_t* srcRow = static_cast<const uint32_t*>(buffer) + y * width; | |
96 for (int x = 0; x < width; ++x) { | |
97 uint8_t a = SkGetPackedA32(srcRow[x]); | |
98 uint8_t r = SkGetPackedR32(srcRow[x]); | |
99 uint8_t g = SkGetPackedG32(srcRow[x]); | |
100 uint8_t b = SkGetPackedB32(srcRow[x]); | |
101 SkA32Assert(a); | |
102 SkASSERT(r <= a); | |
103 SkASSERT(g <= a); | |
104 SkASSERT(b <= a); | |
105 } | |
106 } | |
107 #endif | |
108 } | |
109 | |
110 static void DebugValidate(const CFX_DIBitmap* bitmap, | 89 static void DebugValidate(const CFX_DIBitmap* bitmap, |
111 const CFX_DIBitmap* device) { | 90 const CFX_DIBitmap* device) { |
112 if (bitmap) { | 91 if (bitmap) { |
113 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); | 92 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); |
114 if (bitmap->GetBPP() == 32) { | 93 if (bitmap->GetBPP() == 32) { |
115 DebugVerifyBitmapIsPreMultiplied(bitmap->GetBuffer(), bitmap->GetWidth(), | 94 bitmap->DebugVerifyBitmapIsPreMultiplied(); |
116 bitmap->GetHeight()); | |
117 } | 95 } |
118 } | 96 } |
119 if (device) { | 97 if (device) { |
120 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); | 98 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); |
121 if (device->GetBPP() == 32) { | 99 if (device->GetBPP() == 32) { |
122 DebugVerifyBitmapIsPreMultiplied(device->GetBuffer(), device->GetWidth(), | 100 device->DebugVerifyBitmapIsPreMultiplied(); |
123 device->GetHeight()); | |
124 } | 101 } |
125 } | 102 } |
126 } | 103 } |
127 | 104 |
128 SkPath BuildPath(const CFX_PathData* pPathData) { | 105 SkPath BuildPath(const CFX_PathData* pPathData) { |
129 SkPath skPath; | 106 SkPath skPath; |
130 const CFX_PathData* pFPath = pPathData; | 107 const CFX_PathData* pFPath = pPathData; |
131 int nPoints = pFPath->GetPointCount(); | 108 int nPoints = pFPath->GetPointCount(); |
132 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 109 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
133 for (int i = 0; i < nPoints; i++) { | 110 for (int i = 0; i < nPoints; i++) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return false; | 261 return false; |
285 FX_FLOAT boundsEnd = | 262 FX_FLOAT boundsEnd = |
286 i < inputs - 1 ? pFunc->GetBound(i) : pFunc->GetDomain(1); | 263 i < inputs - 1 ? pFunc->GetBound(i) : pFunc->GetDomain(1); |
287 skPos->push(boundsStart); | 264 skPos->push(boundsStart); |
288 skPos->push(boundsEnd); | 265 skPos->push(boundsEnd); |
289 boundsStart = boundsEnd; | 266 boundsStart = boundsEnd; |
290 } | 267 } |
291 return true; | 268 return true; |
292 } | 269 } |
293 | 270 |
294 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, | |
295 int dest_left, | |
296 int dest_top, | |
297 int width, | |
298 int height, | |
299 const CFX_DIBSource* pSrcBitmap, | |
300 int src_left, | |
301 int src_top) { | |
302 if (!pBitmap) | |
303 return; | |
304 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, | |
305 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), | |
306 src_left, src_top, nullptr); | |
307 if (width == 0 || height == 0) | |
308 return; | |
309 int Bpp = pBitmap->GetBPP() / 8; | |
310 FXDIB_Format dest_format = pBitmap->GetFormat(); | |
311 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | |
312 int pitch = pBitmap->GetPitch(); | |
313 uint8_t* buffer = pBitmap->GetBuffer(); | |
314 if (dest_format == src_format) { | |
315 for (int row = 0; row < height; row++) { | |
316 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; | |
317 uint8_t* src_scan = | |
318 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | |
319 if (Bpp == 4) { | |
320 for (int col = 0; col < width; col++) { | |
321 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], | |
322 src_scan[1], src_scan[2])); | |
323 dest_scan += 4; | |
324 src_scan += 4; | |
325 } | |
326 } else { | |
327 for (int col = 0; col < width; col++) { | |
328 *dest_scan++ = src_scan[2]; | |
329 *dest_scan++ = src_scan[1]; | |
330 *dest_scan++ = src_scan[0]; | |
331 src_scan += 3; | |
332 } | |
333 } | |
334 } | |
335 return; | |
336 } | |
337 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp; | |
338 if (dest_format == FXDIB_Rgb) { | |
339 if (src_format == FXDIB_Rgb32) { | |
340 for (int row = 0; row < height; row++) { | |
341 uint8_t* dest_scan = dest_buf + row * pitch; | |
342 uint8_t* src_scan = | |
343 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; | |
344 for (int col = 0; col < width; col++) { | |
345 *dest_scan++ = src_scan[2]; | |
346 *dest_scan++ = src_scan[1]; | |
347 *dest_scan++ = src_scan[0]; | |
348 src_scan += 4; | |
349 } | |
350 } | |
351 } else { | |
352 ASSERT(FALSE); | |
353 } | |
354 } else if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { | |
355 if (src_format == FXDIB_Rgb) { | |
356 for (int row = 0; row < height; row++) { | |
357 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); | |
358 uint8_t* src_scan = | |
359 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; | |
360 for (int col = 0; col < width; col++) { | |
361 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
362 src_scan[2])); | |
363 dest_scan += 4; | |
364 src_scan += 3; | |
365 } | |
366 } | |
367 } else if (src_format == FXDIB_Rgb32) { | |
368 ASSERT(dest_format == FXDIB_Argb); | |
369 for (int row = 0; row < height; row++) { | |
370 uint8_t* dest_scan = dest_buf + row * pitch; | |
371 uint8_t* src_scan = | |
372 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); | |
373 for (int col = 0; col < width; col++) { | |
374 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
375 src_scan[2])); | |
376 src_scan += 4; | |
377 dest_scan += 4; | |
378 } | |
379 } | |
380 } | |
381 } else { | |
382 ASSERT(FALSE); | |
383 } | |
384 } | |
385 | |
386 // see https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line | 271 // see https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line |
387 SkScalar LineSide(const SkPoint line[2], const SkPoint& pt) { | 272 SkScalar LineSide(const SkPoint line[2], const SkPoint& pt) { |
388 return (line[1].fY - line[0].fY) * pt.fX - (line[1].fX - line[0].fX) * pt.fY + | 273 return (line[1].fY - line[0].fY) * pt.fX - (line[1].fX - line[0].fX) * pt.fY + |
389 line[1].fX * line[0].fY - line[1].fY * line[0].fX; | 274 line[1].fX * line[0].fY - line[1].fY * line[0].fX; |
390 } | 275 } |
391 | 276 |
392 SkPoint IntersectSides(const SkPoint& parallelPt, | 277 SkPoint IntersectSides(const SkPoint& parallelPt, |
393 const SkVector& paraRay, | 278 const SkVector& paraRay, |
394 const SkPoint& perpendicularPt) { | 279 const SkPoint& perpendicularPt) { |
395 SkVector perpRay = {paraRay.fY, -paraRay.fX}; | 280 SkVector perpRay = {paraRay.fY, -paraRay.fX}; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, | 403 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, |
519 fill_mode, blend_type)) { | 404 fill_mode, blend_type)) { |
520 FlushPath(pDriver); | 405 FlushPath(pDriver); |
521 } | 406 } |
522 if (!m_drawPath) { | 407 if (!m_drawPath) { |
523 m_skPath.reset(); | 408 m_skPath.reset(); |
524 m_fillPath = (fill_mode & 3) && fill_color; | 409 m_fillPath = (fill_mode & 3) && fill_color; |
525 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 410 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
526 ? SkPath::kEvenOdd_FillType | 411 ? SkPath::kEvenOdd_FillType |
527 : SkPath::kWinding_FillType); | 412 : SkPath::kWinding_FillType); |
528 m_drawState = *pDrawState; | 413 if (pDrawState) |
| 414 m_drawState.Copy(*pDrawState); |
529 m_fillColor = fill_color; | 415 m_fillColor = fill_color; |
530 m_strokeColor = stroke_color; | 416 m_strokeColor = stroke_color; |
531 m_blendType = blend_type; | 417 m_blendType = blend_type; |
532 m_drawMatrix = *pMatrix; | 418 if (pMatrix) |
| 419 m_drawMatrix = *pMatrix; |
533 } | 420 } |
534 SkPath skPath = BuildPath(pPathData); | 421 SkPath skPath = BuildPath(pPathData); |
535 SkPoint delta; | 422 SkPoint delta; |
536 if (MatrixOffset(pMatrix, &delta)) | 423 if (MatrixOffset(pMatrix, &delta)) |
537 skPath.offset(delta.fX, delta.fY); | 424 skPath.offset(delta.fX, delta.fY); |
538 m_skPath.addPath(skPath); | 425 m_skPath.addPath(skPath); |
539 m_drawPath = true; | 426 m_drawPath = true; |
540 return true; | 427 return true; |
541 } | 428 } |
542 | 429 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 SkPaint skPaint; | 513 SkPaint skPaint; |
627 skPaint.setAntiAlias(true); | 514 skPaint.setAntiAlias(true); |
628 skPaint.setColor(m_fillColor); | 515 skPaint.setColor(m_fillColor); |
629 if (m_pFont->GetFace() && m_pCache) { // exclude placeholder test fonts | 516 if (m_pFont->GetFace() && m_pCache) { // exclude placeholder test fonts |
630 sk_sp<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); | 517 sk_sp<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); |
631 skPaint.setTypeface(typeface); | 518 skPaint.setTypeface(typeface); |
632 } | 519 } |
633 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 520 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
634 skPaint.setTextSize(m_fontSize); | 521 skPaint.setTextSize(m_fontSize); |
635 skPaint.setSubpixelText(true); | 522 skPaint.setSubpixelText(true); |
| 523 skPaint.setHinting(SkPaint::kNo_Hinting); |
636 SkCanvas* skCanvas = pDriver->SkiaCanvas(); | 524 SkCanvas* skCanvas = pDriver->SkiaCanvas(); |
637 skCanvas->save(); | 525 skCanvas->save(); |
638 skCanvas->concat(skMatrix); | 526 skCanvas->concat(skMatrix); |
639 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, | 527 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, |
640 m_positions.begin(), skPaint); | 528 m_positions.begin(), skPaint); |
641 skCanvas->restore(); | 529 skCanvas->restore(); |
642 m_drawText = false; | 530 m_drawText = false; |
643 } | 531 } |
644 | 532 |
645 bool SetClipFill(const CFX_PathData* pPathData, | 533 bool SetClipFill(const CFX_PathData* pPathData, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 SkMatrix skMatrix = ToSkMatrix(*pMatrix); | 571 SkMatrix skMatrix = ToSkMatrix(*pMatrix); |
684 SkPaint skPaint; | 572 SkPaint skPaint; |
685 pDriver->PaintStroke(&skPaint, pGraphState, skMatrix); | 573 pDriver->PaintStroke(&skPaint, pGraphState, skMatrix); |
686 SkPath dst_path; | 574 SkPath dst_path; |
687 skPaint.getFillPath(skPath, &dst_path); | 575 skPaint.getFillPath(skPath, &dst_path); |
688 dst_path.transform(skMatrix); | 576 dst_path.transform(skMatrix); |
689 return SetClip(dst_path, pDriver); | 577 return SetClip(dst_path, pDriver); |
690 } | 578 } |
691 | 579 |
692 bool MatrixOffset(const CFX_Matrix* pMatrix, SkPoint* delta) { | 580 bool MatrixOffset(const CFX_Matrix* pMatrix, SkPoint* delta) { |
| 581 CFX_Matrix identityMatrix; |
| 582 if (!pMatrix) |
| 583 pMatrix = &identityMatrix; |
693 delta->set(pMatrix->e - m_drawMatrix.e, pMatrix->f - m_drawMatrix.f); | 584 delta->set(pMatrix->e - m_drawMatrix.e, pMatrix->f - m_drawMatrix.f); |
694 if (!delta->fX && !delta->fY) | 585 if (!delta->fX && !delta->fY) |
695 return true; | 586 return true; |
696 SkMatrix drawMatrix = ToSkMatrix(m_drawMatrix); | 587 SkMatrix drawMatrix = ToSkMatrix(m_drawMatrix); |
697 if (!(drawMatrix.getType() & ~SkMatrix::kTranslate_Mask)) | 588 if (!(drawMatrix.getType() & ~SkMatrix::kTranslate_Mask)) |
698 return true; | 589 return true; |
699 SkMatrix invDrawMatrix; | 590 SkMatrix invDrawMatrix; |
700 if (!drawMatrix.invert(&invDrawMatrix)) | 591 if (!drawMatrix.invert(&invDrawMatrix)) |
701 return false; | 592 return false; |
702 SkMatrix invNewMatrix; | 593 SkMatrix invNewMatrix; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 CFX_FontCache* pCache, | 673 CFX_FontCache* pCache, |
783 const CFX_Matrix* pMatrix, | 674 const CFX_Matrix* pMatrix, |
784 FX_FLOAT font_size, | 675 FX_FLOAT font_size, |
785 uint32_t color) { | 676 uint32_t color) { |
786 return pFont != m_pFont || pCache != m_pCache || | 677 return pFont != m_pFont || pCache != m_pCache || |
787 MatrixChanged(pMatrix, m_drawMatrix) || font_size != m_fontSize || | 678 MatrixChanged(pMatrix, m_drawMatrix) || font_size != m_fontSize || |
788 color != m_fillColor; | 679 color != m_fillColor; |
789 } | 680 } |
790 | 681 |
791 bool MatrixChanged(const CFX_Matrix* pMatrix, const CFX_Matrix& refMatrix) { | 682 bool MatrixChanged(const CFX_Matrix* pMatrix, const CFX_Matrix& refMatrix) { |
| 683 CFX_Matrix identityMatrix; |
| 684 if (!pMatrix) |
| 685 pMatrix = &identityMatrix; |
792 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b || | 686 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b || |
793 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d; | 687 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d; |
794 } | 688 } |
795 | 689 |
796 bool StateChanged(const CFX_GraphStateData* pState, | 690 bool StateChanged(const CFX_GraphStateData* pState, |
797 const CFX_GraphStateData& refState) { | 691 const CFX_GraphStateData& refState) { |
| 692 CFX_GraphStateData identityState; |
| 693 if (!pState) |
| 694 pState = &identityState; |
798 return pState->m_LineWidth != refState.m_LineWidth || | 695 return pState->m_LineWidth != refState.m_LineWidth || |
799 pState->m_LineCap != refState.m_LineCap || | 696 pState->m_LineCap != refState.m_LineCap || |
800 pState->m_LineJoin != refState.m_LineJoin || | 697 pState->m_LineJoin != refState.m_LineJoin || |
801 pState->m_MiterLimit != refState.m_MiterLimit || | 698 pState->m_MiterLimit != refState.m_MiterLimit || |
802 DashChanged(pState, refState); | 699 DashChanged(pState, refState); |
803 } | 700 } |
804 | 701 |
805 bool DashChanged(const CFX_GraphStateData* pState, | 702 bool DashChanged(const CFX_GraphStateData* pState, |
806 const CFX_GraphStateData& refState) { | 703 const CFX_GraphStateData& refState) { |
807 if (!pState->m_DashArray && !refState.m_DashArray) | 704 bool dashArray = pState && pState->m_DashArray; |
| 705 if (!dashArray && !refState.m_DashArray) |
808 return false; | 706 return false; |
809 if (!pState->m_DashArray || !refState.m_DashArray) | 707 if (!dashArray || !refState.m_DashArray) |
810 return true; | 708 return true; |
811 if (pState->m_DashPhase != refState.m_DashPhase || | 709 if (pState->m_DashPhase != refState.m_DashPhase || |
812 pState->m_DashCount != refState.m_DashCount) { | 710 pState->m_DashCount != refState.m_DashCount) { |
813 return true; | 711 return true; |
814 } | 712 } |
815 for (int index = 0; index < pState->m_DashCount; ++index) { | 713 for (int index = 0; index < pState->m_DashCount; ++index) { |
816 if (pState->m_DashArray[index] != refState.m_DashArray[index]) | 714 if (pState->m_DashArray[index] != refState.m_DashArray[index]) |
817 return false; | 715 return false; |
818 } | 716 } |
819 return true; | 717 return true; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 837 } |
940 | 838 |
941 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 839 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
942 FX_BOOL bRgbByteOrder, | 840 FX_BOOL bRgbByteOrder, |
943 CFX_DIBitmap* pOriDevice, | 841 CFX_DIBitmap* pOriDevice, |
944 FX_BOOL bGroupKnockout) | 842 FX_BOOL bGroupKnockout) |
945 : m_pBitmap(pBitmap), | 843 : m_pBitmap(pBitmap), |
946 m_pOriDevice(pOriDevice), | 844 m_pOriDevice(pOriDevice), |
947 m_pRecorder(nullptr), | 845 m_pRecorder(nullptr), |
948 m_pCache(new SkiaState), | 846 m_pCache(new SkiaState), |
949 m_bRgbByteOrder(bRgbByteOrder), | |
950 m_bGroupKnockout(bGroupKnockout) { | 847 m_bGroupKnockout(bGroupKnockout) { |
951 SkBitmap skBitmap; | 848 SkBitmap skBitmap; |
952 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); | 849 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); |
953 SkImageInfo imageInfo = SkImageInfo::Make( | 850 SkImageInfo imageInfo = SkImageInfo::Make( |
954 pBitmap->GetWidth(), pBitmap->GetHeight(), | 851 pBitmap->GetWidth(), pBitmap->GetHeight(), |
955 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, | 852 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, |
956 kOpaque_SkAlphaType); | 853 kOpaque_SkAlphaType); |
957 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), | 854 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), |
958 nullptr, /* to do : set color table */ | 855 nullptr, /* to do : set color table */ |
959 nullptr, nullptr); | 856 nullptr, nullptr); |
960 m_pCanvas = new SkCanvas(skBitmap); | 857 m_pCanvas = new SkCanvas(skBitmap); |
961 if (m_bGroupKnockout) | 858 if (m_bGroupKnockout) |
962 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' | 859 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' |
963 } | 860 } |
964 | 861 |
965 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) | 862 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
966 : m_pBitmap(nullptr), | 863 : m_pBitmap(nullptr), |
967 m_pOriDevice(nullptr), | 864 m_pOriDevice(nullptr), |
968 m_pRecorder(new SkPictureRecorder), | 865 m_pRecorder(new SkPictureRecorder), |
969 m_pCache(new SkiaState), | 866 m_pCache(new SkiaState), |
970 m_bRgbByteOrder(FALSE), | |
971 m_bGroupKnockout(FALSE) { | 867 m_bGroupKnockout(FALSE) { |
972 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | 868 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); |
973 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 869 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
974 } | 870 } |
975 | 871 |
976 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) | 872 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
977 : m_pBitmap(nullptr), | 873 : m_pBitmap(nullptr), |
978 m_pOriDevice(nullptr), | 874 m_pOriDevice(nullptr), |
979 m_pRecorder(recorder), | 875 m_pRecorder(recorder), |
980 m_pCache(new SkiaState), | 876 m_pCache(new SkiaState), |
981 m_bRgbByteOrder(FALSE), | |
982 m_bGroupKnockout(FALSE) { | 877 m_bGroupKnockout(FALSE) { |
983 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 878 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
984 } | 879 } |
985 | 880 |
986 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 881 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
987 Flush(); | 882 Flush(); |
988 if (!m_pRecorder) | 883 if (!m_pRecorder) |
989 delete m_pCanvas; | 884 delete m_pCanvas; |
990 } | 885 } |
991 | 886 |
(...skipping 13 matching lines...) Expand all Loading... |
1005 font_size, color, this)) { | 900 font_size, color, this)) { |
1006 return TRUE; | 901 return TRUE; |
1007 } | 902 } |
1008 sk_sp<SkTypeface> typeface( | 903 sk_sp<SkTypeface> typeface( |
1009 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); | 904 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr)); |
1010 SkPaint paint; | 905 SkPaint paint; |
1011 paint.setAntiAlias(true); | 906 paint.setAntiAlias(true); |
1012 paint.setColor(color); | 907 paint.setColor(color); |
1013 paint.setTypeface(typeface); | 908 paint.setTypeface(typeface); |
1014 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 909 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 910 paint.setHinting(SkPaint::kNo_Hinting); |
1015 paint.setTextSize(font_size); | 911 paint.setTextSize(font_size); |
1016 paint.setSubpixelText(true); | 912 paint.setSubpixelText(true); |
1017 m_pCanvas->save(); | 913 m_pCanvas->save(); |
1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); | 914 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device); |
1019 m_pCanvas->concat(skMatrix); | 915 m_pCanvas->concat(skMatrix); |
1020 SkTDArray<SkPoint> positions; | 916 SkTDArray<SkPoint> positions; |
1021 positions.setCount(nChars); | 917 positions.setCount(nChars); |
1022 SkTDArray<uint16_t> glyphs; | 918 SkTDArray<uint16_t> glyphs; |
1023 glyphs.setCount(nChars); | 919 glyphs.setCount(nChars); |
1024 for (int index = 0; index < nChars; ++index) { | 920 for (int index = 0; index < nChars; ++index) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 pRect->top = 0; | 1243 pRect->top = 0; |
1348 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 1244 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
1349 pRect->right = canvasSize.width(); | 1245 pRect->right = canvasSize.width(); |
1350 pRect->bottom = canvasSize.height(); | 1246 pRect->bottom = canvasSize.height(); |
1351 return TRUE; | 1247 return TRUE; |
1352 } | 1248 } |
1353 | 1249 |
1354 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 1250 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
1355 int left, | 1251 int left, |
1356 int top) { | 1252 int top) { |
1357 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1253 if (!m_pBitmap) |
1358 return TRUE; | 1254 return TRUE; |
1359 | 1255 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
1360 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | 1256 if (!srcBuffer) |
1361 top + pBitmap->GetHeight()); | |
1362 std::unique_ptr<CFX_DIBitmap> pBack; | |
1363 if (m_pOriDevice) { | |
1364 pBack.reset(m_pOriDevice->Clone(&rect)); | |
1365 if (!pBack) | |
1366 return TRUE; | |
1367 | |
1368 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | |
1369 m_pBitmap, 0, 0); | |
1370 } else { | |
1371 pBack.reset(m_pBitmap->Clone(&rect)); | |
1372 if (!pBack) | |
1373 return TRUE; | |
1374 } | |
1375 | |
1376 left = std::min(left, 0); | |
1377 top = std::min(top, 0); | |
1378 if (m_bRgbByteOrder) { | |
1379 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | |
1380 pBack.get(), left, top); | |
1381 return TRUE; | 1257 return TRUE; |
1382 } | 1258 int srcWidth = m_pBitmap->GetWidth(); |
1383 | 1259 int srcHeight = m_pBitmap->GetHeight(); |
1384 return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(), | 1260 int srcRowBytes = srcWidth * sizeof(uint32_t); |
1385 left, top); | 1261 SkImageInfo srcImageInfo = SkImageInfo::Make( |
| 1262 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
| 1263 SkBitmap skSrcBitmap; |
| 1264 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, |
| 1265 nullptr, nullptr); |
| 1266 SkASSERT(pBitmap); |
| 1267 uint8_t* dstBuffer = pBitmap->GetBuffer(); |
| 1268 SkASSERT(dstBuffer); |
| 1269 int dstWidth = pBitmap->GetWidth(); |
| 1270 int dstHeight = pBitmap->GetHeight(); |
| 1271 int dstRowBytes = dstWidth * sizeof(uint32_t); |
| 1272 SkImageInfo dstImageInfo = SkImageInfo::Make( |
| 1273 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
| 1274 SkBitmap skDstBitmap; |
| 1275 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, |
| 1276 nullptr, nullptr); |
| 1277 SkCanvas canvas(skDstBitmap); |
| 1278 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
| 1279 return TRUE; |
1386 } | 1280 } |
1387 | 1281 |
1388 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { | 1282 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
1389 return m_pOriDevice; | 1283 return m_pOriDevice; |
1390 } | 1284 } |
1391 | 1285 |
1392 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1286 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1393 uint32_t argb, | 1287 uint32_t argb, |
1394 const FX_RECT* pSrcRect, | 1288 const FX_RECT* pSrcRect, |
1395 int left, | 1289 int left, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 } | 1378 } |
1485 } | 1379 } |
1486 buffer = dst32Storage.get(); | 1380 buffer = dst32Storage.get(); |
1487 rowBytes = width * sizeof(uint32_t); | 1381 rowBytes = width * sizeof(uint32_t); |
1488 colorType = SkColorType::kN32_SkColorType; | 1382 colorType = SkColorType::kN32_SkColorType; |
1489 alphaType = kOpaque_SkAlphaType; | 1383 alphaType = kOpaque_SkAlphaType; |
1490 } break; | 1384 } break; |
1491 case 32: | 1385 case 32: |
1492 colorType = SkColorType::kN32_SkColorType; | 1386 colorType = SkColorType::kN32_SkColorType; |
1493 alphaType = kPremul_SkAlphaType; | 1387 alphaType = kPremul_SkAlphaType; |
1494 DebugVerifyBitmapIsPreMultiplied(buffer, width, height); | 1388 pSource->DebugVerifyBitmapIsPreMultiplied(buffer); |
1495 break; | 1389 break; |
1496 default: | 1390 default: |
1497 SkASSERT(0); // TODO(caryclark) ensure that all cases are covered | 1391 SkASSERT(0); // TODO(caryclark) ensure that all cases are covered |
1498 colorType = SkColorType::kUnknown_SkColorType; | 1392 colorType = SkColorType::kUnknown_SkColorType; |
1499 } | 1393 } |
1500 SkImageInfo imageInfo = | 1394 SkImageInfo imageInfo = |
1501 SkImageInfo::Make(width, height, colorType, alphaType); | 1395 SkImageInfo::Make(width, height, colorType, alphaType); |
1502 SkBitmap skBitmap; | 1396 SkBitmap skBitmap; |
1503 skBitmap.installPixels(imageInfo, buffer, rowBytes, ct, nullptr, nullptr); | 1397 skBitmap.installPixels(imageInfo, buffer, rowBytes, ct, nullptr, nullptr); |
1504 m_pCanvas->save(); | 1398 m_pCanvas->save(); |
(...skipping 16 matching lines...) Expand all Loading... |
1521 if (ct) | 1415 if (ct) |
1522 ct->unref(); | 1416 ct->unref(); |
1523 DebugValidate(m_pBitmap, m_pOriDevice); | 1417 DebugValidate(m_pBitmap, m_pOriDevice); |
1524 return TRUE; | 1418 return TRUE; |
1525 } | 1419 } |
1526 | 1420 |
1527 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1421 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
1528 return FALSE; | 1422 return FALSE; |
1529 } | 1423 } |
1530 | 1424 |
1531 void CFX_SkiaDeviceDriver::PreMultiply() { | |
1532 PreMultiply(m_pBitmap); | |
1533 } | |
1534 | |
1535 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | 1425 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
1536 void* buffer = pDIBitmap->GetBuffer(); | 1426 void* buffer = pDIBitmap->GetBuffer(); |
1537 if (!buffer) | 1427 if (!buffer) |
1538 return; | 1428 return; |
1539 if (pDIBitmap->GetBPP() != 32) { | 1429 if (pDIBitmap->GetBPP() != 32) { |
1540 return; | 1430 return; |
1541 } | 1431 } |
1542 int height = pDIBitmap->GetHeight(); | 1432 int height = pDIBitmap->GetHeight(); |
1543 int width = pDIBitmap->GetWidth(); | 1433 int width = pDIBitmap->GetWidth(); |
1544 int rowBytes = pDIBitmap->GetPitch(); | 1434 int rowBytes = pDIBitmap->GetPitch(); |
1545 SkImageInfo unpremultipliedInfo = | 1435 SkImageInfo unpremultipliedInfo = |
1546 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); | 1436 SkImageInfo::Make(width, height, kN32_SkColorType, kUnpremul_SkAlphaType); |
1547 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); | 1437 SkPixmap unpremultiplied(unpremultipliedInfo, buffer, rowBytes); |
1548 SkImageInfo premultipliedInfo = | 1438 SkImageInfo premultipliedInfo = |
1549 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); | 1439 SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); |
1550 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); | 1440 SkPixmap premultiplied(premultipliedInfo, buffer, rowBytes); |
1551 unpremultiplied.readPixels(premultiplied); | 1441 unpremultiplied.readPixels(premultiplied); |
1552 DebugVerifyBitmapIsPreMultiplied(buffer, width, height); | 1442 pDIBitmap->DebugVerifyBitmapIsPreMultiplied(); |
1553 } | 1443 } |
1554 | 1444 |
1555 void CFX_SkiaDeviceDriver::Dump() const { | 1445 void CFX_SkiaDeviceDriver::Dump() const { |
1556 #ifdef SK_DEBUG | 1446 #ifdef SK_DEBUG |
1557 if (m_pCache) | 1447 if (m_pCache) |
1558 m_pCache->Dump(this); | 1448 m_pCache->Dump(this); |
1559 #endif | 1449 #endif |
1560 } | 1450 } |
1561 | 1451 |
| 1452 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
| 1453 if (m_pOriDevice) |
| 1454 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
| 1455 } |
| 1456 |
1562 CFX_FxgeDevice::CFX_FxgeDevice() { | 1457 CFX_FxgeDevice::CFX_FxgeDevice() { |
1563 m_bOwnedBitmap = FALSE; | 1458 m_bOwnedBitmap = FALSE; |
1564 } | 1459 } |
1565 | 1460 |
1566 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { | 1461 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
1567 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); | 1462 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); |
1568 SetDeviceDriver(skDriver); | 1463 SetDeviceDriver(skDriver); |
1569 return skDriver->GetRecorder(); | 1464 return skDriver->GetRecorder(); |
1570 } | 1465 } |
1571 | 1466 |
(...skipping 27 matching lines...) Expand all Loading... |
1599 return false; | 1494 return false; |
1600 } | 1495 } |
1601 SetBitmap(pBitmap); | 1496 SetBitmap(pBitmap); |
1602 CFX_SkiaDeviceDriver* pDriver = | 1497 CFX_SkiaDeviceDriver* pDriver = |
1603 new CFX_SkiaDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE); | 1498 new CFX_SkiaDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE); |
1604 SetDeviceDriver(pDriver); | 1499 SetDeviceDriver(pDriver); |
1605 return true; | 1500 return true; |
1606 } | 1501 } |
1607 | 1502 |
1608 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1503 CFX_FxgeDevice::~CFX_FxgeDevice() { |
| 1504 Flush(); |
| 1505 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately |
1609 if (m_bOwnedBitmap && GetBitmap()) | 1506 if (m_bOwnedBitmap && GetBitmap()) |
1610 delete GetBitmap(); | 1507 delete GetBitmap(); |
1611 } | 1508 } |
1612 | 1509 |
1613 void CFX_FxgeDevice::PreMultiply() { | 1510 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { |
1614 (static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()))->PreMultiply(); | 1511 #ifdef SK_DEBUG |
| 1512 CFX_SkiaDeviceDriver* skDriver = |
| 1513 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
| 1514 if (skDriver) |
| 1515 skDriver->DebugVerifyBitmapIsPreMultiplied(); |
| 1516 #endif |
| 1517 } |
| 1518 |
| 1519 void CFX_DIBSource::DebugVerifyBitmapIsPreMultiplied(void* opt) const { |
| 1520 #ifdef SK_DEBUG |
| 1521 SkASSERT(32 == GetBPP()); |
| 1522 const uint32_t* buffer = (const uint32_t*)(opt ? opt : GetBuffer()); |
| 1523 int width = GetWidth(); |
| 1524 int height = GetHeight(); |
| 1525 // verify that input is really premultiplied |
| 1526 for (int y = 0; y < height; ++y) { |
| 1527 const uint32_t* srcRow = buffer + y * width; |
| 1528 for (int x = 0; x < width; ++x) { |
| 1529 uint8_t a = SkGetPackedA32(srcRow[x]); |
| 1530 uint8_t r = SkGetPackedR32(srcRow[x]); |
| 1531 uint8_t g = SkGetPackedG32(srcRow[x]); |
| 1532 uint8_t b = SkGetPackedB32(srcRow[x]); |
| 1533 SkA32Assert(a); |
| 1534 SkASSERT(r <= a); |
| 1535 SkASSERT(g <= a); |
| 1536 SkASSERT(b <= a); |
| 1537 } |
| 1538 } |
| 1539 #endif |
1615 } | 1540 } |
1616 | 1541 |
1617 #endif | 1542 #endif |
OLD | NEW |