OLD | NEW |
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/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 fRenderTarget = SkRef(surface->asRenderTarget()); | 140 fRenderTarget = SkRef(surface->asRenderTarget()); |
141 | 141 |
142 SkImageInfo info = surface->surfacePriv().info(); | 142 SkImageInfo info = surface->surfacePriv().info(); |
143 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); | 143 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); |
144 fLegacyBitmap.setInfo(info); | 144 fLegacyBitmap.setInfo(info); |
145 fLegacyBitmap.setPixelRef(pr)->unref(); | 145 fLegacyBitmap.setPixelRef(pr)->unref(); |
146 | 146 |
147 this->setPixelGeometry(props.pixelGeometry()); | 147 this->setPixelGeometry(props.pixelGeometry()); |
148 | 148 |
149 bool useDFFonts = !!(flags & kDFFonts_Flag); | 149 bool useDFFonts = !!(flags & kDFFonts_Flag); |
150 fMainTextContext = fContext->createTextContext(fRenderTarget, this->getLeaky
Properties(), useDFFonts); | 150 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFFonts); |
151 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, this->getL
eakyProperties())); | |
152 } | 151 } |
153 | 152 |
154 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 153 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
155 const SkSurfaceProps& props, int sampleCount) { | 154 const SkSurfaceProps& props, int sampleCount) { |
156 if (kUnknown_SkColorType == origInfo.colorType() || | 155 if (kUnknown_SkColorType == origInfo.colorType() || |
157 origInfo.width() < 0 || origInfo.height() < 0) { | 156 origInfo.width() < 0 || origInfo.height() < 0) { |
158 return NULL; | 157 return NULL; |
159 } | 158 } |
160 | 159 |
161 SkColorType ct = origInfo.colorType(); | 160 SkColorType ct = origInfo.colorType(); |
(...skipping 23 matching lines...) Expand all Loading... |
185 } | 184 } |
186 | 185 |
187 return SkNEW_ARGS(SkGpuDevice, (texture.get(), props)); | 186 return SkNEW_ARGS(SkGpuDevice, (texture.get(), props)); |
188 } | 187 } |
189 | 188 |
190 SkGpuDevice::~SkGpuDevice() { | 189 SkGpuDevice::~SkGpuDevice() { |
191 if (fDrawProcs) { | 190 if (fDrawProcs) { |
192 delete fDrawProcs; | 191 delete fDrawProcs; |
193 } | 192 } |
194 | 193 |
195 delete fMainTextContext; | 194 delete fTextContext; |
196 delete fFallbackTextContext; | |
197 | 195 |
198 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 196 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
199 // target to be unnecessarily kept alive. | 197 // target to be unnecessarily kept alive. |
200 if (fContext->getRenderTarget() == fRenderTarget) { | 198 if (fContext->getRenderTarget() == fRenderTarget) { |
201 fContext->setRenderTarget(NULL); | 199 fContext->setRenderTarget(NULL); |
202 } | 200 } |
203 | 201 |
204 if (fContext->getClip() == &fClipData) { | 202 if (fContext->getClip() == &fClipData) { |
205 fContext->setClip(NULL); | 203 fContext->setClip(NULL); |
206 } | 204 } |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 } | 1676 } |
1679 | 1677 |
1680 /////////////////////////////////////////////////////////////////////////////// | 1678 /////////////////////////////////////////////////////////////////////////////// |
1681 | 1679 |
1682 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1680 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1683 size_t byteLength, SkScalar x, SkScalar y, | 1681 size_t byteLength, SkScalar x, SkScalar y, |
1684 const SkPaint& paint) { | 1682 const SkPaint& paint) { |
1685 CHECK_SHOULD_DRAW(draw, false); | 1683 CHECK_SHOULD_DRAW(draw, false); |
1686 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); | 1684 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); |
1687 | 1685 |
1688 if (fMainTextContext->canDraw(paint)) { | 1686 GrPaint grPaint; |
1689 GrPaint grPaint; | 1687 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
1690 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | |
1691 | 1688 |
1692 SkDEBUGCODE(this->validate();) | 1689 SkDEBUGCODE(this->validate();) |
1693 | 1690 |
1694 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt
h, x, y); | 1691 if (!fTextContext->drawText(grPaint, paint, (const char *)text, byteLength,
x, y)) { |
1695 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { | 1692 // this will just call our drawPath() |
1696 GrPaint grPaint; | |
1697 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | |
1698 | |
1699 SkDEBUGCODE(this->validate();) | |
1700 | |
1701 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL
ength, x, y); | |
1702 } else { | |
1703 // this guy will just call our drawPath() | |
1704 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); | 1693 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
1705 } | 1694 } |
1706 } | 1695 } |
1707 | 1696 |
1708 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
ength, | 1697 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
ength, |
1709 const SkScalar pos[], int scalarsPerPos, | 1698 const SkScalar pos[], int scalarsPerPos, |
1710 const SkPoint& offset, const SkPaint& paint) { | 1699 const SkPoint& offset, const SkPaint& paint) { |
1711 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); | 1700 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); |
1712 CHECK_SHOULD_DRAW(draw, false); | 1701 CHECK_SHOULD_DRAW(draw, false); |
1713 | 1702 |
1714 if (fMainTextContext->canDraw(paint)) { | 1703 GrPaint grPaint; |
1715 GrPaint grPaint; | 1704 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
1716 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | |
1717 | 1705 |
1718 SkDEBUGCODE(this->validate();) | 1706 SkDEBUGCODE(this->validate();) |
1719 | 1707 |
1720 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe
ngth, pos, | 1708 if (!fTextContext->drawPosText(grPaint, paint, (const char *)text, byteLengt
h, pos, |
1721 scalarsPerPos, offset); | 1709 scalarsPerPos, offset)) { |
1722 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { | 1710 // this will just call our drawPath() |
1723 GrPaint grPaint; | |
1724 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | |
1725 | |
1726 SkDEBUGCODE(this->validate();) | |
1727 | |
1728 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by
teLength, pos, | |
1729 scalarsPerPos, offset); | |
1730 } else { | |
1731 draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerP
os, offset, paint); | 1711 draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerP
os, offset, paint); |
1732 } | 1712 } |
1733 } | 1713 } |
1734 | 1714 |
1735 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1715 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
1736 size_t len, const SkPath& path, | 1716 size_t len, const SkPath& path, |
1737 const SkMatrix* m, const SkPaint& paint) { | 1717 const SkMatrix* m, const SkPaint& paint) { |
1738 CHECK_SHOULD_DRAW(draw, false); | 1718 CHECK_SHOULD_DRAW(draw, false); |
1739 | 1719 |
1740 SkASSERT(draw.fDevice == this); | 1720 SkASSERT(draw.fDevice == this); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 GrLayerHoister::UnlockLayers(fContext, atlased, nonAtlased, recycled); | 1838 GrLayerHoister::UnlockLayers(fContext, atlased, nonAtlased, recycled); |
1859 | 1839 |
1860 return true; | 1840 return true; |
1861 } | 1841 } |
1862 | 1842 |
1863 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1843 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1864 // We always return a transient cache, so it is freed after each | 1844 // We always return a transient cache, so it is freed after each |
1865 // filter traversal. | 1845 // filter traversal. |
1866 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1846 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1867 } | 1847 } |
OLD | NEW |