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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 void SkGpuDevice::initFromRenderTarget(GrContext* context, | 195 void SkGpuDevice::initFromRenderTarget(GrContext* context, |
196 GrRenderTarget* renderTarget, | 196 GrRenderTarget* renderTarget, |
197 bool cached) { | 197 bool cached) { |
198 fDrawProcs = NULL; | 198 fDrawProcs = NULL; |
199 | 199 |
200 fContext = context; | 200 fContext = context; |
201 fContext->ref(); | 201 fContext->ref(); |
202 | 202 |
203 #if SK_DISTANCEFIELD_FONTS | 203 #if SK_DISTANCEFIELD_FONTS |
204 fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext
>); | 204 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP
roperties)); |
| 205 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); |
205 #else | 206 #else |
206 fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>); | 207 fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperti
es)); |
| 208 fFallbackTextContext = NULL; |
207 #endif | 209 #endif |
208 | 210 |
209 fRenderTarget = NULL; | 211 fRenderTarget = NULL; |
210 fNeedClear = false; | 212 fNeedClear = false; |
211 | 213 |
212 SkASSERT(NULL != renderTarget); | 214 SkASSERT(NULL != renderTarget); |
213 fRenderTarget = renderTarget; | 215 fRenderTarget = renderTarget; |
214 fRenderTarget->ref(); | 216 fRenderTarget->ref(); |
215 | 217 |
216 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 218 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
(...skipping 18 matching lines...) Expand all Loading... |
235 int height, | 237 int height, |
236 int sampleCount) | 238 int sampleCount) |
237 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) | 239 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) |
238 { | 240 { |
239 fDrawProcs = NULL; | 241 fDrawProcs = NULL; |
240 | 242 |
241 fContext = context; | 243 fContext = context; |
242 fContext->ref(); | 244 fContext->ref(); |
243 | 245 |
244 #if SK_DISTANCEFIELD_FONTS | 246 #if SK_DISTANCEFIELD_FONTS |
245 fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext
>); | 247 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP
roperties)); |
| 248 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); |
246 #else | 249 #else |
247 fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>); | 250 fMainTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProperti
es)); |
| 251 fFallbackTextContext = NULL; |
248 #endif | 252 #endif |
249 | 253 |
250 fRenderTarget = NULL; | 254 fRenderTarget = NULL; |
251 fNeedClear = false; | 255 fNeedClear = false; |
252 | 256 |
253 if (config != SkBitmap::kRGB_565_Config) { | 257 if (config != SkBitmap::kRGB_565_Config) { |
254 config = SkBitmap::kARGB_8888_Config; | 258 config = SkBitmap::kARGB_8888_Config; |
255 } | 259 } |
256 | 260 |
257 GrTextureDesc desc; | 261 GrTextureDesc desc; |
(...skipping 27 matching lines...) Expand all Loading... |
285 width, height); | 289 width, height); |
286 SkASSERT(false); | 290 SkASSERT(false); |
287 } | 291 } |
288 } | 292 } |
289 | 293 |
290 SkGpuDevice::~SkGpuDevice() { | 294 SkGpuDevice::~SkGpuDevice() { |
291 if (fDrawProcs) { | 295 if (fDrawProcs) { |
292 delete fDrawProcs; | 296 delete fDrawProcs; |
293 } | 297 } |
294 | 298 |
295 delete fTextContextManager; | 299 delete fMainTextContext; |
| 300 delete fFallbackTextContext; |
296 | 301 |
297 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 302 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
298 // target to be unnecessarily kept alive. | 303 // target to be unnecessarily kept alive. |
299 if (fContext->getRenderTarget() == fRenderTarget) { | 304 if (fContext->getRenderTarget() == fRenderTarget) { |
300 fContext->setRenderTarget(NULL); | 305 fContext->setRenderTarget(NULL); |
301 } | 306 } |
302 | 307 |
303 if (fContext->getClip() == &fClipData) { | 308 if (fContext->getClip() == &fClipData) { |
304 fContext->setClip(NULL); | 309 fContext->setClip(NULL); |
305 } | 310 } |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 indexCount); | 1776 indexCount); |
1772 } | 1777 } |
1773 | 1778 |
1774 /////////////////////////////////////////////////////////////////////////////// | 1779 /////////////////////////////////////////////////////////////////////////////// |
1775 | 1780 |
1776 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, | 1781 void SkGpuDevice::drawText(const SkDraw& draw, const void* text, |
1777 size_t byteLength, SkScalar x, SkScalar y, | 1782 size_t byteLength, SkScalar x, SkScalar y, |
1778 const SkPaint& paint) { | 1783 const SkPaint& paint) { |
1779 CHECK_SHOULD_DRAW(draw, false); | 1784 CHECK_SHOULD_DRAW(draw, false); |
1780 | 1785 |
1781 if (fTextContextManager->canDraw(paint, fContext->getMatrix())) { | 1786 if (fMainTextContext->canDraw(paint)) { |
1782 GrPaint grPaint; | 1787 GrPaint grPaint; |
1783 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1788 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1784 return; | 1789 return; |
1785 } | 1790 } |
1786 | 1791 |
1787 SkDEBUGCODE(this->validate();) | 1792 SkDEBUGCODE(this->validate();) |
1788 | 1793 |
1789 SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->conte
xt(), | 1794 fMainTextContext->drawText(grPaint, paint, (const char *)text, byteLengt
h, x, y); |
1790 grPaint, pa
int, | 1795 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
1791 this->getDe
viceProperties())); | |
1792 ctx->drawText((const char *)text, byteLength, x, y); | |
1793 } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) { | |
1794 GrPaint grPaint; | 1796 GrPaint grPaint; |
1795 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1797 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1796 return; | 1798 return; |
1797 } | 1799 } |
1798 | 1800 |
1799 SkDEBUGCODE(this->validate();) | 1801 SkDEBUGCODE(this->validate();) |
1800 | 1802 |
1801 GrBitmapTextContext textContext(this->context(), grPaint, paint, | 1803 fFallbackTextContext->drawText(grPaint, paint, (const char *)text, byteL
ength, x, y); |
1802 this->getDeviceProperties()); | |
1803 textContext.drawText((const char *)text, byteLength, x, y); | |
1804 } else { | 1804 } else { |
1805 // this guy will just call our drawPath() | 1805 // this guy will just call our drawPath() |
1806 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); | 1806 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
1807 } | 1807 } |
1808 } | 1808 } |
1809 | 1809 |
1810 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1810 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
1811 size_t byteLength, const SkScalar pos[], | 1811 size_t byteLength, const SkScalar pos[], |
1812 SkScalar constY, int scalarsPerPos, | 1812 SkScalar constY, int scalarsPerPos, |
1813 const SkPaint& paint) { | 1813 const SkPaint& paint) { |
1814 CHECK_SHOULD_DRAW(draw, false); | 1814 CHECK_SHOULD_DRAW(draw, false); |
1815 | 1815 |
1816 if (fTextContextManager->canDraw(paint, fContext->getMatrix())) { | 1816 if (fMainTextContext->canDraw(paint)) { |
1817 GrPaint grPaint; | 1817 GrPaint grPaint; |
1818 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1818 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1819 return; | 1819 return; |
1820 } | 1820 } |
1821 | 1821 |
1822 SkDEBUGCODE(this->validate();) | 1822 SkDEBUGCODE(this->validate();) |
1823 | 1823 |
1824 SkAutoTDelete<GrTextContext> ctx(fTextContextManager->create(this->conte
xt(), | 1824 fMainTextContext->drawPosText(grPaint, paint, (const char *)text, byteLe
ngth, pos, |
1825 grPaint, pa
int, | 1825 constY, scalarsPerPos); |
1826 this->getDe
viceProperties())); | 1826 } else if (fFallbackTextContext && fFallbackTextContext->canDraw(paint)) { |
1827 ctx->drawPosText((const char *)text, byteLength, pos, constY, scalarsPer
Pos); | |
1828 } else if (GrBitmapTextContext::CanDraw(paint, fContext->getMatrix())) { | |
1829 GrPaint grPaint; | 1827 GrPaint grPaint; |
1830 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1828 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1831 return; | 1829 return; |
1832 } | 1830 } |
1833 | 1831 |
1834 SkDEBUGCODE(this->validate();) | 1832 SkDEBUGCODE(this->validate();) |
1835 | 1833 |
1836 GrBitmapTextContext textContext(this->context(), grPaint, paint, | 1834 fFallbackTextContext->drawPosText(grPaint, paint, (const char *)text, by
teLength, pos, |
1837 this->getDeviceProperties()); | 1835 constY, scalarsPerPos); |
1838 textContext.drawPosText((const char *)text, byteLength, pos, constY, sca
larsPerPos); | |
1839 } else { | 1836 } else { |
1840 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, | 1837 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
1841 scalarsPerPos, paint); | 1838 scalarsPerPos, paint); |
1842 } | 1839 } |
1843 } | 1840 } |
1844 | 1841 |
1845 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1842 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
1846 size_t len, const SkPath& path, | 1843 size_t len, const SkPath& path, |
1847 const SkMatrix* m, const SkPaint& paint) { | 1844 const SkMatrix* m, const SkPaint& paint) { |
1848 CHECK_SHOULD_DRAW(draw, false); | 1845 CHECK_SHOULD_DRAW(draw, false); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 GrTexture* texture, | 1917 GrTexture* texture, |
1921 bool needClear) | 1918 bool needClear) |
1922 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1919 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1923 | 1920 |
1924 SkASSERT(texture && texture->asRenderTarget()); | 1921 SkASSERT(texture && texture->asRenderTarget()); |
1925 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1922 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1926 // cache. We pass true for the third argument so that it will get unlocked. | 1923 // cache. We pass true for the third argument so that it will get unlocked. |
1927 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1924 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1928 fNeedClear = needClear; | 1925 fNeedClear = needClear; |
1929 } | 1926 } |
OLD | NEW |