2014-06-11 23:53:02 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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/. */
|
|
|
|
|
2014-09-01 09:28:53 +04:00
|
|
|
#include "DrawTargetTiled.h"
|
|
|
|
#include "Logging.h"
|
2015-02-24 00:20:35 +03:00
|
|
|
#include "PathHelpers.h"
|
2014-09-01 09:28:53 +04:00
|
|
|
|
2014-06-11 23:53:02 +04:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
DrawTargetTiled::DrawTargetTiled()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetTiled::Init(const TileSet& aTiles)
|
|
|
|
{
|
|
|
|
if (!aTiles.mTileCount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-06 16:40:03 +04:00
|
|
|
mTiles.reserve(aTiles.mTileCount);
|
|
|
|
for (size_t i = 0; i < aTiles.mTileCount; ++i) {
|
2014-09-03 16:11:28 +04:00
|
|
|
mTiles.push_back(TileInternal(aTiles.mTiles[i]));
|
2014-08-06 16:40:03 +04:00
|
|
|
if (!aTiles.mTiles[i].mDrawTarget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mTiles[0].mDrawTarget->GetFormat() != mTiles.back().mDrawTarget->GetFormat() ||
|
|
|
|
mTiles[0].mDrawTarget->GetBackendType() != mTiles.back().mDrawTarget->GetBackendType()) {
|
2014-06-11 23:53:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uint32_t newXMost = max(mRect.XMost(),
|
|
|
|
mTiles[i].mTileOrigin.x + mTiles[i].mDrawTarget->GetSize().width);
|
|
|
|
uint32_t newYMost = max(mRect.YMost(),
|
|
|
|
mTiles[i].mTileOrigin.y + mTiles[i].mDrawTarget->GetSize().height);
|
2014-08-28 20:45:48 +04:00
|
|
|
mRect.x = min(mRect.x, mTiles[i].mTileOrigin.x);
|
|
|
|
mRect.y = min(mRect.y, mTiles[i].mTileOrigin.y);
|
2014-06-11 23:53:02 +04:00
|
|
|
mRect.width = newXMost - mRect.x;
|
|
|
|
mRect.height = newYMost - mRect.y;
|
2015-02-05 13:09:57 +03:00
|
|
|
mTiles[i].mDrawTarget->SetTransform(Matrix::Translation(mTiles[i].mTileOrigin.x,
|
|
|
|
mTiles[i].mTileOrigin.y));
|
2014-06-11 23:53:02 +04:00
|
|
|
}
|
2014-08-29 07:07:35 +04:00
|
|
|
mFormat = mTiles[0].mDrawTarget->GetFormat();
|
2014-06-11 23:53:02 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2014-06-11 23:53:02 +04:00
|
|
|
DrawTargetTiled::Snapshot()
|
|
|
|
{
|
2015-04-30 22:20:30 +03:00
|
|
|
return MakeAndAddRef<SnapshotTiled>(mTiles, mRect);
|
2014-06-11 23:53:02 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 11:58:13 +03:00
|
|
|
void
|
|
|
|
DrawTargetTiled::DetachAllSnapshots()
|
|
|
|
{}
|
|
|
|
|
2014-09-03 01:20:44 +04:00
|
|
|
// Skip the mClippedOut check since this is only used for Flush() which
|
|
|
|
// should happen even if we're clipped.
|
2014-06-11 23:53:02 +04:00
|
|
|
#define TILED_COMMAND(command) \
|
|
|
|
void \
|
|
|
|
DrawTargetTiled::command() \
|
|
|
|
{ \
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) { \
|
2014-09-03 01:20:44 +04:00
|
|
|
mTiles[i].mDrawTarget->command(); \
|
2014-06-11 23:53:02 +04:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TILED_COMMAND1(command, type1) \
|
|
|
|
void \
|
|
|
|
DrawTargetTiled::command(type1 arg1) \
|
|
|
|
{ \
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) { \
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut) \
|
|
|
|
mTiles[i].mDrawTarget->command(arg1); \
|
2014-06-11 23:53:02 +04:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TILED_COMMAND3(command, type1, type2, type3) \
|
|
|
|
void \
|
|
|
|
DrawTargetTiled::command(type1 arg1, type2 arg2, type3 arg3) \
|
|
|
|
{ \
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) { \
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut) \
|
|
|
|
mTiles[i].mDrawTarget->command(arg1, arg2, arg3); \
|
2014-06-11 23:53:02 +04:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TILED_COMMAND4(command, type1, type2, type3, type4) \
|
|
|
|
void \
|
|
|
|
DrawTargetTiled::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
|
|
|
|
{ \
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) { \
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut) \
|
|
|
|
mTiles[i].mDrawTarget->command(arg1, arg2, arg3, arg4); \
|
2014-06-11 23:53:02 +04:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define TILED_COMMAND5(command, type1, type2, type3, type4, type5) \
|
|
|
|
void \
|
|
|
|
DrawTargetTiled::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
|
|
|
|
{ \
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) { \
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut) \
|
|
|
|
mTiles[i].mDrawTarget->command(arg1, arg2, arg3, arg4, arg5); \
|
2014-06-11 23:53:02 +04:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
TILED_COMMAND(Flush)
|
|
|
|
TILED_COMMAND4(DrawFilter, FilterNode*, const Rect&, const Point&, const DrawOptions&)
|
|
|
|
TILED_COMMAND1(ClearRect, const Rect&)
|
|
|
|
TILED_COMMAND4(MaskSurface, const Pattern&, SourceSurface*, Point, const DrawOptions&)
|
|
|
|
TILED_COMMAND5(FillGlyphs, ScaledFont*, const GlyphBuffer&, const Pattern&, const DrawOptions&, const GlyphRenderingOptions*)
|
|
|
|
TILED_COMMAND3(Mask, const Pattern&, const Pattern&, const DrawOptions&)
|
2014-09-03 01:20:44 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::PushClip(const Path* aPath)
|
|
|
|
{
|
|
|
|
mClippedOutTilesStack.push_back(std::vector<uint32_t>());
|
|
|
|
std::vector<uint32_t>& clippedTiles = mClippedOutTilesStack.back();
|
|
|
|
|
|
|
|
Rect deviceRect = aPath->GetBounds(mTransform);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
if (!mTiles[i].mClippedOut) {
|
|
|
|
if (deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->PushClip(aPath);
|
|
|
|
} else {
|
|
|
|
mTiles[i].mClippedOut = true;
|
|
|
|
clippedTiles.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::PushClipRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
mClippedOutTilesStack.push_back(std::vector<uint32_t>());
|
|
|
|
std::vector<uint32_t>& clippedTiles = mClippedOutTilesStack.back();
|
|
|
|
|
|
|
|
Rect deviceRect = mTransform.TransformBounds(aRect);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
if (!mTiles[i].mClippedOut) {
|
|
|
|
if (deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->PushClipRect(aRect);
|
|
|
|
} else {
|
|
|
|
mTiles[i].mClippedOut = true;
|
|
|
|
clippedTiles.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::PopClip()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
if (!mTiles[i].mClippedOut) {
|
|
|
|
mTiles[i].mDrawTarget->PopClip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<uint32_t>& clippedTiles = mClippedOutTilesStack.back();
|
|
|
|
for (size_t i = 0; i < clippedTiles.size(); i++) {
|
|
|
|
mTiles[clippedTiles[i]].mClippedOut = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mClippedOutTilesStack.pop_back();
|
|
|
|
}
|
2014-06-11 23:53:02 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
|
|
|
const IntPoint &aDestination)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
2015-01-19 14:36:43 +03:00
|
|
|
IntPoint tileOrigin = mTiles[i].mTileOrigin;
|
|
|
|
IntSize tileSize = mTiles[i].mDrawTarget->GetSize();
|
|
|
|
if (!IntRect(aDestination, aSourceRect.Size()).Intersects(IntRect(tileOrigin, tileSize))) {
|
2014-06-11 23:53:02 +04:00
|
|
|
continue;
|
|
|
|
}
|
2015-01-19 14:36:43 +03:00
|
|
|
// CopySurface ignores the transform, account for that here.
|
|
|
|
mTiles[i].mDrawTarget->CopySurface(aSurface, aSourceRect, aDestination - tileOrigin);
|
2014-06-11 23:53:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::SetTransform(const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
Matrix mat = aTransform;
|
|
|
|
mat.PostTranslate(Float(-mTiles[i].mTileOrigin.x), Float(-mTiles[i].mTileOrigin.y));
|
|
|
|
mTiles[i].mDrawTarget->SetTransform(mat);
|
|
|
|
}
|
|
|
|
DrawTarget::SetTransform(aTransform);
|
|
|
|
}
|
|
|
|
|
2014-09-03 01:20:10 +04:00
|
|
|
void
|
|
|
|
DrawTargetTiled::DrawSurface(SourceSurface* aSurface, const Rect& aDest, const Rect& aSource, const DrawSurfaceOptions& aSurfaceOptions, const DrawOptions& aDrawOptions)
|
|
|
|
{
|
|
|
|
Rect deviceRect = mTransform.TransformBounds(aDest);
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut &&
|
|
|
|
deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
2014-09-03 01:20:10 +04:00
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->DrawSurface(aSurface, aDest, aSource, aSurfaceOptions, aDrawOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::FillRect(const Rect& aRect, const Pattern& aPattern, const DrawOptions& aDrawOptions)
|
|
|
|
{
|
|
|
|
Rect deviceRect = mTransform.TransformBounds(aRect);
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut &&
|
|
|
|
deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
2014-09-03 01:20:10 +04:00
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->FillRect(aRect, aPattern, aDrawOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-24 00:20:35 +03:00
|
|
|
void
|
|
|
|
DrawTargetTiled::Stroke(const Path* aPath, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, const DrawOptions& aDrawOptions)
|
2014-09-03 01:20:33 +04:00
|
|
|
{
|
2015-02-24 00:20:35 +03:00
|
|
|
// Approximate the stroke extents, since Path::GetStrokeExtents can be slow
|
|
|
|
Rect deviceRect = aPath->GetBounds(mTransform);
|
|
|
|
deviceRect.Inflate(MaxStrokeExtents(aStrokeOptions, mTransform));
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
if (!mTiles[i].mClippedOut &&
|
|
|
|
deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->Stroke(aPath, aPattern, aStrokeOptions, aDrawOptions);
|
|
|
|
}
|
2014-09-03 01:20:33 +04:00
|
|
|
}
|
2015-02-24 00:20:35 +03:00
|
|
|
}
|
2014-09-03 01:20:33 +04:00
|
|
|
|
2015-02-24 00:20:35 +03:00
|
|
|
void
|
|
|
|
DrawTargetTiled::StrokeRect(const Rect& aRect, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
|
|
|
|
{
|
|
|
|
Rect deviceRect = mTransform.TransformBounds(aRect);
|
|
|
|
Margin strokeMargin = MaxStrokeExtents(aStrokeOptions, mTransform);
|
|
|
|
Rect outerRect = deviceRect;
|
|
|
|
outerRect.Inflate(strokeMargin);
|
|
|
|
Rect innerRect;
|
|
|
|
if (mTransform.IsRectilinear()) {
|
|
|
|
// If rects are mapped to rects, we can compute the inner rect
|
|
|
|
// of the stroked rect.
|
|
|
|
innerRect = deviceRect;
|
|
|
|
innerRect.Deflate(strokeMargin);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
if (mTiles[i].mClippedOut) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Rect tileRect(mTiles[i].mTileOrigin.x,
|
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height);
|
|
|
|
if (outerRect.Intersects(tileRect) && !innerRect.Contains(tileRect)) {
|
|
|
|
mTiles[i].mDrawTarget->StrokeRect(aRect, aPattern, aStrokeOptions, aDrawOptions);
|
|
|
|
}
|
2014-09-03 01:20:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 01:20:10 +04:00
|
|
|
void
|
2015-02-24 00:20:35 +03:00
|
|
|
DrawTargetTiled::StrokeLine(const Point& aStart, const Point& aEnd, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
|
2014-09-03 01:20:10 +04:00
|
|
|
{
|
2015-02-24 00:20:35 +03:00
|
|
|
Rect lineBounds = Rect(aStart, Size()).UnionEdges(Rect(aEnd, Size()));
|
|
|
|
Rect deviceRect = mTransform.TransformBounds(lineBounds);
|
|
|
|
deviceRect.Inflate(MaxStrokeExtents(aStrokeOptions, mTransform));
|
2014-09-03 01:20:10 +04:00
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut &&
|
|
|
|
deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
2014-09-03 01:20:10 +04:00
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
2015-02-24 00:20:35 +03:00
|
|
|
mTiles[i].mDrawTarget->StrokeLine(aStart, aEnd, aPattern, aStrokeOptions, aDrawOptions);
|
2014-09-03 01:20:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::Fill(const Path* aPath, const Pattern& aPattern, const DrawOptions& aDrawOptions)
|
|
|
|
{
|
|
|
|
Rect deviceRect = aPath->GetBounds(mTransform);
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
2014-09-03 01:20:44 +04:00
|
|
|
if (!mTiles[i].mClippedOut &&
|
|
|
|
deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
|
2014-09-03 01:20:10 +04:00
|
|
|
mTiles[i].mTileOrigin.y,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().width,
|
|
|
|
mTiles[i].mDrawTarget->GetSize().height))) {
|
|
|
|
mTiles[i].mDrawTarget->Fill(aPath, aPattern, aDrawOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 02:23:33 +03:00
|
|
|
void
|
|
|
|
DrawTargetTiled::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform, const IntRect& aBounds,
|
|
|
|
bool aCopyBackground)
|
|
|
|
{
|
|
|
|
// XXX - not sure this is what we want or whether we want to continue drawing to a larger
|
|
|
|
// intermediate surface, that would require tweaking the code in here a little though.
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
IntRect bounds = aBounds;
|
|
|
|
bounds.MoveBy(-mTiles[i].mTileOrigin);
|
|
|
|
mTiles[i].mDrawTarget->PushLayer(aOpaque, aOpacity, aMask, aMaskTransform, aBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetTiled::PopLayer()
|
|
|
|
{
|
|
|
|
// XXX - not sure this is what we want or whether we want to continue drawing to a larger
|
|
|
|
// intermediate surface, that would require tweaking the code in here a little though.
|
|
|
|
for (size_t i = 0; i < mTiles.size(); i++) {
|
|
|
|
mTiles[i].mDrawTarget->PopLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|