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

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

Issue 13602013: Allow single-pass filters (which use asNewEffect()) to participate in the image filter DAG. This w… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix return value of SkImageFilter::asNewEffect(). Created 7 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 | Annotate | Revision Log
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 "effects/GrTextureDomainEffect.h" 10 #include "effects/GrTextureDomainEffect.h"
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 textureDomain, 1397 textureDomain,
1398 GrTextureDomainEffect::kClamp _WrapMode, 1398 GrTextureDomainEffect::kClamp _WrapMode,
1399 params.isBilerp())); 1399 params.isBilerp()));
1400 } else { 1400 } else {
1401 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param s)); 1401 effect.reset(GrSimpleTextureEffect::Create(texture, SkMatrix::I(), param s));
1402 } 1402 }
1403 grPaint->colorStage(kBitmapEffectIdx)->setEffect(effect); 1403 grPaint->colorStage(kBitmapEffectIdx)->setEffect(effect);
1404 fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m); 1404 fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m);
1405 } 1405 }
1406 1406
1407 namespace {
1408
1409 void apply_effect(GrContext* context,
1410 GrTexture* srcTexture,
1411 GrTexture* dstTexture,
1412 const GrRect& rect,
1413 GrEffectRef* effect) {
1414 SkASSERT(srcTexture && srcTexture->getContext() == context);
1415 GrContext::AutoMatrix am;
1416 am.setIdentity(context);
1417 GrContext::AutoRenderTarget art(context, dstTexture->asRenderTarget());
1418 GrContext::AutoClip acs(context, rect);
1419
1420 GrPaint paint;
1421 paint.colorStage(0)->setEffect(effect);
1422 context->drawRect(paint, rect);
1423 }
1424
1425 };
1426
1427 static SkBitmap wrap_texture(GrTexture* texture) { 1407 static SkBitmap wrap_texture(GrTexture* texture) {
1428 SkBitmap result; 1408 SkBitmap result;
1429 bool dummy; 1409 bool dummy;
1430 SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy); 1410 SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy);
1431 result.setConfig(config, texture->width(), texture->height()); 1411 result.setConfig(config, texture->width(), texture->height());
1432 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); 1412 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
1433 return result; 1413 return result;
1434 } 1414 }
1435 1415
1436 static bool filter_texture(SkDevice* device, GrContext* context, 1416 static bool filter_texture(SkDevice* device, GrContext* context,
1437 GrTexture* texture, SkImageFilter* filter, 1417 GrTexture* texture, SkImageFilter* filter,
1438 int w, int h, SkBitmap* result) { 1418 int w, int h, SkBitmap* result) {
1439 GrAssert(filter); 1419 GrAssert(filter);
1440 SkDeviceImageFilterProxy proxy(device); 1420 SkDeviceImageFilterProxy proxy(device);
1441 1421
1442 GrTextureDesc desc;
1443 desc.fFlags = kRenderTarget_GrTextureFlagBit,
1444 desc.fWidth = w;
1445 desc.fHeight = h;
1446 desc.fConfig = kRGBA_8888_GrPixelConfig;
1447 GrEffectRef* effect;
1448
1449 if (filter->canFilterImageGPU()) { 1422 if (filter->canFilterImageGPU()) {
1450 // Save the render target and set it to NULL, so we don't accidentally d raw to it in the 1423 // Save the render target and set it to NULL, so we don't accidentally d raw to it in the
1451 // filter. Also set the clip wide open and the matrix to identity. 1424 // filter. Also set the clip wide open and the matrix to identity.
1452 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); 1425 GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
1453 return filter->filterImageGPU(&proxy, wrap_texture(texture), result); 1426 return filter->filterImageGPU(&proxy, wrap_texture(texture), result);
1454 } else if (filter->asNewEffect(&effect, texture)) {
1455 GrAutoScratchTexture dst(context, desc);
1456 SkRect r = SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h));
1457 apply_effect(context, texture, dst.texture(), r, effect);
1458 SkAutoTUnref<GrTexture> resultTex(dst.detach());
1459 effect->unref();
1460 *result = wrap_texture(resultTex.get());
1461 return true;
1462 } else { 1427 } else {
1463 return false; 1428 return false;
1464 } 1429 }
1465 } 1430 }
1466 1431
1467 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 1432 void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
1468 int left, int top, const SkPaint& paint) { 1433 int left, int top, const SkPaint& paint) {
1469 // drawSprite is defined to be in device coords. 1434 // drawSprite is defined to be in device coords.
1470 CHECK_SHOULD_DRAW(draw, true); 1435 CHECK_SHOULD_DRAW(draw, true);
1471 1436
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1552
1588 // The device being drawn may not fill up its texture (saveLayer uses 1553 // The device being drawn may not fill up its texture (saveLayer uses
1589 // the approximate ). 1554 // the approximate ).
1590 GrRect srcRect = GrRect::MakeWH(SK_Scalar1 * w / devTex->width(), 1555 GrRect srcRect = GrRect::MakeWH(SK_Scalar1 * w / devTex->width(),
1591 SK_Scalar1 * h / devTex->height()); 1556 SK_Scalar1 * h / devTex->height());
1592 1557
1593 fContext->drawRectToRect(grPaint, dstRect, srcRect); 1558 fContext->drawRectToRect(grPaint, dstRect, srcRect);
1594 } 1559 }
1595 1560
1596 bool SkGpuDevice::canHandleImageFilter(SkImageFilter* filter) { 1561 bool SkGpuDevice::canHandleImageFilter(SkImageFilter* filter) {
1597 if (!filter->asNewEffect(NULL, NULL) && 1562 return filter->canFilterImageGPU();
1598 !filter->canFilterImageGPU()) {
1599 return false;
1600 }
1601 return true;
1602 } 1563 }
1603 1564
1604 bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, 1565 bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src,
1605 const SkMatrix& ctm, 1566 const SkMatrix& ctm,
1606 SkBitmap* result, SkIPoint* offset) { 1567 SkBitmap* result, SkIPoint* offset) {
1607 // want explicitly our impl, so guard against a subclass of us overriding it 1568 // want explicitly our impl, so guard against a subclass of us overriding it
1608 if (!this->SkGpuDevice::canHandleImageFilter(filter)) { 1569 if (!this->SkGpuDevice::canHandleImageFilter(filter)) {
1609 return false; 1570 return false;
1610 } 1571 }
1611 1572
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 GrTexture* texture, 1819 GrTexture* texture,
1859 bool needClear) 1820 bool needClear)
1860 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { 1821 : SkDevice(make_bitmap(context, texture->asRenderTarget())) {
1861 1822
1862 GrAssert(texture && texture->asRenderTarget()); 1823 GrAssert(texture && texture->asRenderTarget());
1863 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1824 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1864 // cache. We pass true for the third argument so that it will get unlocked. 1825 // cache. We pass true for the third argument so that it will get unlocked.
1865 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1826 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1866 fNeedClear = needClear; 1827 fNeedClear = needClear;
1867 } 1828 }
OLDNEW
« src/core/SkImageFilter.cpp ('K') | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698