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 "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 "SkDrawProcs.h" | 22 #include "SkDrawProcs.h" |
22 #include "SkErrorInternals.h" | 23 #include "SkErrorInternals.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (!rt || rt->wasDestroyed()) { | 131 if (!rt || rt->wasDestroyed()) { |
131 return NULL; | 132 return NULL; |
132 } | 133 } |
133 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags)); | 134 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags)); |
134 } | 135 } |
135 | 136 |
136 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop
s) { | 137 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop
s) { |
137 if (props) { | 138 if (props) { |
138 return SkDeviceProperties(props->pixelGeometry()); | 139 return SkDeviceProperties(props->pixelGeometry()); |
139 } else { | 140 } else { |
140 return SkDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType); | 141 return SkDeviceProperties(); |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { | 145 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { |
145 if (props) { | 146 if (props) { |
146 return SkSurfaceProps(*props); | 147 return SkSurfaceProps(*props); |
147 } else { | 148 } else { |
148 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 149 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 153 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
153 const SkSurfaceProps* props, unsigned flags) | 154 const SkSurfaceProps* props, unsigned flags) |
154 : INHERITED(surfaceprops_to_deviceprops(props)) | 155 : INHERITED(surfaceprops_to_deviceprops(props)) |
155 , fSurfaceProps(copy_or_default_props(props)) | 156 , fSurfaceProps(copy_or_default_props(props)) |
156 { | 157 { |
157 fDrawProcs = NULL; | 158 fDrawProcs = NULL; |
158 | 159 |
159 fContext = SkRef(rt->getContext()); | 160 fContext = SkRef(rt->getContext()); |
160 fNeedClear = flags & kNeedClear_Flag; | 161 fNeedClear = flags & kNeedClear_Flag; |
161 | 162 |
162 fRenderTarget = SkRef(rt); | 163 fRenderTarget = SkRef(rt); |
163 | 164 |
164 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height); | 165 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height); |
165 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); | 166 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); |
166 fLegacyBitmap.setInfo(info); | 167 fLegacyBitmap.setInfo(info); |
167 fLegacyBitmap.setPixelRef(pr)->unref(); | 168 fLegacyBitmap.setPixelRef(pr)->unref(); |
168 | 169 |
169 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); | 170 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); |
170 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); | 171 fDrawContext.reset(SkRef(fContext->drawContext(&this->getLeakyProperties(),
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 Loading... |
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 | |
232 fRenderTarget->unref(); | 230 fRenderTarget->unref(); |
233 fContext->unref(); | 231 fContext->unref(); |
234 } | 232 } |
235 | 233 |
236 /////////////////////////////////////////////////////////////////////////////// | 234 /////////////////////////////////////////////////////////////////////////////// |
237 | 235 |
238 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, | 236 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, |
239 int x, int y) { | 237 int x, int y) { |
240 DO_DEFERRED_CLEAR(); | 238 DO_DEFERRED_CLEAR(); |
241 | 239 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 346 |
349 SkASSERT(fRenderTarget != newRT); | 347 SkASSERT(fRenderTarget != newRT); |
350 | 348 |
351 fRenderTarget->unref(); | 349 fRenderTarget->unref(); |
352 fRenderTarget = newRT.detach(); | 350 fRenderTarget = newRT.detach(); |
353 | 351 |
354 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); | 352 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); |
355 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info
(), fRenderTarget)); | 353 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info
(), fRenderTarget)); |
356 fLegacyBitmap.setPixelRef(pr)->unref(); | 354 fLegacyBitmap.setPixelRef(pr)->unref(); |
357 | 355 |
358 fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext())); | 356 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); |
| 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 Loading... |
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 fTextContext->drawText(fRenderTarget, fClip, grPaint, paint, *draw.fMatrix, | 1641 fDrawContext->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 fTextContext->drawPosText(fRenderTarget, fClip, grPaint, paint, *draw.fMatri
x, | 1658 fDrawContext->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 fTextContext->drawTextBlob(fRenderTarget, fClip, paint, *draw.fMatrix, | 1670 fDrawContext->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 Loading... |
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 |
OLD | NEW |