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

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

Issue 1034733002: Implement approx-match support in image filter saveLayer() offscreen. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 5 years, 8 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 "GrBitmapTextContext.h" 10 #include "GrBitmapTextContext.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 struct GrSkDrawProcs : public SkDrawProcs { 114 struct GrSkDrawProcs : public SkDrawProcs {
115 public: 115 public:
116 GrContext* fContext; 116 GrContext* fContext;
117 GrTextContext* fTextContext; 117 GrTextContext* fTextContext;
118 GrFontScaler* fFontScaler; // cached in the skia glyphcache 118 GrFontScaler* fFontScaler; // cached in the skia glyphcache
119 }; 119 };
120 120
121 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
122 122
123 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props , unsigned flags) { 123 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props , unsigned flags) {
124 return SkGpuDevice::Create(rt, rt->width(), rt->height(), props, flags);
125 }
126
127 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height,
128 const SkSurfaceProps* props, unsigned flags) {
124 if (!rt || rt->wasDestroyed()) { 129 if (!rt || rt->wasDestroyed()) {
125 return NULL; 130 return NULL;
126 } 131 }
127 return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); 132 return SkNEW_ARGS(SkGpuDevice, (rt, width, height, props, flags));
128 } 133 }
129 134
130 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) { 135 static SkDeviceProperties surfaceprops_to_deviceprops(const SkSurfaceProps* prop s) {
131 if (props) { 136 if (props) {
132 return SkDeviceProperties(props->pixelGeometry()); 137 return SkDeviceProperties(props->pixelGeometry());
133 } else { 138 } else {
134 return SkDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType); 139 return SkDeviceProperties(SkDeviceProperties::kLegacyLCD_InitType);
135 } 140 }
136 } 141 }
137 142
138 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) { 143 static SkSurfaceProps copy_or_default_props(const SkSurfaceProps* props) {
139 if (props) { 144 if (props) {
140 return SkSurfaceProps(*props); 145 return SkSurfaceProps(*props);
141 } else { 146 } else {
142 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); 147 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
143 } 148 }
144 } 149 }
145 150
146 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsign ed flags) 151 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
152 const SkSurfaceProps* props, unsigned flags)
147 : INHERITED(surfaceprops_to_deviceprops(props)) 153 : INHERITED(surfaceprops_to_deviceprops(props))
148 , fSurfaceProps(copy_or_default_props(props)) 154 , fSurfaceProps(copy_or_default_props(props))
149 { 155 {
150 fDrawProcs = NULL; 156 fDrawProcs = NULL;
151 157
152 fContext = SkRef(rt->getContext()); 158 fContext = SkRef(rt->getContext());
153 fNeedClear = flags & kNeedClear_Flag; 159 fNeedClear = flags & kNeedClear_Flag;
154 160
155 fRenderTarget = SkRef(rt); 161 fRenderTarget = SkRef(rt);
156 162
157 SkImageInfo info = rt->surfacePriv().info(); 163 SkImageInfo info = rt->surfacePriv().info().makeWH(width, height);
158 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); 164 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt));
159 fLegacyBitmap.setInfo(info); 165 fLegacyBitmap.setInfo(info);
160 fLegacyBitmap.setPixelRef(pr)->unref(); 166 fLegacyBitmap.setPixelRef(pr)->unref();
161 167
162 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); 168 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts();
163 fTextContext = fContext->createTextContext(fRenderTarget, this, this->getLea kyProperties(), 169 fTextContext = fContext->createTextContext(fRenderTarget, this, this->getLea kyProperties(),
164 useDFT); 170 useDFT);
165 } 171 }
166 172
167 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted, 173 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B udgeted budgeted,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 210
205 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete d, 211 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete d,
206 const SkImageInfo& info, int sampleCount, 212 const SkImageInfo& info, int sampleCount,
207 const SkSurfaceProps* props, unsigned flags) { 213 const SkSurfaceProps* props, unsigned flags) {
208 214
209 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info, sampleCount)); 215 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info, sampleCount));
210 if (NULL == rt) { 216 if (NULL == rt) {
211 return NULL; 217 return NULL;
212 } 218 }
213 219
214 return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); 220 return SkNEW_ARGS(SkGpuDevice, (rt, info.width(), info.height(), props, flag s));
215 } 221 }
216 222
217 SkGpuDevice::~SkGpuDevice() { 223 SkGpuDevice::~SkGpuDevice() {
218 if (fDrawProcs) { 224 if (fDrawProcs) {
219 delete fDrawProcs; 225 delete fDrawProcs;
220 } 226 }
221 227
222 delete fTextContext; 228 delete fTextContext;
223 229
224 fRenderTarget->unref(); 230 fRenderTarget->unref();
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // setup new clip 735 // setup new clip
730 GrClip clip(clipRect); 736 GrClip clip(clipRect);
731 737
732 // Draw the mask into maskTexture with the path's top-left at the origin usi ng tempPaint. 738 // Draw the mask into maskTexture with the path's top-left at the origin usi ng tempPaint.
733 SkMatrix translate; 739 SkMatrix translate;
734 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); 740 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
735 context->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, devPat h, strokeInfo); 741 context->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, devPat h, strokeInfo);
736 return mask; 742 return mask;
737 } 743 }
738 744
739 SkBitmap wrap_texture(GrTexture* texture) { 745 SkBitmap wrap_texture(GrTexture* texture, int width, int height) {
740 SkBitmap result; 746 SkBitmap result;
741 result.setInfo(texture->surfacePriv().info()); 747 result.setInfo(SkImageInfo::MakeN32Premul(width, height));
742 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre f(); 748 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre f();
743 return result; 749 return result;
744 } 750 }
745 751
746 }; 752 };
747 753
748 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, 754 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
749 const SkPaint& paint, const SkMatrix* prePathMatrix, 755 const SkPaint& paint, const SkMatrix* prePathMatrix,
750 bool pathIsMutable) { 756 bool pathIsMutable) {
751 CHECK_FOR_ANNOTATION(paint); 757 CHECK_FOR_ANNOTATION(paint);
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); 1473 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType());
1468 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor() ) : 1474 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor() ) :
1469 SkColor2GrColor(paint.getColor()); 1475 SkColor2GrColor(paint.getColor());
1470 SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, f alse, &grPaint); 1476 SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint, paintColor, f alse, &grPaint);
1471 1477
1472 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dst Rect, 1478 fContext->drawNonAARectToRect(fRenderTarget, fClip, grPaint, viewMatrix, dst Rect,
1473 paintRect); 1479 paintRect);
1474 } 1480 }
1475 1481
1476 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, 1482 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
1483 int width, int height,
1477 const SkImageFilter* filter, 1484 const SkImageFilter* filter,
1478 const SkImageFilter::Context& ctx, 1485 const SkImageFilter::Context& ctx,
1479 SkBitmap* result, SkIPoint* offset) { 1486 SkBitmap* result, SkIPoint* offset) {
1480 SkASSERT(filter); 1487 SkASSERT(filter);
1481 1488
1482 // FIXME: plumb actual surface props such that we don't have to lie about th e flags here 1489 // FIXME: plumb actual surface props such that we don't have to lie about th e flags here
1483 // (https://code.google.com/p/skia/issues/detail?id=3148). 1490 // (https://code.google.com/p/skia/issues/detail?id=3148).
1484 SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties(). pixelGeometry())); 1491 SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties(). pixelGeometry()));
1485 1492
1486 if (filter->canFilterImageGPU()) { 1493 if (filter->canFilterImageGPU()) {
1487 return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result , offset); 1494 return filter->filterImageGPU(&proxy, wrap_texture(texture, width, heigh t),
1495 ctx, result, offset);
1488 } else { 1496 } else {
1489 return false; 1497 return false;
1490 } 1498 }
1491 } 1499 }
1492 1500
1493 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 1501 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
1494 int left, int top, const SkPaint& paint) { 1502 int left, int top, const SkPaint& paint) {
1495 // drawSprite is defined to be in device coords. 1503 // drawSprite is defined to be in device coords.
1496 CHECK_SHOULD_DRAW(draw); 1504 CHECK_SHOULD_DRAW(draw);
1497 1505
(...skipping 18 matching lines...) Expand all
1516 1524
1517 if (filter) { 1525 if (filter) {
1518 SkIPoint offset = SkIPoint::Make(0, 0); 1526 SkIPoint offset = SkIPoint::Make(0, 0);
1519 SkMatrix matrix(*draw.fMatrix); 1527 SkMatrix matrix(*draw.fMatrix);
1520 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); 1528 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1521 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 1529 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
1522 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); 1530 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1523 // This cache is transient, and is freed (along with all its contained 1531 // This cache is transient, and is freed (along with all its contained
1524 // textures) when it goes out of scope. 1532 // textures) when it goes out of scope.
1525 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1533 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1526 if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap, 1534 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB itmap,
1527 &offset)) { 1535 &offset)) {
1528 texture = (GrTexture*) filteredBitmap.getTexture(); 1536 texture = (GrTexture*) filteredBitmap.getTexture();
1529 w = filteredBitmap.width(); 1537 w = filteredBitmap.width();
1530 h = filteredBitmap.height(); 1538 h = filteredBitmap.height();
1531 left += offset.x(); 1539 left += offset.x();
1532 top += offset.y(); 1540 top += offset.y();
1533 } else { 1541 } else {
1534 return; 1542 return;
1535 } 1543 }
1536 } 1544 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 1638
1631 if (filter) { 1639 if (filter) {
1632 SkIPoint offset = SkIPoint::Make(0, 0); 1640 SkIPoint offset = SkIPoint::Make(0, 0);
1633 SkMatrix matrix(*draw.fMatrix); 1641 SkMatrix matrix(*draw.fMatrix);
1634 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); 1642 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
1635 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); 1643 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height());
1636 // This cache is transient, and is freed (along with all its contained 1644 // This cache is transient, and is freed (along with all its contained
1637 // textures) when it goes out of scope. 1645 // textures) when it goes out of scope.
1638 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); 1646 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1639 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1647 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1640 if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap, 1648 if (this->filterTexture(fContext, devTex, device->width(), device->heigh t(),
1641 &offset)) { 1649 filter, ctx, &filteredBitmap, &offset)) {
1642 devTex = filteredBitmap.getTexture(); 1650 devTex = filteredBitmap.getTexture();
1643 w = filteredBitmap.width(); 1651 w = filteredBitmap.width();
1644 h = filteredBitmap.height(); 1652 h = filteredBitmap.height();
1645 x += offset.fX; 1653 x += offset.fX;
1646 y += offset.fY; 1654 y += offset.fY;
1647 } else { 1655 } else {
1648 return; 1656 return;
1649 } 1657 }
1650 } 1658 }
1651 1659
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 SkAutoLockPixels alp(src, !src.getTexture()); 1692 SkAutoLockPixels alp(src, !src.getTexture());
1685 if (!src.getTexture() && !src.readyToDraw()) { 1693 if (!src.getTexture() && !src.readyToDraw()) {
1686 return false; 1694 return false;
1687 } 1695 }
1688 1696
1689 GrTexture* texture; 1697 GrTexture* texture;
1690 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup 1698 // We assume here that the filter will not attempt to tile the src. Otherwis e, this cache lookup
1691 // must be pushed upstack. 1699 // must be pushed upstack.
1692 AutoBitmapTexture abt(fContext, src, NULL, &texture); 1700 AutoBitmapTexture abt(fContext, src, NULL, &texture);
1693 1701
1694 return this->filterTexture(fContext, texture, filter, ctx, result, offset); 1702 return this->filterTexture(fContext, texture, src.width(), src.height(),
1703 filter, ctx, result, offset);
1695 } 1704 }
1696 1705
1697 /////////////////////////////////////////////////////////////////////////////// 1706 ///////////////////////////////////////////////////////////////////////////////
1698 1707
1699 // must be in SkCanvas::VertexMode order 1708 // must be in SkCanvas::VertexMode order
1700 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { 1709 static const GrPrimitiveType gVertexMode2PrimitiveType[] = {
1701 kTriangles_GrPrimitiveType, 1710 kTriangles_GrPrimitiveType,
1702 kTriangleStrip_GrPrimitiveType, 1711 kTriangleStrip_GrPrimitiveType,
1703 kTriangleFan_GrPrimitiveType, 1712 kTriangleFan_GrPrimitiveType,
1704 }; 1713 };
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 1903
1895 // layers are never draw in repeat modes, so we can request an approx 1904 // layers are never draw in repeat modes, so we can request an approx
1896 // match and ignore any padding. 1905 // match and ignore any padding.
1897 const GrContext::ScratchTexMatch match = (kNever_TileUsage == cinfo.fTileUsa ge) ? 1906 const GrContext::ScratchTexMatch match = (kNever_TileUsage == cinfo.fTileUsa ge) ?
1898 GrContext::kApprox_ScratchTexMat ch : 1907 GrContext::kApprox_ScratchTexMat ch :
1899 GrContext::kExact_ScratchTexMatc h; 1908 GrContext::kExact_ScratchTexMatc h;
1900 texture.reset(fContext->refScratchTexture(desc, match)); 1909 texture.reset(fContext->refScratchTexture(desc, match));
1901 1910
1902 if (texture) { 1911 if (texture) {
1903 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); 1912 SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry);
1904 return SkGpuDevice::Create(texture->asRenderTarget(), &props, flags); 1913 return SkGpuDevice::Create(
1914 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height() , &props, flags);
1905 } else { 1915 } else {
1906 SkErrorInternals::SetError( kInternalError_SkError, 1916 SkErrorInternals::SetError( kInternalError_SkError,
1907 "---- failed to create compatible device tex ture [%d %d]\n", 1917 "---- failed to create compatible device tex ture [%d %d]\n",
1908 cinfo.fInfo.width(), cinfo.fInfo.height()); 1918 cinfo.fInfo.width(), cinfo.fInfo.height());
1909 return NULL; 1919 return NULL;
1910 } 1920 }
1911 } 1921 }
1912 1922
1913 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps & props) { 1923 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps & props) {
1914 // TODO: Change the signature of newSurface to take a budgeted parameter. 1924 // TODO: Change the signature of newSurface to take a budgeted parameter.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 #endif 1993 #endif
1984 } 1994 }
1985 1995
1986 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1996 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1987 // We always return a transient cache, so it is freed after each 1997 // We always return a transient cache, so it is freed after each
1988 // filter traversal. 1998 // filter traversal.
1989 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1999 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1990 } 2000 }
1991 2001
1992 #endif 2002 #endif
OLDNEW
« src/effects/SkMagnifierImageFilter.cpp ('K') | « src/gpu/SkGpuDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698