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

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 41213003: Hook in rough distance field support for fonts (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "effects/GrTextureDomainEffect.h" 10 #include "effects/GrTextureDomainEffect.h"
11 #include "effects/GrSimpleTextureEffect.h" 11 #include "effects/GrSimpleTextureEffect.h"
12 12
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrBitmapTextContext.h" 14 #include "GrBitmapTextContext.h"
15 #include "GrDistanceFieldTextContext.h"
15 16
16 #include "SkGrTexturePixelRef.h" 17 #include "SkGrTexturePixelRef.h"
17 18
18 #include "SkColorFilter.h" 19 #include "SkColorFilter.h"
19 #include "SkDeviceImageFilterProxy.h" 20 #include "SkDeviceImageFilterProxy.h"
20 #include "SkDrawProcs.h" 21 #include "SkDrawProcs.h"
21 #include "SkGlyphCache.h" 22 #include "SkGlyphCache.h"
22 #include "SkImageFilter.h" 23 #include "SkImageFilter.h"
23 #include "SkPathEffect.h" 24 #include "SkPathEffect.h"
24 #include "SkRRect.h" 25 #include "SkRRect.h"
25 #include "SkStroke.h" 26 #include "SkStroke.h"
26 #include "SkUtils.h" 27 #include "SkUtils.h"
27 #include "SkErrorInternals.h" 28 #include "SkErrorInternals.h"
28 29
29 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 30 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1
30 31
32 #define USE_DISTANCE_FIELDS 1
33
31 #if 0 34 #if 0
32 extern bool (*gShouldDrawProc)(); 35 extern bool (*gShouldDrawProc)();
33 #define CHECK_SHOULD_DRAW(draw, forceI) \ 36 #define CHECK_SHOULD_DRAW(draw, forceI) \
34 do { \ 37 do { \
35 if (gShouldDrawProc && !gShouldDrawProc()) return; \ 38 if (gShouldDrawProc && !gShouldDrawProc()) return; \
36 this->prepareDraw(draw, forceI); \ 39 this->prepareDraw(draw, forceI); \
37 } while (0) 40 } while (0)
38 #else 41 #else
39 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) 42 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI)
40 #endif 43 #endif
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 procs->fFontScaler); 1728 procs->fFontScaler);
1726 } 1729 }
1727 1730
1728 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) { 1731 SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) {
1729 1732
1730 // deferred allocation 1733 // deferred allocation
1731 if (NULL == fDrawProcs) { 1734 if (NULL == fDrawProcs) {
1732 fDrawProcs = SkNEW(GrSkDrawProcs); 1735 fDrawProcs = SkNEW(GrSkDrawProcs);
1733 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph; 1736 fDrawProcs->fD1GProc = SkGPU_Draw1Glyph;
1734 fDrawProcs->fContext = fContext; 1737 fDrawProcs->fContext = fContext;
1738 fDrawProcs->fFlags = 0;
1739 #if USE_DISTANCE_FIELDS
1740 fDrawProcs->fFlags |= SkDrawProcs::kSkipBakedGlyphTransform_Flag;
1741 fDrawProcs->fFlags |= SkDrawProcs::kUseScaledGlyphs_Flag;
1742 #endif
1735 } 1743 }
1736 1744
1737 // init our (and GL's) state 1745 // init our (and GL's) state
1738 fDrawProcs->fTextContext = context; 1746 fDrawProcs->fTextContext = context;
1739 fDrawProcs->fFontScaler = NULL; 1747 fDrawProcs->fFontScaler = NULL;
1740 return fDrawProcs; 1748 return fDrawProcs;
1741 } 1749 }
1742 1750
1743 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, 1751 void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
1744 size_t byteLength, SkScalar x, SkScalar y, 1752 size_t byteLength, SkScalar x, SkScalar y,
1745 const SkPaint& paint) { 1753 const SkPaint& paint) {
1746 CHECK_SHOULD_DRAW(draw, false); 1754 CHECK_SHOULD_DRAW(draw, false);
1747 1755
1748 if (fContext->getMatrix().hasPerspective()) { 1756 if (fContext->getMatrix().hasPerspective()) {
1749 // this guy will just call our drawPath() 1757 // this guy will just call our drawPath()
1750 draw.drawText((const char*)text, byteLength, x, y, paint); 1758 draw.drawText((const char*)text, byteLength, x, y, paint);
1751 } else { 1759 } else {
1752 SkDraw myDraw(draw); 1760 SkDraw myDraw(draw);
1753 1761
1754 GrPaint grPaint; 1762 GrPaint grPaint;
1755 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1763 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1756 return; 1764 return;
1757 } 1765 }
1766 #if USE_DISTANCE_FIELDS
1767 GrDistanceFieldTextContext context(fContext, grPaint, paint.getTextSize( ));
1768 #else
1758 GrBitmapTextContext context(fContext, grPaint); 1769 GrBitmapTextContext context(fContext, grPaint);
1770 #endif
1759 myDraw.fProcs = this->initDrawForText(&context); 1771 myDraw.fProcs = this->initDrawForText(&context);
1760 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); 1772 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
1761 } 1773 }
1762 } 1774 }
1763 1775
1764 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, 1776 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
1765 size_t byteLength, const SkScalar pos[], 1777 size_t byteLength, const SkScalar pos[],
1766 SkScalar constY, int scalarsPerPos, 1778 SkScalar constY, int scalarsPerPos,
1767 const SkPaint& paint) { 1779 const SkPaint& paint) {
1768 CHECK_SHOULD_DRAW(draw, false); 1780 CHECK_SHOULD_DRAW(draw, false);
1769 1781
1770 if (fContext->getMatrix().hasPerspective()) { 1782 if (fContext->getMatrix().hasPerspective()) {
1771 // this guy will just call our drawPath() 1783 // this guy will just call our drawPath()
1772 draw.drawPosText((const char*)text, byteLength, pos, constY, 1784 draw.drawPosText((const char*)text, byteLength, pos, constY,
1773 scalarsPerPos, paint); 1785 scalarsPerPos, paint);
1774 } else { 1786 } else {
1775 SkDraw myDraw(draw); 1787 SkDraw myDraw(draw);
1776 1788
1777 GrPaint grPaint; 1789 GrPaint grPaint;
1778 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1790 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1779 return; 1791 return;
1780 } 1792 }
1793 #if USE_DISTANCE_FIELDS
1794 GrDistanceFieldTextContext context(fContext, grPaint, paint.getTextSize( ));
1795 #else
1781 GrBitmapTextContext context(fContext, grPaint); 1796 GrBitmapTextContext context(fContext, grPaint);
1797 #endif
1782 myDraw.fProcs = this->initDrawForText(&context); 1798 myDraw.fProcs = this->initDrawForText(&context);
1783 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, 1799 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
1784 scalarsPerPos, paint); 1800 scalarsPerPos, paint);
1785 } 1801 }
1786 } 1802 }
1787 1803
1788 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, 1804 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text,
1789 size_t len, const SkPath& path, 1805 size_t len, const SkPath& path,
1790 const SkMatrix* m, const SkPaint& paint) { 1806 const SkMatrix* m, const SkPaint& paint) {
1791 CHECK_SHOULD_DRAW(draw, false); 1807 CHECK_SHOULD_DRAW(draw, false);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 GrTexture* texture, 1879 GrTexture* texture,
1864 bool needClear) 1880 bool needClear)
1865 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { 1881 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
1866 1882
1867 SkASSERT(texture && texture->asRenderTarget()); 1883 SkASSERT(texture && texture->asRenderTarget());
1868 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1884 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1869 // cache. We pass true for the third argument so that it will get unlocked. 1885 // cache. We pass true for the third argument so that it will get unlocked.
1870 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1886 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1871 fNeedClear = needClear; 1887 fNeedClear = needClear;
1872 } 1888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698