gecko-dev/gfx/thebes/gfxBlur.cpp

113 строки
3.9 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2012-05-21 15:12:37 +04:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gfxBlur.h"
#include "mozilla/gfx/Blur.h"
using namespace mozilla::gfx;
gfxAlphaBoxBlur::gfxAlphaBoxBlur()
: mBlur(nullptr)
{
}
gfxAlphaBoxBlur::~gfxAlphaBoxBlur()
{
mContext = nullptr;
mImageSurface = nullptr;
delete mBlur;
}
gfxContext*
gfxAlphaBoxBlur::Init(const gfxRect& aRect,
const gfxIntSize& aSpreadRadius,
const gfxIntSize& aBlurRadius,
const gfxRect* aDirtyRect,
const gfxRect* aSkipRect)
{
mozilla::gfx::Rect rect(Float(aRect.x), Float(aRect.y),
Float(aRect.width), Float(aRect.height));
IntSize spreadRadius(aSpreadRadius.width, aSpreadRadius.height);
IntSize blurRadius(aBlurRadius.width, aBlurRadius.height);
nsAutoPtr<mozilla::gfx::Rect> dirtyRect;
if (aDirtyRect) {
dirtyRect = new mozilla::gfx::Rect(Float(aDirtyRect->x),
Float(aDirtyRect->y),
Float(aDirtyRect->width),
Float(aDirtyRect->height));
}
nsAutoPtr<mozilla::gfx::Rect> skipRect;
2011-11-17 22:01:11 +04:00
if (aSkipRect) {
skipRect = new mozilla::gfx::Rect(Float(aSkipRect->x),
Float(aSkipRect->y),
Float(aSkipRect->width),
Float(aSkipRect->height));
2011-11-17 22:01:11 +04:00
}
mBlur = new AlphaBoxBlur(rect, spreadRadius, blurRadius, dirtyRect, skipRect);
int32_t blurDataSize = mBlur->GetSurfaceAllocationSize();
if (blurDataSize <= 0)
return nullptr;
IntSize size = mBlur->GetSize();
// Make an alpha-only surface to draw on. We will play with the data after
// everything is drawn to create a blur effect.
mImageSurface = new gfxImageSurface(gfxIntSize(size.width, size.height),
Bug 913872 - Take nested enums out of gfxASurface - 1/3 : automatic changes - r=jrmuizel Generated by these regexes: find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(ImageFormat\|SurfaceType\|ContentType\|MemoryLocation\)[0-9A-Za-z_]*\)/gfx\1/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(CONTENT_\|MEMORY_\)[0-9A-Za-z_]*\)/GFX_\1/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(CONTENT_COLOR\|CONTENT_ALPHA\|CONTENT_COLOR_ALPHA\|CONTENT_SENTINEL\|MEMORY_IN_PROCESS_HEAP\|MEMORY_IN_PROCESS_NONHEAP\|MEMORY_OUT_OF_PROCESS\)\($\|[^A-Za-z0-9_]\)/\1GFX_\2\3/g' find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(ImageFormatARGB32\|ImageFormatRGB24\|ImageFormatA8\|ImageFormatA1\|ImageFormatRGB16_565\|ImageFormatUnknown\|SurfaceTypeImage\|SurfaceTypePDF\|SurfaceTypePS\|SurfaceTypeXlib\|SurfaceTypeXcb\|SurfaceTypeGlitz\|SurfaceTypeQuartz\|SurfaceTypeWin32\|SurfaceTypeBeOS\|SurfaceTypeDirectFB\|SurfaceTypeSVG\|SurfaceTypeOS2\|SurfaceTypeWin32Printing\|SurfaceTypeQuartzImage\|SurfaceTypeScript\|SurfaceTypeQPainter\|SurfaceTypeRecording\|SurfaceTypeVG\|SurfaceTypeGL\|SurfaceTypeDRM\|SurfaceTypeTee\|SurfaceTypeXML\|SurfaceTypeSkia\|SurfaceTypeSubsurface\|SurfaceTypeD2D\|SurfaceTypeMax\)\($\|[^A-Za-z0-9_]\)/\1gfx\2\3/g'
2013-09-25 00:45:13 +04:00
gfxImageFormatA8,
mBlur->GetStride(),
blurDataSize,
true);
if (mImageSurface->CairoStatus())
return nullptr;
IntRect irect = mBlur->GetRect();
gfxPoint topleft(irect.TopLeft().x, irect.TopLeft().y);
// Use a device offset so callers don't need to worry about translating
// coordinates, they can draw as if this was part of the destination context
// at the coordinates of rect.
mImageSurface->SetDeviceOffset(-topleft);
mContext = new gfxContext(mImageSurface);
return mContext;
}
void
gfxAlphaBoxBlur::Paint(gfxContext* aDestinationCtx, const gfxPoint& offset)
{
if (!mContext)
return;
mBlur->Blur(mImageSurface->Data());
mozilla::gfx::Rect* dirtyrect = mBlur->GetDirtyRect();
// Avoid a semi-expensive clip operation if we can, otherwise
// clip to the dirty rect
if (dirtyrect) {
aDestinationCtx->Save();
aDestinationCtx->NewPath();
gfxRect dirty(dirtyrect->x, dirtyrect->y, dirtyrect->width, dirtyrect->height);
gfxRect imageRect(offset - mImageSurface->GetDeviceOffset(), mImageSurface->GetSize());
dirty.IntersectRect(dirty, imageRect);
aDestinationCtx->Rectangle(dirty);
aDestinationCtx->Clip();
aDestinationCtx->Mask(mImageSurface, offset);
aDestinationCtx->Restore();
} else {
aDestinationCtx->Mask(mImageSurface, offset);
}
}
gfxIntSize gfxAlphaBoxBlur::CalculateBlurRadius(const gfxPoint& aStd)
{
mozilla::gfx::Point std(Float(aStd.x), Float(aStd.y));
IntSize size = AlphaBoxBlur::CalculateBlurRadius(std);
return gfxIntSize(size.width, size.height);
}