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 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 GrPaint grPaint; | 1341 GrPaint grPaint; |
1342 grPaint.addColorProcessor(fp); | 1342 grPaint.addColorProcessor(fp); |
1343 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); | 1343 bool alphaOnly = !(kAlpha_8_SkColorType == bitmap.colorType()); |
1344 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : | 1344 GrColor paintColor = (alphaOnly) ? SkColor2GrColorJustAlpha(paint.getColor()
) : |
1345 SkColor2GrColor(paint.getColor()); | 1345 SkColor2GrColor(paint.getColor()); |
1346 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; | 1346 SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint)
; |
1347 | 1347 |
1348 fContext->drawRectToRect(grPaint, dstRect, paintRect); | 1348 fContext->drawRectToRect(grPaint, dstRect, paintRect); |
1349 } | 1349 } |
1350 | 1350 |
1351 static bool filter_texture(SkBaseDevice* device, GrContext* context, | 1351 bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, |
1352 GrTexture* texture, const SkImageFilter* filter, | 1352 const SkImageFilter* filter, |
1353 const SkImageFilter::Context& ctx, | 1353 const SkImageFilter::Context& ctx, |
1354 SkBitmap* result, SkIPoint* offset) { | 1354 SkBitmap* result, SkIPoint* offset) { |
1355 SkASSERT(filter); | 1355 SkASSERT(filter); |
1356 SkDeviceImageFilterProxy proxy(device); | 1356 |
| 1357 // FIXME: plumb actual surface props such that we don't have to lie about th
e flags here |
| 1358 // (https://code.google.com/p/skia/issues/detail?id=3148). |
| 1359 SkDeviceImageFilterProxy proxy(this, SkSurfaceProps(0, getLeakyProperties().
pixelGeometry())); |
1357 | 1360 |
1358 if (filter->canFilterImageGPU()) { | 1361 if (filter->canFilterImageGPU()) { |
1359 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the | 1362 // Save the render target and set it to NULL, so we don't accidentally d
raw to it in the |
1360 // filter. Also set the clip wide open and the matrix to identity. | 1363 // filter. Also set the clip wide open and the matrix to identity. |
1361 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 1364 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); |
1362 return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result
, offset); | 1365 return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result
, offset); |
1363 } else { | 1366 } else { |
1364 return false; | 1367 return false; |
1365 } | 1368 } |
1366 } | 1369 } |
(...skipping 21 matching lines...) Expand all Loading... |
1388 | 1391 |
1389 if (filter) { | 1392 if (filter) { |
1390 SkIPoint offset = SkIPoint::Make(0, 0); | 1393 SkIPoint offset = SkIPoint::Make(0, 0); |
1391 SkMatrix matrix(*draw.fMatrix); | 1394 SkMatrix matrix(*draw.fMatrix); |
1392 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1395 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
1393 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); | 1396 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
1394 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1397 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
1395 // This cache is transient, and is freed (along with all its contained | 1398 // This cache is transient, and is freed (along with all its contained |
1396 // textures) when it goes out of scope. | 1399 // textures) when it goes out of scope. |
1397 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1400 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
1398 if (filter_texture(this, fContext, texture, filter, ctx, &filteredBitmap
, | 1401 if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap, |
1399 &offset)) { | 1402 &offset)) { |
1400 texture = (GrTexture*) filteredBitmap.getTexture(); | 1403 texture = (GrTexture*) filteredBitmap.getTexture(); |
1401 w = filteredBitmap.width(); | 1404 w = filteredBitmap.width(); |
1402 h = filteredBitmap.height(); | 1405 h = filteredBitmap.height(); |
1403 left += offset.x(); | 1406 left += offset.x(); |
1404 top += offset.y(); | 1407 top += offset.y(); |
1405 } else { | 1408 } else { |
1406 return; | 1409 return; |
1407 } | 1410 } |
1408 } | 1411 } |
1409 | 1412 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 | 1502 |
1500 if (filter) { | 1503 if (filter) { |
1501 SkIPoint offset = SkIPoint::Make(0, 0); | 1504 SkIPoint offset = SkIPoint::Make(0, 0); |
1502 SkMatrix matrix(*draw.fMatrix); | 1505 SkMatrix matrix(*draw.fMatrix); |
1503 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 1506 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
1504 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); | 1507 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
1505 // This cache is transient, and is freed (along with all its contained | 1508 // This cache is transient, and is freed (along with all its contained |
1506 // textures) when it goes out of scope. | 1509 // textures) when it goes out of scope. |
1507 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1510 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
1508 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1511 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
1509 if (filter_texture(this, fContext, devTex, filter, ctx, &filteredBitmap, | 1512 if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap, |
1510 &offset)) { | 1513 &offset)) { |
1511 devTex = filteredBitmap.getTexture(); | 1514 devTex = filteredBitmap.getTexture(); |
1512 w = filteredBitmap.width(); | 1515 w = filteredBitmap.width(); |
1513 h = filteredBitmap.height(); | 1516 h = filteredBitmap.height(); |
1514 x += offset.fX; | 1517 x += offset.fX; |
1515 y += offset.fY; | 1518 y += offset.fY; |
1516 } else { | 1519 } else { |
1517 return; | 1520 return; |
1518 } | 1521 } |
1519 } | 1522 } |
1520 | 1523 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 SkAutoLockPixels alp(src, !src.getTexture()); | 1555 SkAutoLockPixels alp(src, !src.getTexture()); |
1553 if (!src.getTexture() && !src.readyToDraw()) { | 1556 if (!src.getTexture() && !src.readyToDraw()) { |
1554 return false; | 1557 return false; |
1555 } | 1558 } |
1556 | 1559 |
1557 GrTexture* texture; | 1560 GrTexture* texture; |
1558 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup | 1561 // We assume here that the filter will not attempt to tile the src. Otherwis
e, this cache lookup |
1559 // must be pushed upstack. | 1562 // must be pushed upstack. |
1560 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1563 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
1561 | 1564 |
1562 return filter_texture(this, fContext, texture, filter, ctx, result, offset); | 1565 return this->filterTexture(fContext, texture, filter, ctx, result, offset); |
1563 } | 1566 } |
1564 | 1567 |
1565 /////////////////////////////////////////////////////////////////////////////// | 1568 /////////////////////////////////////////////////////////////////////////////// |
1566 | 1569 |
1567 // must be in SkCanvas::VertexMode order | 1570 // must be in SkCanvas::VertexMode order |
1568 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1571 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
1569 kTriangles_GrPrimitiveType, | 1572 kTriangles_GrPrimitiveType, |
1570 kTriangleStrip_GrPrimitiveType, | 1573 kTriangleStrip_GrPrimitiveType, |
1571 kTriangleFan_GrPrimitiveType, | 1574 kTriangleFan_GrPrimitiveType, |
1572 }; | 1575 }; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 return true; | 1841 return true; |
1839 } | 1842 } |
1840 | 1843 |
1841 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1844 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1842 // We always return a transient cache, so it is freed after each | 1845 // We always return a transient cache, so it is freed after each |
1843 // filter traversal. | 1846 // filter traversal. |
1844 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1847 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1845 } | 1848 } |
1846 | 1849 |
1847 #endif | 1850 #endif |
OLD | NEW |