Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 144283002: Add factory class for generating various flavors of GrTextContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revise GrTextContext destruction. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/gpu/GrTextContext.h ('K') | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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>( );
bsalomon 2014/01/22 19:13:36 SkNEW()
jvanverth1 2014/01/22 20:28:40 Done.
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
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>( );
bsalomon 2014/01/22 19:13:36 SkNEW()
jvanverth1 2014/01/22 20:28:40 Done.
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
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;
bsalomon 2014/01/22 19:13:36 delete doesn't need a null check.
jvanverth1 2014/01/22 20:28:40 Done.
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
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 SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContex t, grPaint, paint));
1840 GrDistanceFieldTextContext* dfContext =
1841 static_cast<GrDistanceFieldTextConte xt*>(context.get());
1824 1842
1825 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert ies, NULL); 1843 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp erties, NULL);
1826 SkGlyphCache* cache = autoCache.getCache(); 1844 SkGlyphCache* cache = autoCache.getCache();
1827 GrFontScaler* fontScaler = get_gr_font_scaler(cache); 1845 GrFontScaler* fontScaler = get_gr_font_scaler(cache);
1828 1846
1829 context.drawText((const char *)text, byteLength, x, y, cache, fontScaler ); 1847 dfContext->drawText((const char *)text, byteLength, x, y, cache, fontSca ler);
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 SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContex t, grPaint, paint));
1840 myDraw.fProcs = this->initDrawForText(&context); 1858 myDraw.fProcs = this->initDrawForText(context.get());
1841 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint); 1859 this->INHERITED::drawText(myDraw, text, byteLength, x, y, paint);
1842 } 1860 }
1843 } 1861 }
1844 1862
1845 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, 1863 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
1846 size_t byteLength, const SkScalar pos[], 1864 size_t byteLength, const SkScalar pos[],
1847 SkScalar constY, int scalarsPerPos, 1865 SkScalar constY, int scalarsPerPos,
1848 const SkPaint& paint) { 1866 const SkPaint& paint) {
1849 CHECK_SHOULD_DRAW(draw, false); 1867 CHECK_SHOULD_DRAW(draw, false);
1850 1868
1851 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) { 1869 if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) {
1852 // this guy will just call our drawPath() 1870 // this guy will just call our drawPath()
1853 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY, 1871 draw.drawPosText_asPaths((const char*)text, byteLength, pos, constY,
1854 scalarsPerPos, paint); 1872 scalarsPerPos, paint);
1855 #if SK_DISTANCEFIELD_FONTS 1873 #if SK_DISTANCEFIELD_FONTS
1856 } else if (!paint.getRasterizer()) { 1874 } else if (!paint.getRasterizer()) {
1857 GrPaint grPaint; 1875 GrPaint grPaint;
1858 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1876 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1859 return; 1877 return;
1860 } 1878 }
1861 1879
1862 SkDEBUGCODE(this->validate();) 1880 SkDEBUGCODE(this->validate();)
1863 1881
1864 GrDistanceFieldTextContext context(fContext, grPaint, paint); 1882 SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContex t, grPaint, paint));
1865 1883 GrDistanceFieldTextContext* dfContext =
1866 SkAutoGlyphCache autoCache(context.getSkPaint(), &this->fLeakyPropert ies, NULL); 1884 static_cast<GrDistanceFieldTextConte xt*>(context.get());
1885
1886 SkAutoGlyphCache autoCache(dfContext->getSkPaint(), &this->fLeakyProp erties, 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 dfContext->drawPosText((const char *)text, byteLength, pos, constY, scal arsPerPos,
1871 cache, fontScaler); 1891 cache, fontScaler);
1872 #endif 1892 #endif
1873 } else { 1893 } else {
1874 SkDraw myDraw(draw); 1894 SkDraw myDraw(draw);
1875 1895
1876 GrPaint grPaint; 1896 GrPaint grPaint;
1877 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { 1897 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
1878 return; 1898 return;
1879 } 1899 }
1880 GrBitmapTextContext context(fContext, grPaint, paint.getColor()); 1900
1881 myDraw.fProcs = this->initDrawForText(&context); 1901 SkAutoTDelete<GrTextContext> context(fTextContextFactory->Create(fContex t, grPaint, paint));
1902 myDraw.fProcs = this->initDrawForText(context.get());
1882 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY, 1903 this->INHERITED::drawPosText(myDraw, text, byteLength, pos, constY,
1883 scalarsPerPos, paint); 1904 scalarsPerPos, paint);
1884 } 1905 }
1885 } 1906 }
1886 1907
1887 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text, 1908 void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text,
1888 size_t len, const SkPath& path, 1909 size_t len, const SkPath& path,
1889 const SkMatrix* m, const SkPaint& paint) { 1910 const SkMatrix* m, const SkPaint& paint) {
1890 CHECK_SHOULD_DRAW(draw, false); 1911 CHECK_SHOULD_DRAW(draw, false);
1891 1912
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 GrTexture* texture, 1983 GrTexture* texture,
1963 bool needClear) 1984 bool needClear)
1964 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { 1985 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
1965 1986
1966 SkASSERT(texture && texture->asRenderTarget()); 1987 SkASSERT(texture && texture->asRenderTarget());
1967 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1988 // 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. 1989 // cache. We pass true for the third argument so that it will get unlocked.
1969 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1990 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1970 fNeedClear = needClear; 1991 fNeedClear = needClear;
1971 } 1992 }
OLDNEW
« include/gpu/GrTextContext.h ('K') | « src/gpu/GrTextContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698