| 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 23 matching lines...) Expand all Loading... |
| 34 #include "SkPictureReplacementPlayback.h" | 34 #include "SkPictureReplacementPlayback.h" |
| 35 #include "SkRRect.h" | 35 #include "SkRRect.h" |
| 36 #include "SkStroke.h" | 36 #include "SkStroke.h" |
| 37 #include "SkSurface.h" | 37 #include "SkSurface.h" |
| 38 #include "SkTLazy.h" | 38 #include "SkTLazy.h" |
| 39 #include "SkUtils.h" | 39 #include "SkUtils.h" |
| 40 #include "SkVertState.h" | 40 #include "SkVertState.h" |
| 41 #include "SkXfermode.h" | 41 #include "SkXfermode.h" |
| 42 #include "SkErrorInternals.h" | 42 #include "SkErrorInternals.h" |
| 43 | 43 |
| 44 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
| 45 |
| 44 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 | 46 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 |
| 45 | 47 |
| 46 #if 0 | 48 #if 0 |
| 47 extern bool (*gShouldDrawProc)(); | 49 extern bool (*gShouldDrawProc)(); |
| 48 #define CHECK_SHOULD_DRAW(draw, forceI) \ | 50 #define CHECK_SHOULD_DRAW(draw, forceI) \ |
| 49 do { \ | 51 do { \ |
| 50 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 52 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
| 51 this->prepareDraw(draw, forceI); \ | 53 this->prepareDraw(draw, forceI); \ |
| 52 } while (0) | 54 } while (0) |
| 53 #else | 55 #else |
| (...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 | 1420 |
| 1419 SkImageFilter* filter = paint.getImageFilter(); | 1421 SkImageFilter* filter = paint.getImageFilter(); |
| 1420 // This bitmap will own the filtered result as a texture. | 1422 // This bitmap will own the filtered result as a texture. |
| 1421 SkBitmap filteredBitmap; | 1423 SkBitmap filteredBitmap; |
| 1422 | 1424 |
| 1423 if (NULL != filter) { | 1425 if (NULL != filter) { |
| 1424 SkIPoint offset = SkIPoint::Make(0, 0); | 1426 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1425 SkMatrix matrix(*draw.fMatrix); | 1427 SkMatrix matrix(*draw.fMatrix); |
| 1426 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1428 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
| 1427 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); | 1429 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| 1428 SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); | 1430 SkAutoTUnref<SkImageFilter::UniqueIDCache> cache(getImageFilterCache()); |
| 1429 SkAutoUnref aur(cache); | 1431 // This cache is transient, and is freed (along with all its contained |
| 1432 // textures) when it goes out of scope. |
| 1430 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1433 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| 1431 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered
Bitmap, | 1434 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered
Bitmap, |
| 1432 &offset)) { | 1435 &offset)) { |
| 1433 texture = (GrTexture*) filteredBitmap.getTexture(); | 1436 texture = (GrTexture*) filteredBitmap.getTexture(); |
| 1434 w = filteredBitmap.width(); | 1437 w = filteredBitmap.width(); |
| 1435 h = filteredBitmap.height(); | 1438 h = filteredBitmap.height(); |
| 1436 left += offset.x(); | 1439 left += offset.x(); |
| 1437 top += offset.y(); | 1440 top += offset.y(); |
| 1438 } else { | 1441 } else { |
| 1439 return; | 1442 return; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 | 1531 |
| 1529 SkImageFilter* filter = paint.getImageFilter(); | 1532 SkImageFilter* filter = paint.getImageFilter(); |
| 1530 // This bitmap will own the filtered result as a texture. | 1533 // This bitmap will own the filtered result as a texture. |
| 1531 SkBitmap filteredBitmap; | 1534 SkBitmap filteredBitmap; |
| 1532 | 1535 |
| 1533 if (NULL != filter) { | 1536 if (NULL != filter) { |
| 1534 SkIPoint offset = SkIPoint::Make(0, 0); | 1537 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1535 SkMatrix matrix(*draw.fMatrix); | 1538 SkMatrix matrix(*draw.fMatrix); |
| 1536 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 1539 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| 1537 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); | 1540 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); |
| 1538 SkImageFilter::Cache* cache = SkImageFilter::Cache::Create(); | 1541 // This cache is transient, and is freed (along with all its contained |
| 1539 SkAutoUnref aur(cache); | 1542 // textures) when it goes out of scope. |
| 1543 SkAutoTUnref<SkImageFilter::UniqueIDCache> cache(getImageFilterCache()); |
| 1540 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1544 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
| 1541 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB
itmap, | 1545 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB
itmap, |
| 1542 &offset)) { | 1546 &offset)) { |
| 1543 devTex = filteredBitmap.getTexture(); | 1547 devTex = filteredBitmap.getTexture(); |
| 1544 w = filteredBitmap.width(); | 1548 w = filteredBitmap.width(); |
| 1545 h = filteredBitmap.height(); | 1549 h = filteredBitmap.height(); |
| 1546 x += offset.fX; | 1550 x += offset.fX; |
| 1547 y += offset.fY; | 1551 y += offset.fY; |
| 1548 } else { | 1552 } else { |
| 1549 return; | 1553 return; |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 playback.draw(canvas, NULL); | 2057 playback.draw(canvas, NULL); |
| 2054 | 2058 |
| 2055 // unlock the layers | 2059 // unlock the layers |
| 2056 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 2060 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2057 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 2061 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
| 2058 fContext->getLayerCache()->unlock(layer); | 2062 fContext->getLayerCache()->unlock(layer); |
| 2059 } | 2063 } |
| 2060 | 2064 |
| 2061 return true; | 2065 return true; |
| 2062 } | 2066 } |
| 2067 |
| 2068 SkImageFilter::UniqueIDCache* SkGpuDevice::getImageFilterCache() { |
| 2069 // We always return a transient cache, so it is freed after each |
| 2070 // filter traversal. |
| 2071 return SkImageFilter::UniqueIDCache::Create(kDefaultImageFilterCacheSize); |
| 2072 } |
| OLD | NEW |