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

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

Issue 1178383003: Revert of 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
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/image/SkImage_Gpu.cpp » ('j') | 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 "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"
14 #include "GrGpu.h" 13 #include "GrGpu.h"
15 #include "GrGpuResourcePriv.h" 14 #include "GrGpuResourcePriv.h"
16 #include "GrLayerHoister.h" 15 #include "GrLayerHoister.h"
17 #include "GrRecordReplaceDraw.h" 16 #include "GrRecordReplaceDraw.h"
18 #include "GrStrokeInfo.h" 17 #include "GrStrokeInfo.h"
19 #include "GrTextContext.h" 18 #include "GrTextContext.h"
20 #include "GrTracing.h" 19 #include "GrTracing.h"
21 #include "SkCanvasPriv.h" 20 #include "SkCanvasPriv.h"
22 #include "SkDrawProcs.h" 21 #include "SkDrawProcs.h"
23 #include "SkErrorInternals.h" 22 #include "SkErrorInternals.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (!rt || rt->wasDestroyed()) { 130 if (!rt || rt->wasDestroyed()) {
132 return NULL; 131 return NULL;
133 } 132 }
134 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags)); 133 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags));
135 } 134 }
136 135
137 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) { 136 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) {
138 if (props) { 137 if (props) {
139 return SkDeviceProperties(props->pixelGeometry()); 138 return SkDeviceProperties(props->pixelGeometry());
140 } else { 139 } else {
141 return SkDeviceProperties(); 140 return SkDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType);
142 } 141 }
143 } 142 }
144 143
145 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { 144 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) {
146 if (props) { 145 if (props) {
147 return SkSurfaceProps(*props); 146 return SkSurfaceProps(*props);
148 } else { 147 } else {
149 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); 148 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
150 } 149 }
151 } 150 }
152 151
153 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, 152 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
154 const SkSurfaceProps* props, unsigned flags) 153 const SkSurfaceProps* props, unsigned flags)
155 : INHERITED(surfaceprops_to_deviceprops(props)) 154 : INHERITED(surfaceprops_to_deviceprops(props))
156 , fSurfaceProps(copy_or_default_props(props)) 155 , fSurfaceProps(copy_or_default_props(props))
157 { 156 {
158 fDrawProcs = NULL; 157 fDrawProcs = NULL;
159 158
160 fContext = SkRef(rt->getContext()); 159 fContext = SkRef(rt->getContext());
161 fNeedClear = flags & kNeedClear_Flag; 160 fNeedClear = flags & kNeedClear_Flag;
162 161
163 fRenderTarget = SkRef(rt); 162 fRenderTarget = SkRef(rt);
164 163
165 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height); 164 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height);
166 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); 165 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt));
167 fLegacyBitmap.setInfo(info); 166 fLegacyBitmap.setInfo(info);
168 fLegacyBitmap.setPixelRef(pr)->unref(); 167 fLegacyBitmap.setPixelRef(pr)->unref();
169 168
170 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); 169 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
171 fDrawContext.reset(SkRef(fContext->drawContext(&this->getLeakyProperties(), useDFT))); 170 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp erties(), useDFT);
171 fDrawContext.reset(SkRef(fContext->drawContext()));
172 } 172 }
173 173
174 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted, 174 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted,
175 const SkImageInfo& origInfo, int sampleCount) { 175 const SkImageInfo& origInfo, int sampleCount) {
176 if (kUnknown_SkColorType == origInfo.colorType() || 176 if (kUnknown_SkColorType == origInfo.colorType() ||
177 origInfo.width() < 0 || origInfo.height() < 0) { 177 origInfo.width() < 0 || origInfo.height() < 0) {
178 return NULL; 178 return NULL;
179 } 179 }
180 180
181 if (!context) { 181 if (!context) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 220 }
221 221
222 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag s)); 222 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag s));
223 } 223 }
224 224
225 SkGpuDevice::~SkGpuDevice() { 225 SkGpuDevice::~SkGpuDevice() {
226 if (fDrawProcs) { 226 if (fDrawProcs) {
227 delete fDrawProcs; 227 delete fDrawProcs;
228 } 228 }
229 229
230 SkDELETE(fTextContext);
231
230 fRenderTarget->unref(); 232 fRenderTarget->unref();
231 fContext->unref(); 233 fContext->unref();
232 } 234 }
233 235
234 /////////////////////////////////////////////////////////////////////////////// 236 ///////////////////////////////////////////////////////////////////////////////
235 237
236 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes, 238 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size _t dstRowBytes,
237 int x, int y) { 239 int x, int y) {
238 DO_DEFERRED_CLEAR(); 240 DO_DEFERRED_CLEAR();
239 241
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 348
347 SkASSERT(fRenderTarget != newRT); 349 SkASSERT(fRenderTarget != newRT);
348 350
349 fRenderTarget->unref(); 351 fRenderTarget->unref();
350 fRenderTarget = newRT.detach(); 352 fRenderTarget = newRT.detach();
351 353
352 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); 354 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info());
353 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info (), fRenderTarget)); 355 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info (), fRenderTarget));
354 fLegacyBitmap.setPixelRef(pr)->unref(); 356 fLegacyBitmap.setPixelRef(pr)->unref();
355 357
356 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); 358 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext()));
357 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->get LeakyProperties(),
358 useDFT)));
359 } 359 }
360 360
361 /////////////////////////////////////////////////////////////////////////////// 361 ///////////////////////////////////////////////////////////////////////////////
362 362
363 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 363 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
364 CHECK_SHOULD_DRAW(draw); 364 CHECK_SHOULD_DRAW(draw);
365 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); 365 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
366 366
367 GrPaint grPaint; 367 GrPaint grPaint;
368 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 368 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 CHECK_SHOULD_DRAW(draw); 1631 CHECK_SHOULD_DRAW(draw);
1632 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext); 1632 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
1633 1633
1634 GrPaint grPaint; 1634 GrPaint grPaint;
1635 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 1635 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
1636 return; 1636 return;
1637 } 1637 }
1638 1638
1639 SkDEBUGCODE(this->validate();) 1639 SkDEBUGCODE(this->validate();)
1640 1640
1641 fDrawContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, 1641 fTextContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix,
1642 (const char *)text, byteLength, x, y, draw.fClip->get Bounds()); 1642 (const char *)text, byteLength, x, y, draw.fClip->get Bounds());
1643 } 1643 }
1644 1644
1645 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength, 1645 void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL ength,
1646 const SkScalar pos[], int scalarsPerPos, 1646 const SkScalar pos[], int scalarsPerPos,
1647 const SkPoint& offset, const SkPaint& paint) { 1647 const SkPoint& offset, const SkPaint& paint) {
1648 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext); 1648 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
1649 CHECK_SHOULD_DRAW(draw); 1649 CHECK_SHOULD_DRAW(draw);
1650 1650
1651 GrPaint grPaint; 1651 GrPaint grPaint;
1652 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) { 1652 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t rue, &grPaint)) {
1653 return; 1653 return;
1654 } 1654 }
1655 1655
1656 SkDEBUGCODE(this->validate();) 1656 SkDEBUGCODE(this->validate();)
1657 1657
1658 fDrawContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x, 1658 fTextContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri x,
1659 (const char *)text, byteLength, pos, scalarsPerPos , offset, 1659 (const char *)text, byteLength, pos, scalarsPerPos , offset,
1660 draw.fClip->getBounds()); 1660 draw.fClip->getBounds());
1661 } 1661 }
1662 1662
1663 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca lar x, SkScalar y, 1663 void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca lar x, SkScalar y,
1664 const SkPaint& paint, SkDrawFilter* drawFilter) { 1664 const SkPaint& paint, SkDrawFilter* drawFilter) {
1665 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext); 1665 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawTextBlob", fContext);
1666 CHECK_SHOULD_DRAW(draw); 1666 CHECK_SHOULD_DRAW(draw);
1667 1667
1668 SkDEBUGCODE(this->validate();) 1668 SkDEBUGCODE(this->validate();)
1669 1669
1670 fDrawContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, 1670 fTextContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix,
1671 blob, x, y, drawFilter, draw.fClip->getBounds()); 1671 blob, x, y, drawFilter, draw.fClip->getBounds());
1672 } 1672 }
1673 1673
1674 /////////////////////////////////////////////////////////////////////////////// 1674 ///////////////////////////////////////////////////////////////////////////////
1675 1675
1676 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { 1676 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const {
1677 return GrTextContext::ShouldDisableLCD(paint); 1677 return GrTextContext::ShouldDisableLCD(paint);
1678 } 1678 }
1679 1679
1680 void SkGpuDevice::flush() { 1680 void SkGpuDevice::flush() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 #endif 1789 #endif
1790 } 1790 }
1791 1791
1792 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1792 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1793 // We always return a transient cache, so it is freed after each 1793 // We always return a transient cache, so it is freed after each
1794 // filter traversal. 1794 // filter traversal.
1795 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1795 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1796 } 1796 }
1797 1797
1798 #endif 1798 #endif
OLDNEW
« no previous file with comments | « 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