mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1057212 - Avoid copying all the tiles when doing PushGroupAndCopyBackground. r=Bas
This commit is contained in:
parent
f2fcefda71
commit
2999f08ed4
@ -45,52 +45,6 @@ DrawTargetTiled::Init(const TileSet& aTiles)
|
||||
return true;
|
||||
}
|
||||
|
||||
class SnapshotTiled : public SourceSurface
|
||||
{
|
||||
public:
|
||||
SnapshotTiled(const vector<TileInternal>& aTiles, const IntRect& aRect)
|
||||
: mRect(aRect)
|
||||
{
|
||||
for (size_t i = 0; i < aTiles.size(); i++) {
|
||||
mSnapshots.push_back(aTiles[i].mDrawTarget->Snapshot());
|
||||
mOrigins.push_back(aTiles[i].mTileOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
virtual SurfaceType GetType() const { return SurfaceType::TILED; }
|
||||
virtual IntSize GetSize() const { return IntSize(mRect.XMost(), mRect.YMost()); }
|
||||
virtual SurfaceFormat GetFormat() const { return mSnapshots[0]->GetFormat(); }
|
||||
|
||||
virtual TemporaryRef<DataSourceSurface> GetDataSurface()
|
||||
{
|
||||
RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurface(GetSize(), GetFormat());
|
||||
if (MOZ2D_WARN_IF(!surf)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DataSourceSurface::MappedSurface mappedSurf;
|
||||
surf->Map(DataSourceSurface::MapType::WRITE, &mappedSurf);
|
||||
|
||||
{
|
||||
RefPtr<DrawTarget> dt =
|
||||
Factory::CreateDrawTargetForData(BackendType::CAIRO, mappedSurf.mData,
|
||||
GetSize(), mappedSurf.mStride, GetFormat());
|
||||
|
||||
for (size_t i = 0; i < mSnapshots.size(); i++) {
|
||||
RefPtr<DataSourceSurface> dataSurf = mSnapshots[i]->GetDataSurface();
|
||||
dt->CopySurface(dataSurf, IntRect(IntPoint(0, 0), mSnapshots[i]->GetSize()), mOrigins[i]);
|
||||
}
|
||||
}
|
||||
surf->Unmap();
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
private:
|
||||
vector<RefPtr<SourceSurface>> mSnapshots;
|
||||
vector<IntPoint> mOrigins;
|
||||
IntRect mRect;
|
||||
};
|
||||
|
||||
TemporaryRef<SourceSurface>
|
||||
DrawTargetTiled::Snapshot()
|
||||
{
|
||||
|
@ -149,6 +149,49 @@ private:
|
||||
IntRect mRect;
|
||||
};
|
||||
|
||||
class SnapshotTiled : public SourceSurface
|
||||
{
|
||||
public:
|
||||
SnapshotTiled(const std::vector<TileInternal>& aTiles, const IntRect& aRect)
|
||||
: mRect(aRect)
|
||||
{
|
||||
for (size_t i = 0; i < aTiles.size(); i++) {
|
||||
mSnapshots.push_back(aTiles[i].mDrawTarget->Snapshot());
|
||||
mOrigins.push_back(aTiles[i].mTileOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
virtual SurfaceType GetType() const { return SurfaceType::TILED; }
|
||||
virtual IntSize GetSize() const { return IntSize(mRect.XMost(), mRect.YMost()); }
|
||||
virtual SurfaceFormat GetFormat() const { return mSnapshots[0]->GetFormat(); }
|
||||
|
||||
virtual TemporaryRef<DataSourceSurface> GetDataSurface()
|
||||
{
|
||||
RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurface(GetSize(), GetFormat());
|
||||
|
||||
DataSourceSurface::MappedSurface mappedSurf;
|
||||
surf->Map(DataSourceSurface::MapType::WRITE, &mappedSurf);
|
||||
|
||||
{
|
||||
RefPtr<DrawTarget> dt =
|
||||
Factory::CreateDrawTargetForData(BackendType::CAIRO, mappedSurf.mData,
|
||||
GetSize(), mappedSurf.mStride, GetFormat());
|
||||
|
||||
for (size_t i = 0; i < mSnapshots.size(); i++) {
|
||||
RefPtr<DataSourceSurface> dataSurf = mSnapshots[i]->GetDataSurface();
|
||||
dt->CopySurface(dataSurf, IntRect(IntPoint(0, 0), mSnapshots[i]->GetSize()), mOrigins[i]);
|
||||
}
|
||||
}
|
||||
surf->Unmap();
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
|
||||
std::vector<RefPtr<SourceSurface>> mSnapshots;
|
||||
std::vector<IntPoint> mOrigins;
|
||||
IntRect mRect;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ EXPORTS.mozilla.gfx += [
|
||||
'BorrowedContext.h',
|
||||
'Coord.h',
|
||||
'DataSurfaceHelpers.h',
|
||||
'DrawTargetTiled.h',
|
||||
'Filters.h',
|
||||
'Helpers.h',
|
||||
'Logging.h',
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "GeckoProfiler.h"
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "mozilla/gfx/DrawTargetTiled.h"
|
||||
#include <algorithm>
|
||||
|
||||
#if CAIRO_HAS_DWRITE_FONT
|
||||
@ -1118,12 +1119,32 @@ gfxContext::PushGroupAndCopyBackground(gfxContentType content)
|
||||
|
||||
Point offset = CurrentState().deviceOffset - oldDeviceOffset;
|
||||
Rect surfRect(0, 0, Float(mDT->GetSize().width), Float(mDT->GetSize().height));
|
||||
Rect sourceRect = surfRect;
|
||||
sourceRect.x += offset.x;
|
||||
sourceRect.y += offset.y;
|
||||
Rect sourceRect = surfRect + offset;
|
||||
|
||||
mDT->SetTransform(Matrix());
|
||||
|
||||
// XXX: It's really sad that we have to do this (for performance).
|
||||
// Once DrawTarget gets a PushLayer API we can implement this within
|
||||
// DrawTargetTiled.
|
||||
if (source->GetType() == SurfaceType::TILED) {
|
||||
SnapshotTiled *sourceTiled = static_cast<SnapshotTiled*>(source.get());
|
||||
for (uint32_t i = 0; i < sourceTiled->mSnapshots.size(); i++) {
|
||||
Rect tileSourceRect = sourceRect.Intersect(Rect(sourceTiled->mOrigins[i].x,
|
||||
sourceTiled->mOrigins[i].y,
|
||||
sourceTiled->mSnapshots[i]->GetSize().width,
|
||||
sourceTiled->mSnapshots[i]->GetSize().height));
|
||||
|
||||
if (tileSourceRect.IsEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Rect tileDestRect = tileSourceRect - offset;
|
||||
tileSourceRect -= sourceTiled->mOrigins[i];
|
||||
|
||||
mDT->DrawSurface(sourceTiled->mSnapshots[i], tileDestRect, tileSourceRect);
|
||||
}
|
||||
} else {
|
||||
mDT->DrawSurface(source, surfRect, sourceRect);
|
||||
}
|
||||
mDT->SetOpaqueRect(oldDT->GetOpaqueRect());
|
||||
|
||||
PushClipsToDT(mDT);
|
||||
|
Loading…
Reference in New Issue
Block a user