aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrContext.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-02 21:05:45 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-02 21:05:45 +0000
commit05054f1a78a697b507580d0025db6c90423e033f (patch)
treefa00f0862980cdc712f21d2d792d59fe070ebcaa /src/gpu/GrContext.cpp
parentc8ccfb0fbadfdcadcc860bc648c5ac42aa9277b1 (diff)
Erode and dilate image filter effects, CPU and GPU implementations.
Review URL: http://codereview.appspot.com/5656067/ git-svn-id: http://skia.googlecode.com/svn/trunk@3310 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rw-r--r--src/gpu/GrContext.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2de978f757..d6ebada82a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -2007,31 +2007,11 @@ const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
return fGpu->getQuadIndexBuffer();
}
-void GrContext::convolveInX(GrTexture* texture,
- const SkRect& rect,
- const float* kernel,
- int kernelWidth) {
- ASSERT_OWNED_RESOURCE(texture);
-
- float imageIncrement[2] = {1.0f / texture->width(), 0.0f};
- convolve(texture, rect, imageIncrement, kernel, kernelWidth);
-}
-
-void GrContext::convolveInY(GrTexture* texture,
- const SkRect& rect,
- const float* kernel,
- int kernelWidth) {
- ASSERT_OWNED_RESOURCE(texture);
-
- float imageIncrement[2] = {0.0f, 1.0f / texture->height()};
- convolve(texture, rect, imageIncrement, kernel, kernelWidth);
-}
-
void GrContext::convolve(GrTexture* texture,
const SkRect& rect,
- float imageIncrement[2],
const float* kernel,
- int kernelWidth) {
+ int kernelWidth,
+ GrSamplerState::FilterDirection direction) {
ASSERT_OWNED_RESOURCE(texture);
GrDrawTarget::AutoStateRestore asr(fGpu);
@@ -2044,10 +2024,33 @@ void GrContext::convolve(GrTexture* texture,
drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kConvolution_Filter,
sampleM);
- drawState->sampler(0)->setConvolutionParams(kernelWidth,
- kernel,
- imageIncrement);
+ drawState->sampler(0)->setConvolutionParams(kernelWidth, kernel);
+ drawState->sampler(0)->setFilterDirection(direction);
+ drawState->setTexture(0, texture);
+ fGpu->drawSimpleRect(rect, NULL, 1 << 0);
+}
+void GrContext::applyMorphology(GrTexture* texture,
+ const SkRect& rect,
+ int radius,
+ GrSamplerState::Filter filter,
+ GrSamplerState::FilterDirection direction) {
+ ASSERT_OWNED_RESOURCE(texture);
+ GrAssert(filter == GrSamplerState::kErode_Filter ||
+ filter == GrSamplerState::kDilate_Filter);
+
+ GrDrawTarget::AutoStateRestore asr(fGpu);
+ GrDrawState* drawState = fGpu->drawState();
+ GrRenderTarget* target = drawState->getRenderTarget();
+ drawState->reset();
+ drawState->setRenderTarget(target);
+ GrMatrix sampleM;
+ sampleM.setIDiv(texture->width(), texture->height());
+ drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
+ filter,
+ sampleM);
+ drawState->sampler(0)->setMorphologyRadius(radius);
+ drawState->sampler(0)->setFilterDirection(direction);
drawState->setTexture(0, texture);
fGpu->drawSimpleRect(rect, NULL, 1 << 0);
}