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