| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
| 124 | 124 |
| 125 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, const SkSurfaceProps& props
, unsigned flags) { | 125 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, const SkSurfaceProps& props
, unsigned flags) { |
| 126 SkASSERT(surface); | 126 SkASSERT(surface); |
| 127 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { | 127 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { |
| 128 return NULL; | 128 return NULL; |
| 129 } | 129 } |
| 130 return SkNEW_ARGS(SkGpuDevice, (surface, props, flags)); | 130 return SkNEW_ARGS(SkGpuDevice, (surface, props, flags)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign
ed flags) { | 133 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps& prop
s) { |
| 134 return SkDeviceProperties(props.pixelGeometry()); |
| 135 } |
| 134 | 136 |
| 137 SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign
ed flags) |
| 138 : INHERITED(surfaceprops_to_deviceprops(props)) |
| 139 { |
| 135 fDrawProcs = NULL; | 140 fDrawProcs = NULL; |
| 136 | 141 |
| 137 fContext = SkRef(surface->getContext()); | 142 fContext = SkRef(surface->getContext()); |
| 138 | 143 |
| 139 fFlags = flags; | 144 fFlags = flags; |
| 140 | 145 |
| 141 fRenderTarget = SkRef(surface->asRenderTarget()); | 146 fRenderTarget = SkRef(surface->asRenderTarget()); |
| 142 | 147 |
| 143 SkImageInfo info = surface->surfacePriv().info(); | 148 SkImageInfo info = surface->surfacePriv().info(); |
| 144 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); | 149 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); |
| 145 fLegacyBitmap.setInfo(info); | 150 fLegacyBitmap.setInfo(info); |
| 146 fLegacyBitmap.setPixelRef(pr)->unref(); | 151 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 147 | 152 |
| 148 this->setPixelGeometry(props.pixelGeometry()); | |
| 149 | |
| 150 bool useDFT = SkToBool(flags & kDFText_Flag); | 153 bool useDFT = SkToBool(flags & kDFText_Flag); |
| 151 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); | 154 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); |
| 152 } | 155 } |
| 153 | 156 |
| 154 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 157 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
| 155 const SkSurfaceProps& props, int sampleCount) { | 158 const SkSurfaceProps& props, int sampleCount) { |
| 156 if (kUnknown_SkColorType == origInfo.colorType() || | 159 if (kUnknown_SkColorType == origInfo.colorType() || |
| 157 origInfo.width() < 0 || origInfo.height() < 0) { | 160 origInfo.width() < 0 || origInfo.height() < 0) { |
| 158 return NULL; | 161 return NULL; |
| 159 } | 162 } |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 size_t len, const SkPath& path, | 1717 size_t len, const SkPath& path, |
| 1715 const SkMatrix* m, const SkPaint& paint) { | 1718 const SkMatrix* m, const SkPaint& paint) { |
| 1716 CHECK_SHOULD_DRAW(draw, false); | 1719 CHECK_SHOULD_DRAW(draw, false); |
| 1717 | 1720 |
| 1718 SkASSERT(draw.fDevice == this); | 1721 SkASSERT(draw.fDevice == this); |
| 1719 draw.drawTextOnPath((const char*)text, len, path, m, paint); | 1722 draw.drawTextOnPath((const char*)text, len, path, m, paint); |
| 1720 } | 1723 } |
| 1721 | 1724 |
| 1722 /////////////////////////////////////////////////////////////////////////////// | 1725 /////////////////////////////////////////////////////////////////////////////// |
| 1723 | 1726 |
| 1724 bool SkGpuDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { | 1727 bool SkGpuDevice::onShouldDisableLCD(const SkPaint& paint) const { |
| 1725 if (!paint.isLCDRenderText()) { | |
| 1726 // we're cool with the paint as is | |
| 1727 return false; | |
| 1728 } | |
| 1729 | |
| 1730 if (paint.getShader() || | 1728 if (paint.getShader() || |
| 1731 paint.getXfermode() || // unless its srcover | 1729 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) || |
| 1732 paint.getMaskFilter() || | 1730 paint.getMaskFilter() || |
| 1733 paint.getRasterizer() || | 1731 paint.getRasterizer() || |
| 1734 paint.getColorFilter() || | 1732 paint.getColorFilter() || |
| 1735 paint.getPathEffect() || | 1733 paint.getPathEffect() || |
| 1736 paint.isFakeBoldText() || | 1734 paint.isFakeBoldText() || |
| 1737 paint.getStyle() != SkPaint::kFill_Style) { | 1735 paint.getStyle() != SkPaint::kFill_Style) |
| 1738 // turn off lcd, but turn on kGenA8 | 1736 { |
| 1739 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | |
| 1740 flags->fFlags |= SkPaint::kGenA8FromLCD_Flag; | |
| 1741 return true; | 1737 return true; |
| 1742 } | 1738 } |
| 1743 // we're cool with the paint as is | |
| 1744 return false; | 1739 return false; |
| 1745 } | 1740 } |
| 1746 | 1741 |
| 1747 void SkGpuDevice::flush() { | 1742 void SkGpuDevice::flush() { |
| 1748 DO_DEFERRED_CLEAR(); | 1743 DO_DEFERRED_CLEAR(); |
| 1749 fRenderTarget->prepareForExternalRead(); | 1744 fRenderTarget->prepareForExternalRead(); |
| 1750 } | 1745 } |
| 1751 | 1746 |
| 1752 /////////////////////////////////////////////////////////////////////////////// | 1747 /////////////////////////////////////////////////////////////////////////////// |
| 1753 | 1748 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1769 // layers are never draw in repeat modes, so we can request an approx | 1764 // layers are never draw in repeat modes, so we can request an approx |
| 1770 // match and ignore any padding. | 1765 // match and ignore any padding. |
| 1771 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == cinfo.fUsage)
? | 1766 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == cinfo.fUsage)
? |
| 1772 GrContext::kApprox_ScratchTexMat
ch : | 1767 GrContext::kApprox_ScratchTexMat
ch : |
| 1773 GrContext::kExact_ScratchTexMatc
h; | 1768 GrContext::kExact_ScratchTexMatc
h; |
| 1774 texture.reset(fContext->refScratchTexture(desc, match)); | 1769 texture.reset(fContext->refScratchTexture(desc, match)); |
| 1775 #else | 1770 #else |
| 1776 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); | 1771 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); |
| 1777 #endif | 1772 #endif |
| 1778 if (texture.get()) { | 1773 if (texture.get()) { |
| 1779 return SkGpuDevice::Create(texture, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType), flags); | 1774 return SkGpuDevice::Create(texture, SkSurfaceProps(0, cinfo.fPixelGeomet
ry), flags); |
| 1780 } else { | 1775 } else { |
| 1781 SkDebugf("---- failed to create compatible device texture [%d %d]\n", | 1776 SkDebugf("---- failed to create compatible device texture [%d %d]\n", |
| 1782 cinfo.fInfo.width(), cinfo.fInfo.height()); | 1777 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 1783 return NULL; | 1778 return NULL; |
| 1784 } | 1779 } |
| 1785 } | 1780 } |
| 1786 | 1781 |
| 1787 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { | 1782 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { |
| 1788 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
), &props); | 1783 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(
), &props); |
| 1789 } | 1784 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 return true; | 1838 return true; |
| 1844 } | 1839 } |
| 1845 | 1840 |
| 1846 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1841 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1847 // We always return a transient cache, so it is freed after each | 1842 // We always return a transient cache, so it is freed after each |
| 1848 // filter traversal. | 1843 // filter traversal. |
| 1849 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1844 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1850 } | 1845 } |
| 1851 | 1846 |
| 1852 #endif | 1847 #endif |
| OLD | NEW |