OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaint.h" | 8 #include "SkPaint.h" |
9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
10 #include "SkAutoKern.h" | 10 #include "SkAutoKern.h" |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 } | 1472 } |
1473 | 1473 |
1474 #define assert_byte(x) SkASSERT(0 == ((x) >> 8)) | 1474 #define assert_byte(x) SkASSERT(0 == ((x) >> 8)) |
1475 | 1475 |
1476 // Beyond this size, LCD doesn't appreciably improve quality, but it always | 1476 // Beyond this size, LCD doesn't appreciably improve quality, but it always |
1477 // cost more RAM and draws slower, so we set a cap. | 1477 // cost more RAM and draws slower, so we set a cap. |
1478 #ifndef SK_MAX_SIZE_FOR_LCDTEXT | 1478 #ifndef SK_MAX_SIZE_FOR_LCDTEXT |
1479 #define SK_MAX_SIZE_FOR_LCDTEXT 48 | 1479 #define SK_MAX_SIZE_FOR_LCDTEXT 48 |
1480 #endif | 1480 #endif |
1481 | 1481 |
1482 static bool tooBigForLCD(const SkScalerContext::Rec& rec) { | 1482 const SkScalar gMaxSize2ForLCDText = SK_MAX_SIZE_FOR_LCDTEXT * SK_MAX_SIZE_FOR_L CDTEXT; |
1483 SkScalar area = rec.fPost2x2[0][0] * rec.fPost2x2[1][1] - | 1483 |
robertphillips
2014/10/01 19:58:41
too_big_for_lcd ?
| |
1484 rec.fPost2x2[1][0] * rec.fPost2x2[0][1]; | 1484 static bool tooBigForLCD(const SkScalerContext::Rec& rec, bool checkPost2x2) { |
1485 SkScalar size = SkScalarSqrt(SkScalarAbs(area)) * rec.fTextSize; | 1485 SkScalar size = rec.fTextSize; |
1486 return size > SkIntToScalar(SK_MAX_SIZE_FOR_LCDTEXT); | 1486 if (checkPost2x2) { |
1487 SkScalar area = rec.fPost2x2[0][0] * rec.fPost2x2[1][1] - | |
1488 rec.fPost2x2[1][0] * rec.fPost2x2[0][1]; | |
1489 size *= SkScalarAbs(area); | |
1490 } | |
1491 return size > gMaxSize2ForLCDText; | |
1487 } | 1492 } |
1488 | 1493 |
1489 /* | 1494 /* |
1490 * Return the scalar with only limited fractional precision. Used to consolidat e matrices | 1495 * Return the scalar with only limited fractional precision. Used to consolidat e matrices |
1491 * that vary only slightly when we create our key into the font cache, since th e font scaler | 1496 * that vary only slightly when we create our key into the font cache, since th e font scaler |
1492 * typically returns the same looking resuts for tiny changes in the matrix. | 1497 * typically returns the same looking resuts for tiny changes in the matrix. |
1493 */ | 1498 */ |
1494 static SkScalar sk_relax(SkScalar x) { | 1499 static SkScalar sk_relax(SkScalar x) { |
1495 int n = sk_float_round2int(x * 1024); | 1500 int n = sk_float_round2int(x * 1024); |
1496 return n / 1024.0f; | 1501 return n / 1024.0f; |
1497 } | 1502 } |
1498 | 1503 |
1499 void SkScalerContext::MakeRec(const SkPaint& paint, | 1504 void SkScalerContext::MakeRec(const SkPaint& paint, |
1500 const SkDeviceProperties* deviceProperties, | 1505 const SkDeviceProperties* deviceProperties, |
1501 const SkMatrix* deviceMatrix, | 1506 const SkMatrix* deviceMatrix, |
1502 Rec* rec) { | 1507 Rec* rec) { |
1503 SkASSERT(deviceMatrix == NULL || !deviceMatrix->hasPerspective()); | 1508 SkASSERT(deviceMatrix == NULL || !deviceMatrix->hasPerspective()); |
1504 | 1509 |
1505 SkTypeface* typeface = paint.getTypeface(); | 1510 SkTypeface* typeface = paint.getTypeface(); |
1506 if (NULL == typeface) { | 1511 if (NULL == typeface) { |
1507 typeface = SkTypeface::GetDefaultTypeface(); | 1512 typeface = SkTypeface::GetDefaultTypeface(); |
1508 } | 1513 } |
1509 rec->fFontID = typeface->uniqueID(); | 1514 rec->fFontID = typeface->uniqueID(); |
1510 rec->fTextSize = paint.getTextSize(); | 1515 rec->fTextSize = paint.getTextSize(); |
1511 rec->fPreScaleX = paint.getTextScaleX(); | 1516 rec->fPreScaleX = paint.getTextScaleX(); |
1512 rec->fPreSkewX = paint.getTextSkewX(); | 1517 rec->fPreSkewX = paint.getTextSkewX(); |
1513 | 1518 |
1519 bool checkPost2x2 = false; | |
1520 | |
1514 if (deviceMatrix) { | 1521 if (deviceMatrix) { |
1515 rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX()); | 1522 const SkMatrix::TypeMask mask = deviceMatrix->getType(); |
1516 rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX()); | 1523 if (mask & SkMatrix::kScale_Mask) { |
1517 rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY()); | 1524 rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX()); |
1518 rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY()); | 1525 rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY()); |
1526 checkPost2x2 = true; | |
1527 } else { | |
1528 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; | |
1529 } | |
1530 if (mask & SkMatrix::kAffine_Mask) { | |
1531 rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX()); | |
1532 rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY()); | |
1533 checkPost2x2 = true; | |
1534 } else { | |
1535 rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0; | |
1536 } | |
1519 } else { | 1537 } else { |
1520 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; | 1538 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; |
1521 rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0; | 1539 rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0; |
1522 } | 1540 } |
1523 | 1541 |
1524 SkPaint::Style style = paint.getStyle(); | 1542 SkPaint::Style style = paint.getStyle(); |
1525 SkScalar strokeWidth = paint.getStrokeWidth(); | 1543 SkScalar strokeWidth = paint.getStrokeWidth(); |
1526 | 1544 |
1527 unsigned flags = 0; | 1545 unsigned flags = 0; |
1528 | 1546 |
(...skipping 30 matching lines...) Expand all Loading... | |
1559 } | 1577 } |
1560 } else { | 1578 } else { |
1561 rec->fFrameWidth = 0; | 1579 rec->fFrameWidth = 0; |
1562 rec->fMiterLimit = 0; | 1580 rec->fMiterLimit = 0; |
1563 rec->fStrokeJoin = 0; | 1581 rec->fStrokeJoin = 0; |
1564 } | 1582 } |
1565 | 1583 |
1566 rec->fMaskFormat = SkToU8(computeMaskFormat(paint)); | 1584 rec->fMaskFormat = SkToU8(computeMaskFormat(paint)); |
1567 | 1585 |
1568 if (SkMask::kLCD16_Format == rec->fMaskFormat || SkMask::kLCD32_Format == re c->fMaskFormat) { | 1586 if (SkMask::kLCD16_Format == rec->fMaskFormat || SkMask::kLCD32_Format == re c->fMaskFormat) { |
1569 if (tooBigForLCD(*rec)) { | 1587 if (tooBigForLCD(*rec, checkPost2x2)) { |
1570 rec->fMaskFormat = SkMask::kA8_Format; | 1588 rec->fMaskFormat = SkMask::kA8_Format; |
1571 flags |= SkScalerContext::kGenA8FromLCD_Flag; | 1589 flags |= SkScalerContext::kGenA8FromLCD_Flag; |
1572 } else { | 1590 } else { |
1573 SkPixelGeometry geometry = deviceProperties | 1591 SkPixelGeometry geometry = deviceProperties |
1574 ? deviceProperties->fPixelGeometry | 1592 ? deviceProperties->fPixelGeometry |
1575 : SkSurfacePropsDefaultPixelGeometry(); | 1593 : SkSurfacePropsDefaultPixelGeometry(); |
1576 switch (geometry) { | 1594 switch (geometry) { |
1577 case kUnknown_SkPixelGeometry: | 1595 case kUnknown_SkPixelGeometry: |
1578 // eeek, can't support LCD | 1596 // eeek, can't support LCD |
1579 rec->fMaskFormat = SkMask::kA8_Format; | 1597 rec->fMaskFormat = SkMask::kA8_Format; |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2557 return 0 == this->getAlpha(); | 2575 return 0 == this->getAlpha(); |
2558 case SkXfermode::kDst_Mode: | 2576 case SkXfermode::kDst_Mode: |
2559 return true; | 2577 return true; |
2560 default: | 2578 default: |
2561 break; | 2579 break; |
2562 } | 2580 } |
2563 } | 2581 } |
2564 return false; | 2582 return false; |
2565 } | 2583 } |
2566 | 2584 |
OLD | NEW |