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 fTextContextFactory = new GrTTextContextFactory<GrDistanceFieldTextContext>( ); | |
205 #else | |
206 fTextContextFactory = new GrTTextContextFactory<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 fTextContextFactory = new GrTTextContextFactory<GrDistanceFieldTextContext>( ); | |
246 #else | |
247 fTextContextFactory = new GrTTextContextFactory<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 if (fTextContextFactory) { | |
296 delete fTextContextFactory; | |
297 } | |
282 | 298 |
283 // The GrContext takes a ref on the target. We don't want to cause the rende r | 299 // The GrContext takes a ref on the target. We don't want to cause the rende r |
284 // target to be unnecessarily kept alive. | 300 // target to be unnecessarily kept alive. |
285 if (fContext->getRenderTarget() == fRenderTarget) { | 301 if (fContext->getRenderTarget() == fRenderTarget) { |
286 fContext->setRenderTarget(NULL); | 302 fContext->setRenderTarget(NULL); |
287 } | 303 } |
288 | 304 |
289 if (fContext->getClip() == &fClipData) { | 305 if (fContext->getClip() == &fClipData) { |
290 fContext->setClip(NULL); | 306 fContext->setClip(NULL); |
291 } | 307 } |
(...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1813 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); | 1829 draw.drawText_asPaths((const char*)text, byteLength, x, y, paint); |
1814 #if SK_DISTANCEFIELD_FONTS | 1830 #if SK_DISTANCEFIELD_FONTS |
1815 } else if (!paint.getRasterizer()) { | 1831 } else if (!paint.getRasterizer()) { |
1816 GrPaint grPaint; | 1832 GrPaint grPaint; |
1817 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1833 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1818 return; | 1834 return; |
1819 } | 1835 } |
1820 | 1836 |
1821 SkDEBUGCODE(this->validate();) | 1837 SkDEBUGCODE(this->validate();) |
1822 | 1838 |
1823 GrDistanceFieldTextContext context(fContext, grPaint, paint); | 1839 GrDistanceFieldTextContext* context = |
1840 (GrDistanceFieldTextContext*) fTextContextFactory->Create(fConte xt, grPaint, paint); | |
1824 | 1841 |
1825 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert ies, NULL); | 1842 SkAutoGlyphCache autoCache(context->getSkPaint(), &this->fLeakyProper ties, NULL); |
1826 SkGlyphCache* cache = autoCache.getCache(); | 1843 SkGlyphCache* cache = autoCache.getCache(); |
1827 GrFontScaler* fontScaler = get_gr_font_scaler(cache); | 1844 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
1828 | 1845 |
1829 context.drawText((const char *)text, byteLength, x, y, cache, fontScaler ); | 1846 context->drawText((const char *)text, byteLength, x, y, cache, fontScale r); |
1847 fTextContextFactory->Destroy(context); | |
1830 #endif | 1848 #endif |
1831 } else { | 1849 } else { |
1832 SkDraw myDraw(draw); | 1850 SkDraw myDraw(draw); |
1833 | 1851 |
1834 GrPaint grPaint; | 1852 GrPaint grPaint; |
1835 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1853 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1836 return; | 1854 return; |
1837 } | 1855 } |
1838 | 1856 |
1839 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1857 GrTextContext* context = fTextContextFactory->Create(fContext, grPaint, paint); |
1840 myDraw.fProcs = this->initDrawForText(&context); | 1858 myDraw.fProcs = this->initDrawForText(context); |
1841 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); | 1859 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); |
1860 fTextContextFactory->Destroy(context); | |
1842 } | 1861 } |
1843 } | 1862 } |
1844 | 1863 |
1845 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, | 1864 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, |
1846 size_t byteLength, const SkScalar pos[], | 1865 size_t byteLength, const SkScalar pos[], |
1847 SkScalar constY, int scalarsPerPos, | 1866 SkScalar constY, int scalarsPerPos, |
1848 const SkPaint& paint) { | 1867 const SkPaint& paint) { |
1849 CHECK_SHOULD_DRAW(draw, false); | 1868 CHECK_SHOULD_DRAW(draw, false); |
1850 | 1869 |
1851 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { | 1870 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { |
1852 // this guy will just call our drawPath() | 1871 // this guy will just call our drawPath() |
1853 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, | 1872 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, |
1854 scalarsPerPos, paint); | 1873 scalarsPerPos, paint); |
1855 #if SK_DISTANCEFIELD_FONTS | 1874 #if SK_DISTANCEFIELD_FONTS |
1856 } else if (!paint.getRasterizer()) { | 1875 } else if (!paint.getRasterizer()) { |
1857 GrPaint grPaint; | 1876 GrPaint grPaint; |
1858 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1877 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1859 return; | 1878 return; |
1860 } | 1879 } |
1861 | 1880 |
1862 SkDEBUGCODE(this->validate();) | 1881 SkDEBUGCODE(this->validate();) |
1863 | 1882 |
1864 GrDistanceFieldTextContext context(fContext, grPaint, paint); | 1883 GrDistanceFieldTextContext* context = |
1884 (GrDistanceFieldTextContext*) fTextContextFactory->Create(fConte xt, grPaint, paint); | |
bsalomon
2014/01/21 20:46:17
Does phase 2 remove the need for this downcast?
jvanverth1
2014/01/21 21:10:56
Yes. The current shared interface is for working w
| |
1865 | 1885 |
1866 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert ies, NULL); | 1886 SkAutoGlyphCache autoCache(context->getSkPaint(), &this->fLeakyProper ties, NULL); |
1867 SkGlyphCache* cache = autoCache.getCache(); | 1887 SkGlyphCache* cache = autoCache.getCache(); |
1868 GrFontScaler* fontScaler = get_gr_font_scaler(cache); | 1888 GrFontScaler* fontScaler = get_gr_font_scaler(cache); |
1869 | 1889 |
1870 context.drawPosText((const char *)text, byteLength, pos, constY, scalars PerPos, | 1890 context->drawPosText((const char *)text, byteLength, pos, constY, scalar sPerPos, |
1871 cache, fontScaler); | 1891 cache, fontScaler); |
1892 fTextContextFactory->Destroy(context); | |
1872 #endif | 1893 #endif |
1873 } else { | 1894 } else { |
1874 SkDraw myDraw(draw); | 1895 SkDraw myDraw(draw); |
1875 | 1896 |
1876 GrPaint grPaint; | 1897 GrPaint grPaint; |
1877 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 1898 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
1878 return; | 1899 return; |
1879 } | 1900 } |
1880 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); | 1901 |
1881 myDraw.fProcs = this->initDrawForText(&context); | 1902 GrTextContext* context = fTextContextFactory->Create(fContext, grPaint, paint); |
1903 myDraw.fProcs = this->initDrawForText(context); | |
1882 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, | 1904 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, |
1883 scalarsPerPos, paint); | 1905 scalarsPerPos, paint); |
1906 fTextContextFactory->Destroy(context); | |
1884 } | 1907 } |
1885 } | 1908 } |
1886 | 1909 |
1887 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 1910 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
1888 size_t len, const SkPath& path, | 1911 size_t len, const SkPath& path, |
1889 const SkMatrix* m, const SkPaint& paint) { | 1912 const SkMatrix* m, const SkPaint& paint) { |
1890 CHECK_SHOULD_DRAW(draw, false); | 1913 CHECK_SHOULD_DRAW(draw, false); |
1891 | 1914 |
1892 SkASSERT(draw.fDevice == this); | 1915 SkASSERT(draw.fDevice == this); |
1893 draw.drawTextOnPath((const char*)text, len, path, m, paint); | 1916 draw.drawTextOnPath((const char*)text, len, path, m, paint); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1962 GrTexture* texture, | 1985 GrTexture* texture, |
1963 bool needClear) | 1986 bool needClear) |
1964 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1987 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1965 | 1988 |
1966 SkASSERT(texture && texture->asRenderTarget()); | 1989 SkASSERT(texture && texture->asRenderTarget()); |
1967 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture | 1990 // 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. | 1991 // cache. We pass true for the third argument so that it will get unlocked. |
1969 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1992 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1970 fNeedClear = needClear; | 1993 fNeedClear = needClear; |
1971 } | 1994 } |
OLD | NEW |