| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 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 |
| 204 fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext
>); |
| 205 #else |
| 206 fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>); |
| 207 #endif |
| 208 |
| 203 fRenderTarget = NULL; | 209 fRenderTarget = NULL; |
| 204 fNeedClear = false; | 210 fNeedClear = false; |
| 205 | 211 |
| 206 SkASSERT(NULL != renderTarget); | 212 SkASSERT(NULL != renderTarget); |
| 207 fRenderTarget = renderTarget; | 213 fRenderTarget = renderTarget; |
| 208 fRenderTarget->ref(); | 214 fRenderTarget->ref(); |
| 209 | 215 |
| 210 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 216 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
| 211 // on the RT but not vice-versa. | 217 // on the RT but not vice-versa. |
| 212 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 218 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
| (...skipping 15 matching lines...) Expand all Loading... |
| 228 int width, | 234 int width, |
| 229 int height, | 235 int height, |
| 230 int sampleCount) | 236 int sampleCount) |
| 231 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) | 237 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) |
| 232 { | 238 { |
| 233 fDrawProcs = NULL; | 239 fDrawProcs = NULL; |
| 234 | 240 |
| 235 fContext = context; | 241 fContext = context; |
| 236 fContext->ref(); | 242 fContext->ref(); |
| 237 | 243 |
| 244 #if SK_DISTANCEFIELD_FONTS |
| 245 fTextContextManager = SkNEW(GrTTextContextManager<GrDistanceFieldTextContext
>); |
| 246 #else |
| 247 fTextContextManager = SkNEW(GrTTextContextManager<GrBitmapTextContext>); |
| 248 #endif |
| 249 |
| 238 fRenderTarget = NULL; | 250 fRenderTarget = NULL; |
| 239 fNeedClear = false; | 251 fNeedClear = false; |
| 240 | 252 |
| 241 if (config != SkBitmap::kRGB_565_Config) { | 253 if (config != SkBitmap::kRGB_565_Config) { |
| 242 config = SkBitmap::kARGB_8888_Config; | 254 config = SkBitmap::kARGB_8888_Config; |
| 243 } | 255 } |
| 244 | 256 |
| 245 GrTextureDesc desc; | 257 GrTextureDesc desc; |
| 246 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 258 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 247 desc.fWidth = width; | 259 desc.fWidth = width; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 272 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", | 284 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", |
| 273 width, height); | 285 width, height); |
| 274 SkASSERT(false); | 286 SkASSERT(false); |
| 275 } | 287 } |
| 276 } | 288 } |
| 277 | 289 |
| 278 SkGpuDevice::~SkGpuDevice() { | 290 SkGpuDevice::~SkGpuDevice() { |
| 279 if (fDrawProcs) { | 291 if (fDrawProcs) { |
| 280 delete fDrawProcs; | 292 delete fDrawProcs; |
| 281 } | 293 } |
| 294 |
| 295 delete fTextContextManager; |
| 282 | 296 |
| 283 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 297 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
| 284 // target to be unnecessarily kept alive. | 298 // target to be unnecessarily kept alive. |
| 285 if (fContext->getRenderTarget() == fRenderTarget) { | 299 if (fContext->getRenderTarget() == fRenderTarget) { |
| 286 fContext->setRenderTarget(NULL); | 300 fContext->setRenderTarget(NULL); |
| 287 } | 301 } |
| 288 | 302 |
| 289 if (fContext->getClip() == &fClipData) { | 303 if (fContext->getClip() == &fClipData) { |
| 290 fContext->setClip(NULL); | 304 fContext->setClip(NULL); |
| 291 } | 305 } |
| (...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); | 1827 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
| 1814 #if SK_DISTANCEFIELD_FONTS | 1828 #if SK_DISTANCEFIELD_FONTS |
| 1815 } else if (!paint.getRasterizer()) { | 1829 } else if (!paint.getRasterizer()) { |
| 1816 GrPaint grPaint; | 1830 GrPaint grPaint; |
| 1817 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1831 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1818 return; | 1832 return; |
| 1819 } | 1833 } |
| 1820 | 1834 |
| 1821 SkDEBUGCODE(this->validate();) | 1835 SkDEBUGCODE(this->validate();) |
| 1822 | 1836 |
| 1823 GrDistanceFieldTextContext context(fContext, grPaint, paint); | 1837 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex
t, grPaint, paint)); |
| 1838 GrDistanceFieldTextContext* dfContext = |
| 1839 static_cast<GrDistanceFieldTextConte
xt*>(context.get()); |
| 1824 | 1840 |
| 1825 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert
ies, NULL); | 1841 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp
erties, NULL); |
| 1826 SkGlyphCache* cache = autoCache.getCache(); | 1842 SkGlyphCache* cache = autoCache.getCache(); |
| 1827 GrFontScaler* fontScaler = get_gr_font_scaler(cache); | 1843 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
| 1828 | 1844 |
| 1829 context.drawText((const char *)text, byteLength, x, y, cache, fontScaler
); | 1845 dfContext->drawText((const char *)text, byteLength, x, y, cache, fontSca
ler); |
| 1830 #endif | 1846 #endif |
| 1831 } else { | 1847 } else { |
| 1832 SkDraw myDraw(draw); | 1848 SkDraw myDraw(draw); |
| 1833 | 1849 |
| 1834 GrPaint grPaint; | 1850 GrPaint grPaint; |
| 1835 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1851 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1836 return; | 1852 return; |
| 1837 } | 1853 } |
| 1838 | 1854 |
| 1839 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1855 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex
t, grPaint, paint)); |
| 1840 myDraw.fProcs = this->initDrawForText(&context); | 1856 myDraw.fProcs = this->initDrawForText(context.get()); |
| 1841 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); | 1857 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
| 1842 } | 1858 } |
| 1843 } | 1859 } |
| 1844 | 1860 |
| 1845 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1861 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
| 1846 size_t byteLength, const SkScalar pos[], | 1862 size_t byteLength, const SkScalar pos[], |
| 1847 SkScalar constY, int scalarsPerPos, | 1863 SkScalar constY, int scalarsPerPos, |
| 1848 const SkPaint& paint) { | 1864 const SkPaint& paint) { |
| 1849 CHECK_SHOULD_DRAW(draw, false); | 1865 CHECK_SHOULD_DRAW(draw, false); |
| 1850 | 1866 |
| 1851 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { | 1867 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
| 1852 // this guy will just call our drawPath() | 1868 // this guy will just call our drawPath() |
| 1853 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, | 1869 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
| 1854 scalarsPerPos, paint); | 1870 scalarsPerPos, paint); |
| 1855 #if SK_DISTANCEFIELD_FONTS | 1871 #if SK_DISTANCEFIELD_FONTS |
| 1856 } else if (!paint.getRasterizer()) { | 1872 } else if (!paint.getRasterizer()) { |
| 1857 GrPaint grPaint; | 1873 GrPaint grPaint; |
| 1858 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1874 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1859 return; | 1875 return; |
| 1860 } | 1876 } |
| 1861 | 1877 |
| 1862 SkDEBUGCODE(this->validate();) | 1878 SkDEBUGCODE(this->validate();) |
| 1863 | 1879 |
| 1864 GrDistanceFieldTextContext context(fContext, grPaint, paint); | 1880 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex
t, grPaint, paint)); |
| 1865 | 1881 GrDistanceFieldTextContext* dfContext = |
| 1866 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert
ies, NULL); | 1882 static_cast<GrDistanceFieldTextConte
xt*>(context.get()); |
| 1883 |
| 1884 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp
erties, NULL); |
| 1867 SkGlyphCache* cache = autoCache.getCache(); | 1885 SkGlyphCache* cache = autoCache.getCache(); |
| 1868 GrFontScaler* fontScaler = get_gr_font_scaler(cache); | 1886 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
| 1869 | 1887 |
| 1870 context.drawPosText((const char *)text, byteLength, pos, constY, scalars
PerPos, | 1888 dfContext->drawPosText((const char *)text, byteLength, pos, constY, scal
arsPerPos, |
| 1871 cache, fontScaler); | 1889 cache, fontScaler); |
| 1872 #endif | 1890 #endif |
| 1873 } else { | 1891 } else { |
| 1874 SkDraw myDraw(draw); | 1892 SkDraw myDraw(draw); |
| 1875 | 1893 |
| 1876 GrPaint grPaint; | 1894 GrPaint grPaint; |
| 1877 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1895 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 1878 return; | 1896 return; |
| 1879 } | 1897 } |
| 1880 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1898 |
| 1881 myDraw.fProcs = this->initDrawForText(&context); | 1899 SkAutoTDelete<GrTextContext> context(fTextContextManager->create(fContex
t, grPaint, paint)); |
| 1900 myDraw.fProcs = this->initDrawForText(context.get()); |
| 1882 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, | 1901 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
| 1883 scalarsPerPos, paint); | 1902 scalarsPerPos, paint); |
| 1884 } | 1903 } |
| 1885 } | 1904 } |
| 1886 | 1905 |
| 1887 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1906 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
| 1888 size_t len, const SkPath& path, | 1907 size_t len, const SkPath& path, |
| 1889 const SkMatrix* m, const SkPaint& paint) { | 1908 const SkMatrix* m, const SkPaint& paint) { |
| 1890 CHECK_SHOULD_DRAW(draw, false); | 1909 CHECK_SHOULD_DRAW(draw, false); |
| 1891 | 1910 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 GrTexture* texture, | 1981 GrTexture* texture, |
| 1963 bool needClear) | 1982 bool needClear) |
| 1964 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1983 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| 1965 | 1984 |
| 1966 SkASSERT(texture && texture->asRenderTarget()); | 1985 SkASSERT(texture && texture->asRenderTarget()); |
| 1967 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1986 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
| 1968 // cache. We pass true for the third argument so that it will get unlocked. | 1987 // cache. We pass true for the third argument so that it will get unlocked. |
| 1969 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1988 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
| 1970 fNeedClear = needClear; | 1989 fNeedClear = needClear; |
| 1971 } | 1990 } |
| OLD | NEW |