2014-08-01 20:01:47 +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/. */
|
|
|
|
|
|
|
|
#include "DrawTargetCapture.h"
|
|
|
|
#include "DrawCommand.h"
|
2017-07-27 01:43:00 +03:00
|
|
|
#include "gfxPlatform.h"
|
2014-08-01 20:01:47 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
|
|
|
|
DrawTargetCaptureImpl::~DrawTargetCaptureImpl()
|
|
|
|
{
|
|
|
|
uint8_t* start = &mDrawCommandStorage.front();
|
|
|
|
|
|
|
|
uint8_t* current = start;
|
|
|
|
|
|
|
|
while (current < start + mDrawCommandStorage.size()) {
|
|
|
|
reinterpret_cast<DrawingCommand*>(current + sizeof(uint32_t))->~DrawingCommand();
|
|
|
|
current += *(uint32_t*)current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:43:00 +03:00
|
|
|
DrawTargetCaptureImpl::DrawTargetCaptureImpl(BackendType aBackend,
|
|
|
|
const IntSize& aSize,
|
|
|
|
SurfaceFormat aFormat)
|
|
|
|
: mSize(aSize)
|
|
|
|
{
|
|
|
|
RefPtr<DrawTarget> screenRefDT =
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
|
|
|
|
|
|
|
if (aBackend == screenRefDT->GetBackendType()) {
|
|
|
|
mRefDT = screenRefDT;
|
|
|
|
} else {
|
|
|
|
// If you got here, we have to create a new ref DT to create
|
|
|
|
// backend specific assets like paths / gradients. Try to
|
|
|
|
// create the same backend type as the screen ref dt.
|
|
|
|
gfxWarning() << "Creating a RefDT in DrawTargetCapture.";
|
|
|
|
|
|
|
|
// Create a 1x1 size ref dt to create assets
|
|
|
|
// If we have to snapshot, we'll just create the real DT
|
|
|
|
IntSize size(1, 1);
|
|
|
|
mRefDT = Factory::CreateDrawTarget(aBackend, size, mFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
}
|
|
|
|
|
2014-08-01 20:01:47 +04:00
|
|
|
bool
|
|
|
|
DrawTargetCaptureImpl::Init(const IntSize& aSize, DrawTarget* aRefDT)
|
|
|
|
{
|
|
|
|
if (!aRefDT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRefDT = aRefDT;
|
|
|
|
|
|
|
|
mSize = aSize;
|
2017-07-14 20:55:03 +03:00
|
|
|
mFormat = aRefDT->GetFormat();
|
2014-08-01 20:01:47 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2014-08-01 20:01:47 +04:00
|
|
|
DrawTargetCaptureImpl::Snapshot()
|
|
|
|
{
|
2017-07-27 01:43:00 +03:00
|
|
|
RefPtr<DrawTarget> dt = mRefDT->CreateSimilarDrawTarget(mSize, mFormat);
|
2014-08-01 20:01:47 +04:00
|
|
|
|
|
|
|
ReplayToDrawTarget(dt, Matrix());
|
|
|
|
|
|
|
|
return dt->Snapshot();
|
|
|
|
}
|
|
|
|
|
2016-07-01 11:58:13 +03:00
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::DetachAllSnapshots()
|
|
|
|
{}
|
|
|
|
|
2014-08-01 20:01:47 +04:00
|
|
|
#define AppendCommand(arg) new (AppendToCommandList<arg>()) arg
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
aSurface->GuaranteePersistance();
|
|
|
|
AppendCommand(DrawSurfaceCommand)(aSurface, aDest, aSource, aSurfOptions, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
// @todo XXX - this won't work properly long term yet due to filternodes not
|
|
|
|
// being immutable.
|
|
|
|
AppendCommand(DrawFilterCommand)(aNode, aSourceRect, aDestPoint, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::ClearRect(const Rect &aRect)
|
|
|
|
{
|
|
|
|
AppendCommand(ClearRectCommand)(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
aMask->GuaranteePersistance();
|
|
|
|
AppendCommand(MaskSurfaceCommand)(aSource, aMask, aOffset, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::CopySurface(SourceSurface* aSurface,
|
|
|
|
const IntRect& aSourceRect,
|
|
|
|
const IntPoint& aDestination)
|
|
|
|
{
|
|
|
|
aSurface->GuaranteePersistance();
|
|
|
|
AppendCommand(CopySurfaceCommand)(aSurface, aSourceRect, aDestination);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::FillRect(const Rect& aRect,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(FillRectCommand)(aRect, aPattern, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::StrokeRect(const Rect& aRect,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(StrokeRectCommand)(aRect, aPattern, aStrokeOptions, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::StrokeLine(const Point& aStart,
|
|
|
|
const Point& aEnd,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(StrokeLineCommand)(aStart, aEnd, aPattern, aStrokeOptions, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::Stroke(const Path* aPath,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(StrokeCommand)(aPath, aPattern, aStrokeOptions, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::Fill(const Path* aPath,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(FillCommand)(aPath, aPattern, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::FillGlyphs(ScaledFont* aFont,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderingOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(FillGlyphsCommand)(aFont, aBuffer, aPattern, aOptions, aRenderingOptions);
|
|
|
|
}
|
|
|
|
|
2017-07-15 03:48:00 +03:00
|
|
|
void DrawTargetCaptureImpl::StrokeGlyphs(ScaledFont* aFont,
|
|
|
|
const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const GlyphRenderingOptions* aRenderingOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(StrokeGlyphsCommand)(aFont, aBuffer, aPattern, aStrokeOptions, aOptions, aRenderingOptions);
|
|
|
|
}
|
|
|
|
|
2014-08-01 20:01:47 +04:00
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
AppendCommand(MaskCommand)(aSource, aMask, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::PushClip(const Path* aPath)
|
|
|
|
{
|
|
|
|
AppendCommand(PushClipCommand)(aPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::PushClipRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
AppendCommand(PushClipRectCommand)(aRect);
|
|
|
|
}
|
|
|
|
|
2017-06-22 00:19:42 +03:00
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::PushLayer(bool aOpaque,
|
|
|
|
Float aOpacity,
|
|
|
|
SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds,
|
|
|
|
bool aCopyBackground)
|
|
|
|
{
|
|
|
|
AppendCommand(PushLayerCommand)(aOpaque,
|
|
|
|
aOpacity,
|
|
|
|
aMask,
|
|
|
|
aMaskTransform,
|
|
|
|
aBounds,
|
|
|
|
aCopyBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::PopLayer()
|
|
|
|
{
|
|
|
|
AppendCommand(PopLayerCommand)();
|
|
|
|
}
|
|
|
|
|
2014-08-01 20:01:47 +04:00
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::PopClip()
|
|
|
|
{
|
|
|
|
AppendCommand(PopClipCommand)();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::SetTransform(const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
AppendCommand(SetTransformCommand)(aTransform);
|
2017-06-29 01:22:59 +03:00
|
|
|
|
|
|
|
// Have to update the transform for this DT
|
|
|
|
// because some code paths query the current transform
|
|
|
|
// to render specific things.
|
|
|
|
DrawTarget::SetTransform(aTransform);
|
2014-08-01 20:01:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetCaptureImpl::ReplayToDrawTarget(DrawTarget* aDT, const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
uint8_t* start = &mDrawCommandStorage.front();
|
|
|
|
|
|
|
|
uint8_t* current = start;
|
|
|
|
|
|
|
|
while (current < start + mDrawCommandStorage.size()) {
|
2015-09-28 14:49:45 +03:00
|
|
|
reinterpret_cast<DrawingCommand*>(current + sizeof(uint32_t))->ExecuteOnDT(aDT, &aTransform);
|
2014-08-01 20:01:47 +04:00
|
|
|
current += *(uint32_t*)current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:11:29 +03:00
|
|
|
bool
|
|
|
|
DrawTargetCaptureImpl::ContainsOnlyColoredGlyphs(RefPtr<ScaledFont>& aScaledFont,
|
|
|
|
Color& aColor,
|
|
|
|
std::vector<Glyph>& aGlyphs)
|
|
|
|
{
|
|
|
|
uint8_t* start = &mDrawCommandStorage.front();
|
|
|
|
uint8_t* current = start;
|
2017-05-18 05:55:28 +03:00
|
|
|
bool result = false;
|
2016-11-24 08:11:29 +03:00
|
|
|
|
|
|
|
while (current < start + mDrawCommandStorage.size()) {
|
|
|
|
DrawingCommand* command =
|
|
|
|
reinterpret_cast<DrawingCommand*>(current + sizeof(uint32_t));
|
|
|
|
current += *(uint32_t*)current;
|
|
|
|
|
|
|
|
if (command->GetType() != CommandType::FILLGLYPHS &&
|
|
|
|
command->GetType() != CommandType::SETTRANSFORM) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command->GetType() == CommandType::SETTRANSFORM) {
|
|
|
|
SetTransformCommand* transform = static_cast<SetTransformCommand*>(command);
|
|
|
|
if (transform->mTransform != Matrix()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillGlyphsCommand* fillGlyphs = static_cast<FillGlyphsCommand*>(command);
|
|
|
|
if (aScaledFont && fillGlyphs->mFont != aScaledFont) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aScaledFont = fillGlyphs->mFont;
|
|
|
|
|
|
|
|
Pattern& pat = fillGlyphs->mPattern;
|
|
|
|
|
|
|
|
if (pat.GetType() != PatternType::COLOR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorPattern* colorPat = static_cast<ColorPattern*>(&pat);
|
|
|
|
if (aColor != Color() && colorPat->mColor != aColor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aColor = colorPat->mColor;
|
|
|
|
|
|
|
|
if (fillGlyphs->mOptions.mCompositionOp != CompositionOp::OP_OVER ||
|
|
|
|
fillGlyphs->mOptions.mAlpha != 1.0f) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Deal with AA on the DrawOptions, and the GlyphRenderingOptions
|
|
|
|
|
|
|
|
aGlyphs.insert(aGlyphs.end(),
|
|
|
|
fillGlyphs->mGlyphs.begin(),
|
|
|
|
fillGlyphs->mGlyphs.end());
|
2017-05-18 05:55:28 +03:00
|
|
|
result = true;
|
2016-11-24 08:11:29 +03:00
|
|
|
}
|
2017-05-18 05:55:28 +03:00
|
|
|
return result;
|
2016-11-24 08:11:29 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|