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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) | 60 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) |
61 #endif | 61 #endif |
62 | 62 |
63 // This constant represents the screen alignment criterion in texels for | 63 // This constant represents the screen alignment criterion in texels for |
64 // requiring texture domain clamping to prevent color bleeding when drawing | 64 // requiring texture domain clamping to prevent color bleeding when drawing |
65 // a sub region of a larger source image. | 65 // a sub region of a larger source image. |
66 #define COLOR_BLEED_TOLERANCE 0.001f | 66 #define COLOR_BLEED_TOLERANCE 0.001f |
67 | 67 |
68 #define DO_DEFERRED_CLEAR() \ | 68 #define DO_DEFERRED_CLEAR() \ |
69 do { \ | 69 do { \ |
70 if (fFlags & kNeedClear_Flag) { \ | 70 if (fNeedClear) { \ |
71 this->clear(SK_ColorTRANSPARENT); \ | 71 this->clear(SK_ColorTRANSPARENT); \ |
72 } \ | 72 } \ |
73 } while (false) \ | 73 } while (false) \ |
74 | 74 |
75 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
76 | 76 |
77 #define CHECK_FOR_ANNOTATION(paint) \ | 77 #define CHECK_FOR_ANNOTATION(paint) \ |
78 do { if (paint.getAnnotation()) { return; } } while (0) | 78 do { if (paint.getAnnotation()) { return; } } while (0) |
79 | 79 |
80 /////////////////////////////////////////////////////////////////////////////// | 80 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 return SkNEW_ARGS(SkGpuDevice, (surface, props, flags)); | 131 return SkNEW_ARGS(SkGpuDevice, (surface, props, flags)); |
132 } | 132 } |
133 | 133 |
134 SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign
ed flags) { | 134 SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign
ed flags) { |
135 | 135 |
136 fDrawProcs = NULL; | 136 fDrawProcs = NULL; |
137 | 137 |
138 fContext = SkRef(surface->getContext()); | 138 fContext = SkRef(surface->getContext()); |
139 | 139 |
140 fFlags = flags; | 140 fNeedClear = flags & kNeedClear_Flag; |
141 | 141 |
142 fRenderTarget = SkRef(surface->asRenderTarget()); | 142 fRenderTarget = SkRef(surface->asRenderTarget()); |
143 | 143 |
144 SkImageInfo info = surface->surfacePriv().info(); | 144 SkImageInfo info = surface->surfacePriv().info(); |
145 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); | 145 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); |
146 fLegacyBitmap.setInfo(info); | 146 fLegacyBitmap.setInfo(info); |
147 fLegacyBitmap.setPixelRef(pr)->unref(); | 147 fLegacyBitmap.setPixelRef(pr)->unref(); |
148 | 148 |
149 this->setPixelGeometry(props.pixelGeometry()); | 149 this->setPixelGeometry(props.pixelGeometry()); |
150 | 150 |
151 bool useDFT = SkToBool(flags & kDFText_Flag); | 151 bool useDFFonts = !!(flags & kDFFonts_Flag); |
152 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); | 152 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFFonts); |
153 } | 153 } |
154 | 154 |
155 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 155 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
156 const SkSurfaceProps& props, int sampleCount) { | 156 const SkSurfaceProps& props, int sampleCount) { |
157 if (kUnknown_SkColorType == origInfo.colorType() || | 157 if (kUnknown_SkColorType == origInfo.colorType() || |
158 origInfo.width() < 0 || origInfo.height() < 0) { | 158 origInfo.width() < 0 || origInfo.height() < 0) { |
159 return NULL; | 159 return NULL; |
160 } | 160 } |
161 | 161 |
162 SkColorType ct = origInfo.colorType(); | 162 SkColorType ct = origInfo.colorType(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 shader_type_mismatch); | 303 shader_type_mismatch); |
304 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); | 304 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); |
305 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); | 305 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); |
306 | 306 |
307 /////////////////////////////////////////////////////////////////////////////// | 307 /////////////////////////////////////////////////////////////////////////////// |
308 | 308 |
309 void SkGpuDevice::clear(SkColor color) { | 309 void SkGpuDevice::clear(SkColor color) { |
310 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clear", fContext); | 310 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clear", fContext); |
311 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 311 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
312 fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); | 312 fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); |
313 fFlags &= ~kNeedClear_Flag; | 313 fNeedClear = false; |
314 } | 314 } |
315 | 315 |
316 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 316 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
317 CHECK_SHOULD_DRAW(draw, false); | 317 CHECK_SHOULD_DRAW(draw, false); |
318 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 318 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
319 | 319 |
320 GrPaint grPaint; | 320 GrPaint grPaint; |
321 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 321 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
322 | 322 |
323 fContext->drawPaint(grPaint); | 323 fContext->drawPaint(grPaint); |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 dstSize.fHeight = tmpDst.height(); | 1466 dstSize.fHeight = tmpDst.height(); |
1467 | 1467 |
1468 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); | 1468 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); |
1469 } | 1469 } |
1470 | 1470 |
1471 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1471 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
1472 int x, int y, const SkPaint& paint) { | 1472 int x, int y, const SkPaint& paint) { |
1473 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1473 // clear of the source device must occur before CHECK_SHOULD_DRAW |
1474 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); | 1474 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); |
1475 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | 1475 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
1476 if (dev->fFlags & kNeedClear_Flag) { | 1476 if (dev->fNeedClear) { |
1477 // TODO: could check here whether we really need to draw at all | 1477 // TODO: could check here whether we really need to draw at all |
1478 dev->clear(0x0); | 1478 dev->clear(0x0); |
1479 } | 1479 } |
1480 | 1480 |
1481 // drawDevice is defined to be in device coords. | 1481 // drawDevice is defined to be in device coords. |
1482 CHECK_SHOULD_DRAW(draw, true); | 1482 CHECK_SHOULD_DRAW(draw, true); |
1483 | 1483 |
1484 GrRenderTarget* devRT = dev->accessRenderTarget(); | 1484 GrRenderTarget* devRT = dev->accessRenderTarget(); |
1485 GrTexture* devTex; | 1485 GrTexture* devTex; |
1486 if (NULL == (devTex = devRT->asTexture())) { | 1486 if (NULL == (devTex = devRT->asTexture())) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 GrSurfaceDesc desc; | 1756 GrSurfaceDesc desc; |
1757 desc.fConfig = fRenderTarget->config(); | 1757 desc.fConfig = fRenderTarget->config(); |
1758 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 1758 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
1759 desc.fWidth = info.width(); | 1759 desc.fWidth = info.width(); |
1760 desc.fHeight = info.height(); | 1760 desc.fHeight = info.height(); |
1761 desc.fSampleCnt = fRenderTarget->numSamples(); | 1761 desc.fSampleCnt = fRenderTarget->numSamples(); |
1762 | 1762 |
1763 SkAutoTUnref<GrTexture> texture; | 1763 SkAutoTUnref<GrTexture> texture; |
1764 // Skia's convention is to only clear a device if it is non-opaque. | 1764 // Skia's convention is to only clear a device if it is non-opaque. |
1765 unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag; | 1765 unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag; |
1766 // If we're using distance field text, enable in the new device | |
1767 flags |= (fFlags & kDFText_Flag) ? kDFText_Flag : 0; | |
1768 | 1766 |
1769 #if CACHE_COMPATIBLE_DEVICE_TEXTURES | 1767 #if CACHE_COMPATIBLE_DEVICE_TEXTURES |
1770 // layers are never draw in repeat modes, so we can request an approx | 1768 // layers are never draw in repeat modes, so we can request an approx |
1771 // match and ignore any padding. | 1769 // match and ignore any padding. |
1772 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? | 1770 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? |
1773 GrContext::kApprox_ScratchTexMat
ch : | 1771 GrContext::kApprox_ScratchTexMat
ch : |
1774 GrContext::kExact_ScratchTexMatc
h; | 1772 GrContext::kExact_ScratchTexMatc
h; |
1775 texture.reset(fContext->refScratchTexture(desc, match)); | 1773 texture.reset(fContext->refScratchTexture(desc, match)); |
1776 #else | 1774 #else |
1777 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); | 1775 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 return true; | 1852 return true; |
1855 } | 1853 } |
1856 | 1854 |
1857 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1855 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1858 // We always return a transient cache, so it is freed after each | 1856 // We always return a transient cache, so it is freed after each |
1859 // filter traversal. | 1857 // filter traversal. |
1860 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1858 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1861 } | 1859 } |
1862 | 1860 |
1863 #endif | 1861 #endif |
OLD | NEW |