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

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

Issue 1175553002: Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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
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 "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrDrawContext.h" 12 #include "GrDrawContext.h"
13 #include "GrFontScaler.h"
13 #include "GrGpu.h" 14 #include "GrGpu.h"
14 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
15 #include "GrLayerHoister.h" 16 #include "GrLayerHoister.h"
16 #include "GrRecordReplaceDraw.h" 17 #include "GrRecordReplaceDraw.h"
17 #include "GrStrokeInfo.h" 18 #include "GrStrokeInfo.h"
18 #include "GrTextContext.h" 19 #include "GrTextContext.h"
19 #include "GrTracing.h" 20 #include "GrTracing.h"
20 #include "SkCanvasPriv.h" 21 #include "SkCanvasPriv.h"
21 #include "SkDeviceImageFilterProxy.h" 22 #include "SkDeviceImageFilterProxy.h"
23 #include "SkDeviceProperties.h"
22 #include "SkDrawProcs.h" 24 #include "SkDrawProcs.h"
23 #include "SkErrorInternals.h" 25 #include "SkErrorInternals.h"
24 #include "SkGlyphCache.h" 26 #include "SkGlyphCache.h"
25 #include "SkGrTexturePixelRef.h" 27 #include "SkGrTexturePixelRef.h"
26 #include "SkImage_Base.h" 28 #include "SkImage_Base.h"
27 #include "SkImageFilter.h" 29 #include "SkImageFilter.h"
28 #include "SkLayerInfo.h" 30 #include "SkLayerInfo.h"
29 #include "SkMaskFilter.h" 31 #include "SkMaskFilter.h"
30 #include "SkPathEffect.h" 32 #include "SkPathEffect.h"
31 #include "SkPicture.h" 33 #include "SkPicture.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (!rt || rt->wasDestroyed()) { 133 if (!rt || rt->wasDestroyed()) {
132 return NULL; 134 return NULL;
133 } 135 }
134 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags)); 136 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags));
135 } 137 }
136 138
137 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) { 139 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) {
138 if (props) { 140 if (props) {
139 return SkDeviceProperties(props->pixelGeometry()); 141 return SkDeviceProperties(props->pixelGeometry());
140 } else { 142 } else {
141 return SkDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType); 143 return SkDeviceProperties();
142 } 144 }
143 } 145 }
144 146
145 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { 147 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) {
146 if (props) { 148 if (props) {
147 return SkSurfaceProps(*props); 149 return SkSurfaceProps(*props);
148 } else { 150 } else {
149 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); 151 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
150 } 152 }
151 } 153 }
152 154
153 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, 155 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
154 const SkSurfaceProps* props, unsigned flags) 156 const SkSurfaceProps* props, unsigned flags)
155 : INHERITED(surfaceprops_to_deviceprops(props)) 157 : INHERITED(surfaceprops_to_deviceprops(props))
156 , fSurfaceProps(copy_or_default_props(props)) 158 , fSurfaceProps(copy_or_default_props(props))
157 { 159 {
158 fDrawProcs = NULL; 160 fDrawProcs = NULL;
159 161
160 fContext = SkRef(rt->getContext()); 162 fContext = SkRef(rt->getContext());
161 fNeedClear = flags & kNeedClear_Flag; 163 fNeedClear = flags & kNeedClear_Flag;
162 164
163 fRenderTarget = SkRef(rt); 165 fRenderTarget = SkRef(rt);
164 166
165 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height); 167 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height);
166 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); 168 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt));
167 fLegacyBitmap.setInfo(info); 169 fLegacyBitmap.setInfo(info);
168 fLegacyBitmap.setPixelRef(pr)->unref(); 170 fLegacyBitmap.setPixelRef(pr)->unref();
169 171
170 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); 172 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
171 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp erties(), useDFT); 173 fDrawContext.reset(SkRef(fContext->drawContext(&this->getLeakyProperties(), useDFT)));
172 fDrawContext.reset(SkRef(fContext->drawContext()));
173 } 174 }
174 175
175 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted, 176 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted,
176 const SkImageInfo& origInfo, int sampleCount) { 177 const SkImageInfo& origInfo, int sampleCount) {
177 if (kUnknown_SkColorType == origInfo.colorType() || 178 if (kUnknown_SkColorType == origInfo.colorType() ||
178 origInfo.width() < 0 || origInfo.height() < 0) { 179 origInfo.width() < 0 || origInfo.height() < 0) {
179 return NULL; 180 return NULL;
180 } 181 }
181 182
182 if (!context) { 183 if (!context) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 222 }
222 223
223 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag s)); 224 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag s));
224 } 225 }
225 226
226 SkGpuDevice::~SkGpuDevice() { 227 SkGpuDevice::~SkGpuDevice() {
227 if (fDrawProcs) { 228 if (fDrawProcs) {
228 delete fDrawProcs; 229 delete fDrawProcs;
229 } 230 }
230 231
231 SkDELETE(fTextContext);
232
233 fRenderTarget->unref(); 232 fRenderTarget->unref();
234 fContext->unref(); 233 fContext->unref();
235 } 234 }
236 235
237 /////////////////////////////////////////////////////////////////////////////// 236 ///////////////////////////////////////////////////////////////////////////////
238 237
239 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, 238 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes,
240 int x, int y) { 239 int x, int y) {
241 DO_DEFERRED_CLEAR(); 240 DO_DEFERRED_CLEAR();
242 241
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 339
341 SkASSERT(fRenderTarget != newRT); 340 SkASSERT(fRenderTarget != newRT);
342 341
343 fRenderTarget->unref(); 342 fRenderTarget->unref();
344 fRenderTarget = newRT.detach(); 343 fRenderTarget = newRT.detach();
345 344
346 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); 345 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info());
347 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info (), fRenderTarget)); 346 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info (), fRenderTarget));
348 fLegacyBitmap.setPixelRef(pr)->unref(); 347 fLegacyBitmap.setPixelRef(pr)->unref();
349 348
350 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext())); 349 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
350 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->get LeakyProperties(),
351 useDFT)));
351 } 352 }
352 353
353 /////////////////////////////////////////////////////////////////////////////// 354 ///////////////////////////////////////////////////////////////////////////////
354 355
355 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 356 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
356 CHECK_SHOULD_DRAW(draw); 357 CHECK_SHOULD_DRAW(draw);
357 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); 358 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
358 359
359 GrPaint grPaint; 360 GrPaint grPaint;
360 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 361 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 CHECK_SHOULD_DRAW(draw); 1624 CHECK_SHOULD_DRAW(draw);
1624 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1625 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
1625 1626
1626 GrPaint grPaint; 1627 GrPaint grPaint;
1627 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 1628 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
1628 return; 1629 return;
1629 } 1630 }
1630 1631
1631 SkDEBUGCODE(this->validate();) 1632 SkDEBUGCODE(this->validate();)
1632 1633
1633 fTextContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, 1634 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix,
1634 (const char *)text, byteLength, x, y, draw.fClip->get Bounds()); 1635 (const char *)text, byteLength, x, y, draw.fClip->get Bounds());
1635 } 1636 }
1636 1637
1637 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength, 1638 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength,
1638 const SkScalar pos[], int scalarsPerPos, 1639 const SkScalar pos[], int scalarsPerPos,
1639 const SkPoint& offset, const SkPaint& paint) { 1640 const SkPoint& offset, const SkPaint& paint) {
1640 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); 1641 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
1641 CHECK_SHOULD_DRAW(draw); 1642 CHECK_SHOULD_DRAW(draw);
1642 1643
1643 GrPaint grPaint; 1644 GrPaint grPaint;
1644 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 1645 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
1645 return; 1646 return;
1646 } 1647 }
1647 1648
1648 SkDEBUGCODE(this->validate();) 1649 SkDEBUGCODE(this->validate();)
1649 1650
1650 fTextContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x, 1651 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x,
1651 (const char *)text, byteLength, pos, scalarsPerPos , offset, 1652 (const char *)text, byteLength, pos, scalarsPerPos , offset,
1652 draw.fClip->getBounds()); 1653 draw.fClip->getBounds());
1653 } 1654 }
1654 1655
1655 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca lar x, SkScalar y, 1656 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca lar x, SkScalar y,
1656 const SkPaint& paint, SkDrawFilter* drawFilter) { 1657 const SkPaint& paint, SkDrawFilter* drawFilter) {
1657 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); 1658 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext);
1658 CHECK_SHOULD_DRAW(draw); 1659 CHECK_SHOULD_DRAW(draw);
1659 1660
1660 SkDEBUGCODE(this->validate();) 1661 SkDEBUGCODE(this->validate();)
1661 1662
1662 fTextContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, 1663 fDrawContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix,
1663 blob, x, y, drawFilter, draw.fClip->getBounds()); 1664 blob, x, y, drawFilter, draw.fClip->getBounds());
1664 } 1665 }
1665 1666
1666 /////////////////////////////////////////////////////////////////////////////// 1667 ///////////////////////////////////////////////////////////////////////////////
1667 1668
1668 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { 1669 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const {
1669 return GrTextContext::ShouldDisableLCD(paint); 1670 return GrTextContext::ShouldDisableLCD(paint);
1670 } 1671 }
1671 1672
1672 void SkGpuDevice::flush() { 1673 void SkGpuDevice::flush() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 #endif 1782 #endif
1782 } 1783 }
1783 1784
1784 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1785 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1785 // We always return a transient cache, so it is freed after each 1786 // We always return a transient cache, so it is freed after each
1786 // filter traversal. 1787 // filter traversal.
1787 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1788 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1788 } 1789 }
1789 1790
1790 #endif 1791 #endif
OLDNEW
« src/gpu/GrContext.cpp ('K') | « src/gpu/SkGpuDevice.h ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698