Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1480608. Skip over items that aren't in DrawTarget/DirtyRect. r=m…
Browse files Browse the repository at this point in the history
…stange

MozReview-Commit-ID: Kc9E1SUVUh3
  • Loading branch information
jrmuizel committed Aug 2, 2018
1 parent f388bf1 commit af1cafd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions gfx/2d/RectAbsolute.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ struct BaseRectAbsolute {
return result;
}

bool IsEmpty() const {
return right <= left || bottom <= top;
}

bool IsEqualEdges(const Sub& aOther) const
{
return left == aOther.left && top == aOther.top &&
Expand Down
26 changes: 22 additions & 4 deletions gfx/webrender_bindings/Moz2DImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mozilla/Mutex.h"
#include "mozilla/Range.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/RectAbsolute.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/RecordedEvent.h"
#include "mozilla/layers/WebRenderDrawEventRecorder.h"
Expand Down Expand Up @@ -261,9 +262,15 @@ static bool Moz2DRenderCallback(const Range<const uint8_t> aBlob,
dt = gfx::Factory::CreateOffsetDrawTarget(dt, origin);
}

auto bounds = gfx::IntRect(origin, aSize);

if (aDirtyRect) {
Rect dirty(aDirtyRect->origin.x, aDirtyRect->origin.y, aDirtyRect->size.width, aDirtyRect->size.height);
dt->PushClipRect(dirty);
bounds = bounds.Intersect(IntRect(aDirtyRect->origin.x,
aDirtyRect->origin.y,
aDirtyRect->size.width,
aDirtyRect->size.height));
}

struct Reader {
Expand All @@ -288,9 +295,15 @@ static bool Moz2DRenderCallback(const Range<const uint8_t> aBlob,
return ret;
}

void SkipBounds() {
MOZ_RELEASE_ASSERT(pos + sizeof(int) * 4 <= len);
pos += sizeof(int) * 4;
IntRectAbsolute ReadBounds() {
MOZ_RELEASE_ASSERT(pos + sizeof(int32_t) * 4 <= len);
int32_t x1, y1, x2, y2;
memcpy(&x1, buf + pos + 0 * sizeof(int32_t), sizeof(x1));
memcpy(&y1, buf + pos + 1 * sizeof(int32_t), sizeof(y1));
memcpy(&x2, buf + pos + 2 * sizeof(int32_t), sizeof(x2));
memcpy(&y2, buf + pos + 3 * sizeof(int32_t), sizeof(y2));
pos += sizeof(int32_t) * 4;
return IntRectAbsolute(x1, y1, x2, y2);
}

};
Expand All @@ -300,10 +313,15 @@ static bool Moz2DRenderCallback(const Range<const uint8_t> aBlob,

bool ret;
size_t offset = 0;
auto absBounds = IntRectAbsolute::FromRect(bounds);
while (reader.pos < reader.len) {
size_t end = reader.ReadSize();
size_t extra_end = reader.ReadSize();
reader.SkipBounds();
auto combinedBounds = absBounds.Intersect(reader.ReadBounds());
if (combinedBounds.IsEmpty()) {
offset = extra_end;
continue;
}

layers::WebRenderTranslator translator(dt);

Expand Down

0 comments on commit af1cafd

Please sign in to comment.