Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: src/core/SkDraw.cpp

Issue 1711223003: Only use fake gamma with linear devices. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Formatting. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkGlyphCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #define __STDC_LIMIT_MACROS 7 #define __STDC_LIMIT_MACROS
8 8
9 #include "SkDraw.h" 9 #include "SkDraw.h"
10 #include "SkBlitter.h" 10 #include "SkBlitter.h"
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 SkGlyphCache * const fGlyphCache; 1549 SkGlyphCache * const fGlyphCache;
1550 SkBlitter * const fBlitter; 1550 SkBlitter * const fBlitter;
1551 const SkRegion* const fClip; 1551 const SkRegion* const fClip;
1552 const SkDraw& fDraw; 1552 const SkDraw& fDraw;
1553 const SkPaint& fPaint; 1553 const SkPaint& fPaint;
1554 const SkIRect fClipBounds; 1554 const SkIRect fClipBounds;
1555 }; 1555 };
1556 1556
1557 //////////////////////////////////////////////////////////////////////////////// //////////////////// 1557 //////////////////////////////////////////////////////////////////////////////// ////////////////////
1558 1558
1559 SkPaint::FakeGamma SkDraw::fakeGamma() const {
1560 return fDevice->imageInfo().isLinear() ? SkPaint::FakeGamma::On : SkPaint::F akeGamma::Off;
1561 }
1562
1559 void SkDraw::drawText(const char text[], size_t byteLength, 1563 void SkDraw::drawText(const char text[], size_t byteLength,
1560 SkScalar x, SkScalar y, const SkPaint& paint) const { 1564 SkScalar x, SkScalar y, const SkPaint& paint) const {
1561 SkASSERT(byteLength == 0 || text != nullptr); 1565 SkASSERT(byteLength == 0 || text != nullptr);
1562 1566
1563 SkDEBUGCODE(this->validate();) 1567 SkDEBUGCODE(this->validate();)
1564 1568
1565 // nothing to draw 1569 // nothing to draw
1566 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { 1570 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) {
1567 return; 1571 return;
1568 } 1572 }
1569 1573
1570 // SkScalarRec doesn't currently have a way of representing hairline stroke and 1574 // SkScalarRec doesn't currently have a way of representing hairline stroke and
1571 // will fill if its frame-width is 0. 1575 // will fill if its frame-width is 0.
1572 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { 1576 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1573 this->drawText_asPaths(text, byteLength, x, y, paint); 1577 this->drawText_asPaths(text, byteLength, x, y, paint);
1574 return; 1578 return;
1575 } 1579 }
1576 1580
1577 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), fMatrix); 1581 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), f Matrix);
1578 SkGlyphCache* cache = autoCache.getCache();
1579 1582
1580 // The Blitter Choose needs to be live while using the blitter below. 1583 // The Blitter Choose needs to be live while using the blitter below.
1581 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); 1584 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint);
1582 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); 1585 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get());
1583 DrawOneGlyph drawOneGlyph(*this, paint, cache, wrapper.getBlitter( )); 1586 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl itter());
1584 1587
1585 SkFindAndPlaceGlyph::ProcessText( 1588 SkFindAndPlaceGlyph::ProcessText(
1586 paint.getTextEncoding(), text, byteLength, 1589 paint.getTextEncoding(), text, byteLength,
1587 {x, y}, *fMatrix, paint.getTextAlign(), cache, drawOneGlyph); 1590 {x, y}, *fMatrix, paint.getTextAlign(), cache.get(), drawOneGlyph);
1588 } 1591 }
1589 1592
1590 ////////////////////////////////////////////////////////////////////////////// 1593 //////////////////////////////////////////////////////////////////////////////
1591 1594
1592 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, 1595 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
1593 const SkScalar pos[], int scalarsPerPosition, 1596 const SkScalar pos[], int scalarsPerPosition,
1594 const SkPoint& offset, const SkPaint& origPaint ) const { 1597 const SkPoint& offset, const SkPaint& origPaint ) const {
1595 // setup our std paint, in hopes of getting hits in the cache 1598 // setup our std paint, in hopes of getting hits in the cache
1596 SkPaint paint(origPaint); 1599 SkPaint paint(origPaint);
1597 SkScalar matrixScale = paint.setupForAsPaths(); 1600 SkScalar matrixScale = paint.setupForAsPaths();
1598 1601
1599 SkMatrix matrix; 1602 SkMatrix matrix;
1600 matrix.setScale(matrixScale, matrixScale); 1603 matrix.setScale(matrixScale, matrixScale);
1601 1604
1602 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache. 1605 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache.
1603 paint.setStyle(SkPaint::kFill_Style); 1606 paint.setStyle(SkPaint::kFill_Style);
1604 paint.setPathEffect(nullptr); 1607 paint.setPathEffect(nullptr);
1605 1608
1606 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1609 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1607 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), nullptr); 1610 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma() , nullptr);
1608 SkGlyphCache* cache = autoCache.getCache();
1609 1611
1610 const char* stop = text + byteLength; 1612 const char* stop = text + byteLength;
1611 SkTextAlignProc alignProc(paint.getTextAlign()); 1613 SkTextAlignProc alignProc(paint.getTextAlign());
1612 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 1614 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
1613 1615
1614 // Now restore the original settings, so we "draw" with whatever style/strok ing. 1616 // Now restore the original settings, so we "draw" with whatever style/strok ing.
1615 paint.setStyle(origPaint.getStyle()); 1617 paint.setStyle(origPaint.getStyle());
1616 paint.setPathEffect(origPaint.getPathEffect()); 1618 paint.setPathEffect(origPaint.getPathEffect());
1617 1619
1618 while (text < stop) { 1620 while (text < stop) {
1619 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1621 const SkGlyph& glyph = glyphCacheProc(cache.get(), &text, 0, 0);
1620 if (glyph.fWidth) { 1622 if (glyph.fWidth) {
1621 const SkPath* path = cache->findPath(glyph); 1623 const SkPath* path = cache->findPath(glyph);
1622 if (path) { 1624 if (path) {
1623 SkPoint tmsLoc; 1625 SkPoint tmsLoc;
1624 tmsProc(pos, &tmsLoc); 1626 tmsProc(pos, &tmsLoc);
1625 SkPoint loc; 1627 SkPoint loc;
1626 alignProc(tmsLoc, glyph, &loc); 1628 alignProc(tmsLoc, glyph, &loc);
1627 1629
1628 matrix[SkMatrix::kMTransX] = loc.fX; 1630 matrix[SkMatrix::kMTransX] = loc.fX;
1629 matrix[SkMatrix::kMTransY] = loc.fY; 1631 matrix[SkMatrix::kMTransY] = loc.fY;
(...skipping 19 matching lines...) Expand all
1649 // nothing to draw 1651 // nothing to draw
1650 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { 1652 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) {
1651 return; 1653 return;
1652 } 1654 }
1653 1655
1654 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { 1656 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1655 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off set, paint); 1657 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off set, paint);
1656 return; 1658 return;
1657 } 1659 }
1658 1660
1659 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), fMatrix); 1661 SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), f Matrix);
1660 SkGlyphCache* cache = autoCache.getCache();
1661 1662
1662 // The Blitter Choose needs to be live while using the blitter below. 1663 // The Blitter Choose needs to be live while using the blitter below.
1663 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); 1664 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint);
1664 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get()); 1665 SkAAClipBlitterWrapper wrapper(*fRC, blitterChooser.get());
1665 DrawOneGlyph drawOneGlyph(*this, paint, cache, wrapper.getBlitter( )); 1666 DrawOneGlyph drawOneGlyph(*this, paint, cache.get(), wrapper.getBl itter());
1666 SkPaint::Align textAlignment = paint.getTextAlign(); 1667 SkPaint::Align textAlignment = paint.getTextAlign();
1667 1668
1668 SkFindAndPlaceGlyph::ProcessPosText( 1669 SkFindAndPlaceGlyph::ProcessPosText(
1669 paint.getTextEncoding(), text, byteLength, 1670 paint.getTextEncoding(), text, byteLength,
1670 offset, *fMatrix, pos, scalarsPerPosition, textAlignment, cache, drawOne Glyph); 1671 offset, *fMatrix, pos, scalarsPerPosition, textAlignment, cache.get(), d rawOneGlyph);
1671 } 1672 }
1672 1673
1673 #if defined _WIN32 && _MSC_VER >= 1300 1674 #if defined _WIN32 && _MSC_VER >= 1300
1674 #pragma warning ( pop ) 1675 #pragma warning ( pop )
1675 #endif 1676 #endif
1676 1677
1677 /////////////////////////////////////////////////////////////////////////////// 1678 ///////////////////////////////////////////////////////////////////////////////
1678 1679
1679 static SkScan::HairRCProc ChooseHairProc(bool doAntiAlias) { 1680 static SkScan::HairRCProc ChooseHairProc(bool doAntiAlias) {
1680 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; 1681 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 mask->fImage = SkMask::AllocImage(size); 2056 mask->fImage = SkMask::AllocImage(size);
2056 memset(mask->fImage, 0, mask->computeImageSize()); 2057 memset(mask->fImage, 0, mask->computeImageSize());
2057 } 2058 }
2058 2059
2059 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2060 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2060 draw_into_mask(*mask, devPath, style); 2061 draw_into_mask(*mask, devPath, style);
2061 } 2062 }
2062 2063
2063 return true; 2064 return true;
2064 } 2065 }
OLDNEW
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkGlyphCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698