2012-06-29 06:01:34 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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 "BasicLayersImpl.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include <new> // for operator new
|
|
|
|
#include "Layers.h" // for Layer, etc
|
|
|
|
#include "basic/BasicImplData.h" // for BasicImplData
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
|
|
#include "mozilla/DebugOnly.h" // for DebugOnly
|
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2013-09-24 20:45:14 +00:00
|
|
|
#include "AutoMaskData.h"
|
2012-06-29 06:01:34 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
2012-07-12 12:51:57 +00:00
|
|
|
|
2014-05-22 10:11:45 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2014-04-01 04:02:09 +00:00
|
|
|
bool
|
2014-05-12 00:31:27 +00:00
|
|
|
GetMaskData(Layer* aMaskLayer,
|
|
|
|
const Point& aDeviceOffset,
|
|
|
|
AutoMoz2DMaskData* aMaskData)
|
2014-04-01 04:02:09 +00:00
|
|
|
{
|
|
|
|
if (aMaskLayer) {
|
|
|
|
RefPtr<SourceSurface> surface =
|
|
|
|
static_cast<BasicImplData*>(aMaskLayer->ImplData())->GetAsSourceSurface();
|
|
|
|
if (surface) {
|
|
|
|
Matrix transform;
|
|
|
|
Matrix4x4 effectiveTransform = aMaskLayer->GetEffectiveTransform();
|
|
|
|
DebugOnly<bool> maskIs2D = effectiveTransform.CanDraw2D(&transform);
|
|
|
|
NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
|
2014-05-12 00:31:27 +00:00
|
|
|
transform.Translate(-aDeviceOffset.x, -aDeviceOffset.y);
|
2014-04-01 04:02:09 +00:00
|
|
|
aMaskData->Construct(transform, surface);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-29 06:01:34 +00:00
|
|
|
void
|
|
|
|
PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer)
|
|
|
|
{
|
2014-04-09 09:15:19 +00:00
|
|
|
AutoMoz2DMaskData mask;
|
2014-05-12 00:31:27 +00:00
|
|
|
if (GetMaskData(aMaskLayer, Point(), &mask)) {
|
2012-06-29 06:01:34 +00:00
|
|
|
if (aOpacity < 1.0) {
|
2014-01-23 18:26:40 +00:00
|
|
|
aContext->PushGroup(gfxContentType::COLOR_ALPHA);
|
2012-06-29 06:01:34 +00:00
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
aContext->PopGroupToSource();
|
|
|
|
}
|
2014-01-27 20:25:21 +00:00
|
|
|
aContext->SetMatrix(ThebesMatrix(mask.GetTransform()));
|
2012-07-12 12:51:58 +00:00
|
|
|
aContext->Mask(mask.GetSurface());
|
2012-06-29 06:01:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no mask, just paint normally
|
|
|
|
aContext->Paint(aOpacity);
|
2012-07-12 12:51:57 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 04:02:09 +00:00
|
|
|
void
|
|
|
|
FillRectWithMask(DrawTarget* aDT,
|
|
|
|
const Rect& aRect,
|
|
|
|
const Color& aColor,
|
|
|
|
const DrawOptions& aOptions,
|
2014-04-11 12:23:09 +00:00
|
|
|
SourceSurface* aMaskSource,
|
|
|
|
const Matrix* aMaskTransform)
|
2014-04-01 04:02:09 +00:00
|
|
|
{
|
2014-04-11 12:23:09 +00:00
|
|
|
if (aMaskSource && aMaskTransform) {
|
2014-04-01 04:02:09 +00:00
|
|
|
aDT->PushClipRect(aRect);
|
|
|
|
Matrix oldTransform = aDT->GetTransform();
|
|
|
|
|
2014-04-11 12:23:09 +00:00
|
|
|
aDT->SetTransform(*aMaskTransform);
|
|
|
|
aDT->MaskSurface(ColorPattern(aColor), aMaskSource, Point(), aOptions);
|
2014-04-01 04:02:09 +00:00
|
|
|
aDT->SetTransform(oldTransform);
|
|
|
|
aDT->PopClip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aDT->FillRect(aRect, ColorPattern(aColor), aOptions);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
FillRectWithMask(DrawTarget* aDT,
|
2014-05-12 00:31:27 +00:00
|
|
|
const gfx::Point& aDeviceOffset,
|
2014-04-01 04:02:09 +00:00
|
|
|
const Rect& aRect,
|
2014-04-11 12:23:09 +00:00
|
|
|
const Color& aColor,
|
2014-04-01 04:02:09 +00:00
|
|
|
const DrawOptions& aOptions,
|
|
|
|
Layer* aMaskLayer)
|
|
|
|
{
|
|
|
|
AutoMoz2DMaskData mask;
|
2014-05-12 00:31:27 +00:00
|
|
|
if (GetMaskData(aMaskLayer, aDeviceOffset, &mask)) {
|
2014-04-11 12:23:09 +00:00
|
|
|
const Matrix& maskTransform = mask.GetTransform();
|
|
|
|
FillRectWithMask(aDT, aRect, aColor, aOptions, mask.GetSurface(), &maskTransform);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillRectWithMask(aDT, aRect, aColor, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FillRectWithMask(DrawTarget* aDT,
|
|
|
|
const Rect& aRect,
|
|
|
|
SourceSurface* aSurface,
|
|
|
|
Filter aFilter,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
ExtendMode aExtendMode,
|
|
|
|
SourceSurface* aMaskSource,
|
|
|
|
const Matrix* aMaskTransform,
|
|
|
|
const Matrix* aSurfaceTransform)
|
|
|
|
{
|
|
|
|
if (aMaskSource && aMaskTransform) {
|
2014-04-01 04:02:09 +00:00
|
|
|
aDT->PushClipRect(aRect);
|
|
|
|
Matrix oldTransform = aDT->GetTransform();
|
|
|
|
|
2014-04-11 12:23:09 +00:00
|
|
|
Matrix inverseMask = *aMaskTransform;
|
2014-04-01 04:02:09 +00:00
|
|
|
inverseMask.Invert();
|
|
|
|
|
2014-04-24 07:38:35 +00:00
|
|
|
Matrix transform = oldTransform * inverseMask;
|
2014-04-11 12:23:09 +00:00
|
|
|
if (aSurfaceTransform) {
|
2014-05-28 01:21:32 +00:00
|
|
|
transform = (*aSurfaceTransform) * transform;
|
2014-04-11 12:23:09 +00:00
|
|
|
}
|
2014-04-01 04:02:09 +00:00
|
|
|
|
2014-04-11 12:23:09 +00:00
|
|
|
SurfacePattern source(aSurface, aExtendMode, transform, aFilter);
|
2014-04-01 04:02:09 +00:00
|
|
|
|
2014-04-11 12:23:09 +00:00
|
|
|
aDT->SetTransform(*aMaskTransform);
|
|
|
|
aDT->MaskSurface(source, aMaskSource, Point(0, 0), aOptions);
|
2014-04-01 04:02:09 +00:00
|
|
|
aDT->SetTransform(oldTransform);
|
|
|
|
aDT->PopClip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:23:09 +00:00
|
|
|
aDT->FillRect(aRect,
|
|
|
|
SurfacePattern(aSurface, aExtendMode,
|
|
|
|
aSurfaceTransform ? (*aSurfaceTransform) : Matrix(),
|
|
|
|
aFilter), aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FillRectWithMask(DrawTarget* aDT,
|
2014-05-12 00:31:27 +00:00
|
|
|
const gfx::Point& aDeviceOffset,
|
2014-04-11 12:23:09 +00:00
|
|
|
const Rect& aRect,
|
|
|
|
SourceSurface* aSurface,
|
|
|
|
Filter aFilter,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
Layer* aMaskLayer)
|
|
|
|
{
|
|
|
|
AutoMoz2DMaskData mask;
|
2014-05-12 00:31:27 +00:00
|
|
|
if (GetMaskData(aMaskLayer, aDeviceOffset, &mask)) {
|
2014-04-11 12:23:09 +00:00
|
|
|
const Matrix& maskTransform = mask.GetTransform();
|
|
|
|
FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP,
|
|
|
|
mask.GetSurface(), &maskTransform);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP);
|
2014-04-01 04:02:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 06:01:34 +00:00
|
|
|
BasicImplData*
|
|
|
|
ToData(Layer* aLayer)
|
|
|
|
{
|
|
|
|
return static_cast<BasicImplData*>(aLayer->ImplData());
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:56:48 +00:00
|
|
|
gfx::CompositionOp
|
|
|
|
GetEffectiveOperator(Layer* aLayer)
|
|
|
|
{
|
|
|
|
CompositionOp op = aLayer->GetEffectiveMixBlendMode();
|
|
|
|
|
|
|
|
if (op != CompositionOp::OP_OVER) {
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ToData(aLayer)->GetOperator();
|
|
|
|
}
|
|
|
|
|
2012-06-29 06:01:34 +00:00
|
|
|
ShadowableLayer*
|
|
|
|
ToShadowable(Layer* aLayer)
|
|
|
|
{
|
|
|
|
return aLayer->AsShadowableLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShouldShadow(Layer* aLayer)
|
|
|
|
{
|
|
|
|
if (!ToShadowable(aLayer)) {
|
|
|
|
NS_ABORT_IF_FALSE(aLayer->GetType() == Layer::TYPE_READBACK,
|
|
|
|
"Only expect not to shadow ReadbackLayers");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-12 12:51:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|