2012-04-16 16:02:45 -07:00
|
|
|
/* 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 "mozilla/layers/PLayersChild.h"
|
2013-02-15 19:55:36 -08:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2012-04-16 16:02:45 -07:00
|
|
|
#include "BasicTiledThebesLayer.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "gfxPlatform.h"
|
2012-04-16 16:02:45 -07:00
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
|
|
|
|
#include "cairo.h"
|
|
|
|
#include <sstream>
|
|
|
|
using mozilla::layers::Layer;
|
|
|
|
static void DrawDebugOverlay(gfxImageSurface* imgSurf, int x, int y)
|
|
|
|
{
|
|
|
|
gfxContext c(imgSurf);
|
|
|
|
|
|
|
|
// Draw border
|
|
|
|
c.NewPath();
|
|
|
|
c.SetDeviceColor(gfxRGBA(0.0, 0.0, 0.0, 1.0));
|
|
|
|
c.Rectangle(gfxRect(gfxPoint(0,0),imgSurf->GetSize()));
|
|
|
|
c.Stroke();
|
|
|
|
|
|
|
|
// Build tile description
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << x << ", " << y;
|
|
|
|
|
|
|
|
// Draw text using cairo toy text API
|
|
|
|
cairo_t* cr = c.GetCairo();
|
2012-10-03 07:56:41 -07:00
|
|
|
cairo_set_font_size(cr, 25);
|
2012-04-16 16:02:45 -07:00
|
|
|
cairo_text_extents_t extents;
|
|
|
|
cairo_text_extents(cr, ss.str().c_str(), &extents);
|
|
|
|
|
|
|
|
int textWidth = extents.width + 6;
|
|
|
|
|
|
|
|
c.NewPath();
|
|
|
|
c.SetDeviceColor(gfxRGBA(0.0, 0.0, 0.0, 1.0));
|
2012-10-03 07:56:41 -07:00
|
|
|
c.Rectangle(gfxRect(gfxPoint(2,2),gfxSize(textWidth, 30)));
|
2012-04-16 16:02:45 -07:00
|
|
|
c.Fill();
|
|
|
|
|
|
|
|
c.NewPath();
|
|
|
|
c.SetDeviceColor(gfxRGBA(1.0, 0.0, 0.0, 1.0));
|
2012-10-03 07:56:41 -07:00
|
|
|
c.Rectangle(gfxRect(gfxPoint(2,2),gfxSize(textWidth, 30)));
|
2012-04-16 16:02:45 -07:00
|
|
|
c.Stroke();
|
|
|
|
|
|
|
|
c.NewPath();
|
2012-10-03 07:56:41 -07:00
|
|
|
cairo_move_to(cr, 4, 28);
|
2012-04-16 16:02:45 -07:00
|
|
|
cairo_show_text(cr, ss.str().c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-09-04 15:05:31 -07:00
|
|
|
bool
|
|
|
|
BasicTiledLayerBuffer::HasFormatChanged(BasicTiledThebesLayer* aThebesLayer) const
|
|
|
|
{
|
|
|
|
return aThebesLayer->CanUseOpaqueSurface() != mLastPaintOpaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 16:04:24 -07:00
|
|
|
gfxASurface::gfxImageFormat
|
|
|
|
BasicTiledLayerBuffer::GetFormat() const
|
|
|
|
{
|
|
|
|
if (mThebesLayer->CanUseOpaqueSurface()) {
|
|
|
|
return gfxASurface::ImageFormatRGB16_565;
|
|
|
|
} else {
|
|
|
|
return gfxASurface::ImageFormatARGB32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
void
|
|
|
|
BasicTiledLayerBuffer::PaintThebes(BasicTiledThebesLayer* aLayer,
|
|
|
|
const nsIntRegion& aNewValidRegion,
|
|
|
|
const nsIntRegion& aPaintRegion,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2012-03-18 16:02:38 -07:00
|
|
|
void* aCallbackData)
|
2012-04-16 16:02:45 -07:00
|
|
|
{
|
|
|
|
mThebesLayer = aLayer;
|
|
|
|
mCallback = aCallback;
|
|
|
|
mCallbackData = aCallbackData;
|
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
long start = PR_IntervalNow();
|
|
|
|
#endif
|
2012-10-03 07:28:04 -07:00
|
|
|
|
|
|
|
// If this region is empty XMost() - 1 will give us a negative value.
|
|
|
|
NS_ASSERTION(!aPaintRegion.GetBounds().IsEmpty(), "Empty paint region\n");
|
|
|
|
|
|
|
|
bool useSinglePaintBuffer = UseSinglePaintBuffer();
|
2013-03-13 11:31:01 -07:00
|
|
|
// XXX The single-tile case doesn't work at the moment, see bug 850396
|
|
|
|
/*
|
2012-10-03 07:28:04 -07:00
|
|
|
if (useSinglePaintBuffer) {
|
|
|
|
// Check if the paint only spans a single tile. If that's
|
|
|
|
// the case there's no point in using a single paint buffer.
|
|
|
|
nsIntRect paintBounds = aPaintRegion.GetBounds();
|
2012-11-05 22:35:59 -08:00
|
|
|
useSinglePaintBuffer = GetTileStart(paintBounds.x) !=
|
|
|
|
GetTileStart(paintBounds.XMost() - 1) ||
|
|
|
|
GetTileStart(paintBounds.y) !=
|
|
|
|
GetTileStart(paintBounds.YMost() - 1);
|
2012-10-03 07:28:04 -07:00
|
|
|
}
|
2013-03-13 11:31:01 -07:00
|
|
|
*/
|
2012-10-03 07:28:04 -07:00
|
|
|
|
|
|
|
if (useSinglePaintBuffer) {
|
2012-04-16 16:02:45 -07:00
|
|
|
const nsIntRect bounds = aPaintRegion.GetBounds();
|
2012-04-18 17:40:08 -07:00
|
|
|
{
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("BasicTiledLayerBuffer", "PaintThebesSingleBufferAlloc");
|
2012-11-21 14:34:18 -08:00
|
|
|
mSinglePaintBuffer = new gfxImageSurface(
|
|
|
|
gfxIntSize(ceilf(bounds.width * mResolution),
|
|
|
|
ceilf(bounds.height * mResolution)),
|
|
|
|
GetFormat(), !aLayer->CanUseOpaqueSurface());
|
2012-04-18 17:40:08 -07:00
|
|
|
mSinglePaintBufferOffset = nsIntPoint(bounds.x, bounds.y);
|
|
|
|
}
|
2012-04-16 16:02:45 -07:00
|
|
|
nsRefPtr<gfxContext> ctxt = new gfxContext(mSinglePaintBuffer);
|
|
|
|
ctxt->NewPath();
|
2012-11-21 14:34:18 -08:00
|
|
|
ctxt->Scale(mResolution, mResolution);
|
2012-04-16 16:02:45 -07:00
|
|
|
ctxt->Translate(gfxPoint(-bounds.x, -bounds.y));
|
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
if (PR_IntervalNow() - start > 3) {
|
|
|
|
printf_stderr("Slow alloc %i\n", PR_IntervalNow() - start);
|
|
|
|
}
|
|
|
|
start = PR_IntervalNow();
|
|
|
|
#endif
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("BasicTiledLayerBuffer", "PaintThebesSingleBufferDraw");
|
2012-02-07 14:27:21 -08:00
|
|
|
|
2012-05-15 13:34:06 -07:00
|
|
|
mCallback(mThebesLayer, ctxt, aPaintRegion, nsIntRegion(), mCallbackData);
|
2012-04-16 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
if (PR_IntervalNow() - start > 30) {
|
|
|
|
const nsIntRect bounds = aPaintRegion.GetBounds();
|
|
|
|
printf_stderr("Time to draw %i: %i, %i, %i, %i\n", PR_IntervalNow() - start, bounds.x, bounds.y, bounds.width, bounds.height);
|
|
|
|
if (aPaintRegion.IsComplex()) {
|
|
|
|
printf_stderr("Complex region\n");
|
|
|
|
nsIntRegionRectIterator it(aPaintRegion);
|
2012-07-30 07:20:58 -07:00
|
|
|
for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
|
2012-04-16 16:02:45 -07:00
|
|
|
printf_stderr(" rect %i, %i, %i, %i\n", rect->x, rect->y, rect->width, rect->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
start = PR_IntervalNow();
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("BasicTiledLayerBuffer", "PaintThebesUpdate");
|
2012-04-16 16:02:45 -07:00
|
|
|
Update(aNewValidRegion, aPaintRegion);
|
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
if (PR_IntervalNow() - start > 10) {
|
|
|
|
const nsIntRect bounds = aPaintRegion.GetBounds();
|
|
|
|
printf_stderr("Time to tile %i: %i, %i, %i, %i\n", PR_IntervalNow() - start, bounds.x, bounds.y, bounds.width, bounds.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-04 15:05:31 -07:00
|
|
|
mLastPaintOpaque = mThebesLayer->CanUseOpaqueSurface();
|
2012-07-30 07:20:58 -07:00
|
|
|
mThebesLayer = nullptr;
|
|
|
|
mCallback = nullptr;
|
|
|
|
mCallbackData = nullptr;
|
|
|
|
mSinglePaintBuffer = nullptr;
|
2012-04-16 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicTiledLayerTile
|
|
|
|
BasicTiledLayerBuffer::ValidateTileInternal(BasicTiledLayerTile aTile,
|
|
|
|
const nsIntPoint& aTileOrigin,
|
|
|
|
const nsIntRect& aDirtyRect)
|
|
|
|
{
|
2012-08-30 12:35:36 -07:00
|
|
|
if (aTile == GetPlaceholderTile() || aTile.mSurface->Format() != GetFormat()) {
|
2012-04-16 16:04:24 -07:00
|
|
|
gfxImageSurface* tmpTile = new gfxImageSurface(gfxIntSize(GetTileLength(), GetTileLength()),
|
2012-04-18 17:40:08 -07:00
|
|
|
GetFormat(), !mThebesLayer->CanUseOpaqueSurface());
|
2012-04-16 16:02:45 -07:00
|
|
|
aTile = BasicTiledLayerTile(tmpTile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the gfxReusableSurfaceWrapper, which will reuse the surface
|
|
|
|
// if the compositor no longer has a read lock, otherwise the surface
|
|
|
|
// will be copied into a new writable surface.
|
|
|
|
gfxImageSurface* writableSurface;
|
|
|
|
aTile.mSurface = aTile.mSurface->GetWritable(&writableSurface);
|
|
|
|
|
|
|
|
// Bug 742100, this gfxContext really should live on the stack.
|
|
|
|
nsRefPtr<gfxContext> ctxt = new gfxContext(writableSurface);
|
2012-11-21 14:34:18 -08:00
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
if (mSinglePaintBuffer) {
|
2012-11-21 14:34:18 -08:00
|
|
|
gfxRect drawRect(aDirtyRect.x - aTileOrigin.x, aDirtyRect.y - aTileOrigin.y,
|
|
|
|
aDirtyRect.width, aDirtyRect.height);
|
|
|
|
|
2012-10-03 07:28:04 -07:00
|
|
|
ctxt->SetOperator(gfxContext::OPERATOR_SOURCE);
|
2012-04-16 16:02:45 -07:00
|
|
|
ctxt->NewPath();
|
|
|
|
ctxt->SetSource(mSinglePaintBuffer.get(),
|
2012-11-21 14:34:18 -08:00
|
|
|
gfxPoint((mSinglePaintBufferOffset.x - aDirtyRect.x + drawRect.x) *
|
|
|
|
mResolution,
|
|
|
|
(mSinglePaintBufferOffset.y - aDirtyRect.y + drawRect.y) *
|
|
|
|
mResolution));
|
|
|
|
drawRect.Scale(mResolution, mResolution);
|
2012-04-16 16:02:45 -07:00
|
|
|
ctxt->Rectangle(drawRect, true);
|
|
|
|
ctxt->Fill();
|
|
|
|
} else {
|
|
|
|
ctxt->NewPath();
|
2012-11-21 14:34:18 -08:00
|
|
|
ctxt->Scale(mResolution, mResolution);
|
2012-04-16 16:02:45 -07:00
|
|
|
ctxt->Translate(gfxPoint(-aTileOrigin.x, -aTileOrigin.y));
|
2012-11-21 14:34:18 -08:00
|
|
|
nsIntPoint a = nsIntPoint(aTileOrigin.x, aTileOrigin.y);
|
|
|
|
mCallback(mThebesLayer, ctxt,
|
|
|
|
nsIntRegion(nsIntRect(a, nsIntSize(GetScaledTileLength(),
|
|
|
|
GetScaledTileLength()))),
|
|
|
|
nsIntRegion(), mCallbackData);
|
2012-04-16 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
|
2012-11-21 14:34:18 -08:00
|
|
|
DrawDebugOverlay(writableSurface, aTileOrigin.x * mResolution,
|
|
|
|
aTileOrigin.y * mResolution);
|
2012-04-16 16:02:45 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return aTile;
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicTiledLayerTile
|
|
|
|
BasicTiledLayerBuffer::ValidateTile(BasicTiledLayerTile aTile,
|
|
|
|
const nsIntPoint& aTileOrigin,
|
|
|
|
const nsIntRegion& aDirtyRegion)
|
|
|
|
{
|
|
|
|
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("BasicTiledLayerBuffer", "ValidateTile");
|
2012-04-16 16:02:45 -07:00
|
|
|
|
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
if (aDirtyRegion.IsComplex()) {
|
|
|
|
printf_stderr("Complex region\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIntRegionRectIterator it(aDirtyRegion);
|
2012-07-30 07:20:58 -07:00
|
|
|
for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) {
|
2012-04-16 16:02:45 -07:00
|
|
|
#ifdef GFX_TILEDLAYER_PREF_WARNINGS
|
|
|
|
printf_stderr(" break into subrect %i, %i, %i, %i\n", rect->x, rect->y, rect->width, rect->height);
|
|
|
|
#endif
|
|
|
|
aTile = ValidateTileInternal(aTile, aTileOrigin, *rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aTile;
|
|
|
|
}
|
|
|
|
|
2012-12-05 09:10:41 -08:00
|
|
|
BasicTiledThebesLayer::BasicTiledThebesLayer(BasicShadowLayerManager* const aManager)
|
|
|
|
: ThebesLayer(aManager, static_cast<BasicImplData*>(this))
|
|
|
|
, mLastScrollOffset(0, 0)
|
|
|
|
, mFirstPaint(true)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicTiledThebesLayer);
|
|
|
|
mLowPrecisionTiledBuffer.SetResolution(gfxPlatform::GetLowPrecisionResolution());
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicTiledThebesLayer::~BasicTiledThebesLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicTiledThebesLayer);
|
|
|
|
}
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
void
|
|
|
|
BasicTiledThebesLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = ThebesLayerAttributes(GetValidRegion());
|
|
|
|
}
|
|
|
|
|
2012-10-22 12:18:14 -07:00
|
|
|
static nsIntRect
|
|
|
|
RoundedTransformViewportBounds(const gfx::Rect& aViewport,
|
|
|
|
const gfx::Point& aScrollOffset,
|
2013-03-04 06:37:43 -08:00
|
|
|
const gfxSize& aResolution,
|
2012-10-22 12:18:14 -07:00
|
|
|
float aScaleX,
|
|
|
|
float aScaleY,
|
|
|
|
const gfx3DMatrix& aTransform)
|
|
|
|
{
|
|
|
|
gfxRect transformedViewport(aViewport.x - (aScrollOffset.x * aResolution.width),
|
|
|
|
aViewport.y - (aScrollOffset.y * aResolution.height),
|
|
|
|
aViewport.width, aViewport.height);
|
|
|
|
transformedViewport.Scale((aScaleX / aResolution.width) / aResolution.width,
|
|
|
|
(aScaleY / aResolution.height) / aResolution.height);
|
|
|
|
transformedViewport = aTransform.TransformBounds(transformedViewport);
|
|
|
|
|
|
|
|
return nsIntRect((int32_t)floor(transformedViewport.x),
|
|
|
|
(int32_t)floor(transformedViewport.y),
|
|
|
|
(int32_t)ceil(transformedViewport.width),
|
|
|
|
(int32_t)ceil(transformedViewport.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-11-21 14:34:19 -08:00
|
|
|
BasicTiledThebesLayer::ComputeProgressiveUpdateRegion(BasicTiledLayerBuffer& aTiledBuffer,
|
|
|
|
const nsIntRegion& aInvalidRegion,
|
2012-10-22 12:18:14 -07:00
|
|
|
const nsIntRegion& aOldValidRegion,
|
|
|
|
nsIntRegion& aRegionToPaint,
|
|
|
|
const gfx3DMatrix& aTransform,
|
2012-11-21 14:34:19 -08:00
|
|
|
const nsIntRect& aCompositionBounds,
|
2012-10-22 12:18:14 -07:00
|
|
|
const gfx::Point& aScrollOffset,
|
2013-03-04 06:37:43 -08:00
|
|
|
const gfxSize& aResolution,
|
2012-10-22 12:18:14 -07:00
|
|
|
bool aIsRepeated)
|
|
|
|
{
|
|
|
|
aRegionToPaint = aInvalidRegion;
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// If this is a low precision buffer, we force progressive updates. The
|
|
|
|
// assumption is that the contents is less important, so visual coherency
|
|
|
|
// is lower priority than speed.
|
2012-11-21 14:34:19 -08:00
|
|
|
bool drawingLowPrecision = aTiledBuffer.IsLowPrecision();
|
2012-11-21 14:34:19 -08:00
|
|
|
|
2012-10-22 12:18:14 -07:00
|
|
|
// Find out if we have any non-stale content to update.
|
2012-11-21 14:34:19 -08:00
|
|
|
nsIntRegion staleRegion;
|
|
|
|
staleRegion.And(aInvalidRegion, aOldValidRegion);
|
2012-10-22 12:18:14 -07:00
|
|
|
|
|
|
|
// Find out the current view transform to determine which tiles to draw
|
|
|
|
// first, and see if we should just abort this paint. Aborting is usually
|
|
|
|
// caused by there being an incoming, more relevant paint.
|
|
|
|
gfx::Rect viewport;
|
|
|
|
float scaleX, scaleY;
|
2012-11-21 14:34:19 -08:00
|
|
|
if (BasicManager()->ProgressiveUpdateCallback(!staleRegion.Contains(aInvalidRegion),
|
|
|
|
viewport,
|
2012-11-21 14:34:19 -08:00
|
|
|
scaleX, scaleY, !drawingLowPrecision)) {
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_MARKER("Abort painting");
|
2012-10-22 12:18:14 -07:00
|
|
|
aRegionToPaint.SetEmpty();
|
|
|
|
return aIsRepeated;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transform the screen coordinates into local layer coordinates.
|
|
|
|
nsIntRect roundedTransformedViewport =
|
|
|
|
RoundedTransformViewportBounds(viewport, aScrollOffset, aResolution,
|
|
|
|
scaleX, scaleY, aTransform);
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// Paint tiles that have stale content or that intersected with the screen
|
|
|
|
// at the time of issuing the draw command in a single transaction first.
|
|
|
|
// This is to avoid rendering glitches on animated page content, and when
|
|
|
|
// layers change size/shape.
|
|
|
|
nsIntRect criticalViewportRect = roundedTransformedViewport.Intersect(aCompositionBounds);
|
|
|
|
aRegionToPaint.And(aInvalidRegion, criticalViewportRect);
|
|
|
|
aRegionToPaint.Or(aRegionToPaint, staleRegion);
|
|
|
|
bool drawingStale = !aRegionToPaint.IsEmpty();
|
2012-10-22 12:18:14 -07:00
|
|
|
if (!drawingStale) {
|
2012-11-21 14:34:19 -08:00
|
|
|
aRegionToPaint = aInvalidRegion;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prioritise tiles that are currently visible on the screen.
|
|
|
|
bool paintVisible = false;
|
|
|
|
if (aRegionToPaint.Intersects(roundedTransformedViewport)) {
|
|
|
|
aRegionToPaint.And(aRegionToPaint, roundedTransformedViewport);
|
|
|
|
paintVisible = true;
|
|
|
|
}
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// Paint area that's visible and overlaps previously valid content to avoid
|
|
|
|
// visible glitches in animated elements, such as gifs.
|
|
|
|
bool paintInSingleTransaction = paintVisible && (drawingStale || mFirstPaint);
|
|
|
|
|
2012-10-22 12:18:14 -07:00
|
|
|
// The following code decides what order to draw tiles in, based on the
|
|
|
|
// current scroll direction of the primary scrollable layer.
|
|
|
|
NS_ASSERTION(!aRegionToPaint.IsEmpty(), "Unexpectedly empty paint region!");
|
|
|
|
nsIntRect paintBounds = aRegionToPaint.GetBounds();
|
|
|
|
|
|
|
|
int startX, incX, startY, incY;
|
2012-11-21 14:34:19 -08:00
|
|
|
int tileLength = aTiledBuffer.GetScaledTileLength();
|
2012-10-22 12:18:14 -07:00
|
|
|
if (aScrollOffset.x >= mLastScrollOffset.x) {
|
2012-11-21 14:34:19 -08:00
|
|
|
startX = aTiledBuffer.RoundDownToTileEdge(paintBounds.x);
|
2012-11-21 14:34:18 -08:00
|
|
|
incX = tileLength;
|
2012-10-22 12:18:14 -07:00
|
|
|
} else {
|
2012-11-21 14:34:19 -08:00
|
|
|
startX = aTiledBuffer.RoundDownToTileEdge(paintBounds.XMost() - 1);
|
2012-11-21 14:34:18 -08:00
|
|
|
incX = -tileLength;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aScrollOffset.y >= mLastScrollOffset.y) {
|
2012-11-21 14:34:19 -08:00
|
|
|
startY = aTiledBuffer.RoundDownToTileEdge(paintBounds.y);
|
2012-11-21 14:34:18 -08:00
|
|
|
incY = tileLength;
|
2012-10-22 12:18:14 -07:00
|
|
|
} else {
|
2012-11-21 14:34:19 -08:00
|
|
|
startY = aTiledBuffer.RoundDownToTileEdge(paintBounds.YMost() - 1);
|
2012-11-21 14:34:18 -08:00
|
|
|
incY = -tileLength;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find a tile to draw.
|
2012-11-21 14:34:18 -08:00
|
|
|
nsIntRect tileBounds(startX, startY, tileLength, tileLength);
|
2012-10-22 12:18:14 -07:00
|
|
|
int32_t scrollDiffX = aScrollOffset.x - mLastScrollOffset.x;
|
|
|
|
int32_t scrollDiffY = aScrollOffset.y - mLastScrollOffset.y;
|
|
|
|
// This loop will always terminate, as there is at least one tile area
|
|
|
|
// along the first/last row/column intersecting with regionToPaint, or its
|
|
|
|
// bounds would have been smaller.
|
|
|
|
while (true) {
|
|
|
|
aRegionToPaint.And(aInvalidRegion, tileBounds);
|
|
|
|
if (!aRegionToPaint.IsEmpty()) {
|
|
|
|
break;
|
|
|
|
}
|
2013-03-05 15:43:53 -08:00
|
|
|
if (Abs(scrollDiffY) >= Abs(scrollDiffX)) {
|
2012-10-22 12:18:14 -07:00
|
|
|
tileBounds.x += incX;
|
|
|
|
} else {
|
|
|
|
tileBounds.y += incY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aRegionToPaint.Contains(aInvalidRegion)) {
|
|
|
|
// The region needed to paint is larger then our progressive chunk size
|
|
|
|
// therefore update what we want to paint and ask for a new paint transaction.
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// If we need to draw more than one tile to maintain coherency, make
|
|
|
|
// sure it happens in the same transaction by requesting this work be
|
|
|
|
// repeated immediately.
|
|
|
|
// If this is unnecessary, the remaining work will be done tile-by-tile in
|
|
|
|
// subsequent transactions.
|
|
|
|
if (!drawingLowPrecision && paintInSingleTransaction) {
|
2012-11-29 05:08:40 -08:00
|
|
|
return true;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
2012-11-29 05:08:40 -08:00
|
|
|
|
|
|
|
BasicManager()->SetRepeatTransaction();
|
|
|
|
return false;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
// We're not repeating painting and we've not requested a repeat transaction,
|
|
|
|
// so the paint is finished. If there's still a separate low precision
|
|
|
|
// paint to do, it will get marked as unfinished later.
|
|
|
|
mPaintData.mPaintFinished = true;
|
|
|
|
return false;
|
2012-10-22 12:18:14 -07:00
|
|
|
}
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
bool
|
|
|
|
BasicTiledThebesLayer::ProgressiveUpdate(BasicTiledLayerBuffer& aTiledBuffer,
|
|
|
|
nsIntRegion& aValidRegion,
|
|
|
|
nsIntRegion& aInvalidRegion,
|
|
|
|
const nsIntRegion& aOldValidRegion,
|
|
|
|
const gfx3DMatrix& aTransform,
|
2012-11-21 14:34:19 -08:00
|
|
|
const nsIntRect& aCompositionBounds,
|
2012-11-21 14:34:19 -08:00
|
|
|
const gfx::Point& aScrollOffset,
|
2013-03-04 06:37:43 -08:00
|
|
|
const gfxSize& aResolution,
|
2012-11-21 14:34:19 -08:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
|
|
|
bool repeat = false;
|
2013-03-07 07:02:06 -08:00
|
|
|
bool isBufferChanged = false;
|
2012-11-21 14:34:19 -08:00
|
|
|
do {
|
|
|
|
// Compute the region that should be updated. Repeat as many times as
|
|
|
|
// is required.
|
|
|
|
nsIntRegion regionToPaint;
|
|
|
|
repeat = ComputeProgressiveUpdateRegion(aTiledBuffer,
|
|
|
|
aInvalidRegion,
|
|
|
|
aOldValidRegion,
|
|
|
|
regionToPaint,
|
|
|
|
aTransform,
|
2012-11-21 14:34:19 -08:00
|
|
|
aCompositionBounds,
|
2012-11-21 14:34:19 -08:00
|
|
|
aScrollOffset,
|
|
|
|
aResolution,
|
|
|
|
repeat);
|
|
|
|
|
2013-03-07 07:02:06 -08:00
|
|
|
// There's no further work to be done.
|
2012-11-21 14:34:19 -08:00
|
|
|
if (regionToPaint.IsEmpty()) {
|
2013-03-07 07:02:06 -08:00
|
|
|
break;
|
2012-11-21 14:34:19 -08:00
|
|
|
}
|
|
|
|
|
2013-03-07 07:02:06 -08:00
|
|
|
isBufferChanged |= true;
|
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// Keep track of what we're about to refresh.
|
|
|
|
aValidRegion.Or(aValidRegion, regionToPaint);
|
|
|
|
|
|
|
|
// aValidRegion may have been altered by InvalidateRegion, but we still
|
|
|
|
// want to display stale content until it gets progressively updated.
|
|
|
|
// Create a region that includes stale content.
|
|
|
|
nsIntRegion validOrStale;
|
|
|
|
validOrStale.Or(aValidRegion, aOldValidRegion);
|
|
|
|
|
|
|
|
// Paint the computed region and subtract it from the invalid region.
|
|
|
|
aTiledBuffer.PaintThebes(this, validOrStale, regionToPaint, aCallback, aCallbackData);
|
|
|
|
aInvalidRegion.Sub(aInvalidRegion, regionToPaint);
|
|
|
|
} while (repeat);
|
|
|
|
|
2013-03-07 07:02:06 -08:00
|
|
|
// Return false if nothing has been drawn, or give what has been drawn
|
|
|
|
// to the shadow layer to upload.
|
|
|
|
return isBufferChanged;
|
2012-11-21 14:34:19 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
void
|
|
|
|
BasicTiledThebesLayer::BeginPaint()
|
|
|
|
{
|
|
|
|
if (BasicManager()->IsRepeatTransaction()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPaintData.mLowPrecisionPaintCount = 0;
|
|
|
|
mPaintData.mPaintFinished = false;
|
|
|
|
|
|
|
|
// Calculate the transform required to convert screen space into layer space
|
|
|
|
mPaintData.mTransformScreenToLayer = GetEffectiveTransform();
|
|
|
|
// XXX Not sure if this code for intermediate surfaces is correct.
|
|
|
|
// It rarely gets hit though, and shouldn't have terrible consequences
|
|
|
|
// even if it is wrong.
|
|
|
|
for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) {
|
|
|
|
if (parent->UseIntermediateSurface()) {
|
|
|
|
mPaintData.mTransformScreenToLayer.PreMultiply(parent->GetEffectiveTransform());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mPaintData.mTransformScreenToLayer.Invert();
|
|
|
|
|
|
|
|
// Compute the critical display port in layer space.
|
|
|
|
mPaintData.mLayerCriticalDisplayPort.SetEmpty();
|
2013-03-04 06:37:43 -08:00
|
|
|
const gfx::Rect& criticalDisplayPort = GetParent()->GetFrameMetrics().mCriticalDisplayPort;
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!criticalDisplayPort.IsEmpty()) {
|
|
|
|
gfxRect transformedCriticalDisplayPort =
|
2013-03-04 06:37:43 -08:00
|
|
|
mPaintData.mTransformScreenToLayer.TransformBounds(
|
|
|
|
gfxRect(criticalDisplayPort.x, criticalDisplayPort.y,
|
|
|
|
criticalDisplayPort.width, criticalDisplayPort.height));
|
2012-11-29 05:08:40 -08:00
|
|
|
transformedCriticalDisplayPort.RoundOut();
|
|
|
|
mPaintData.mLayerCriticalDisplayPort = nsIntRect(transformedCriticalDisplayPort.x,
|
|
|
|
transformedCriticalDisplayPort.y,
|
|
|
|
transformedCriticalDisplayPort.width,
|
|
|
|
transformedCriticalDisplayPort.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the frame resolution.
|
2013-03-04 06:37:43 -08:00
|
|
|
mPaintData.mResolution.SizeTo(1, 1);
|
2012-11-29 05:08:40 -08:00
|
|
|
for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) {
|
|
|
|
const FrameMetrics& metrics = parent->GetFrameMetrics();
|
|
|
|
mPaintData.mResolution.width *= metrics.mResolution.width;
|
|
|
|
mPaintData.mResolution.height *= metrics.mResolution.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the scroll offset since the last transaction, and the
|
|
|
|
// composition bounds.
|
|
|
|
mPaintData.mCompositionBounds.SetEmpty();
|
|
|
|
mPaintData.mScrollOffset.MoveTo(0, 0);
|
|
|
|
Layer* primaryScrollable = BasicManager()->GetPrimaryScrollableLayer();
|
|
|
|
if (primaryScrollable) {
|
|
|
|
const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
|
|
|
|
mPaintData.mScrollOffset = metrics.mScrollOffset;
|
|
|
|
gfxRect transformedViewport = mPaintData.mTransformScreenToLayer.TransformBounds(
|
|
|
|
gfxRect(metrics.mCompositionBounds.x, metrics.mCompositionBounds.y,
|
|
|
|
metrics.mCompositionBounds.width, metrics.mCompositionBounds.height));
|
|
|
|
transformedViewport.RoundOut();
|
|
|
|
mPaintData.mCompositionBounds =
|
|
|
|
nsIntRect(transformedViewport.x, transformedViewport.y,
|
|
|
|
transformedViewport.width, transformedViewport.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicTiledThebesLayer::EndPaint(bool aFinish)
|
|
|
|
{
|
|
|
|
if (!aFinish && !mPaintData.mPaintFinished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastScrollOffset = mPaintData.mScrollOffset;
|
|
|
|
mPaintData.mPaintFinished = true;
|
|
|
|
}
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
void
|
|
|
|
BasicTiledThebesLayer::PaintThebes(gfxContext* aContext,
|
2012-07-06 11:02:10 -07:00
|
|
|
Layer* aMaskLayer,
|
2012-04-16 16:02:45 -07:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback)
|
|
|
|
{
|
|
|
|
if (!aCallback) {
|
|
|
|
BasicManager()->SetTransactionIncomplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasShadow()) {
|
|
|
|
NS_ASSERTION(false, "Shadow requested for painting\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-04 15:05:31 -07:00
|
|
|
if (mTiledBuffer.HasFormatChanged(this)) {
|
|
|
|
mValidRegion = nsIntRegion();
|
|
|
|
}
|
|
|
|
|
2012-10-15 01:33:48 -07:00
|
|
|
nsIntRegion invalidRegion = mVisibleRegion;
|
|
|
|
invalidRegion.Sub(invalidRegion, mValidRegion);
|
2012-11-29 05:08:40 -08:00
|
|
|
if (invalidRegion.IsEmpty()) {
|
|
|
|
EndPaint(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fast path for no progressive updates, no low-precision updates and no
|
|
|
|
// critical display-port set.
|
|
|
|
if (!gfxPlatform::UseProgressiveTilePainting() &&
|
|
|
|
!gfxPlatform::UseLowPrecisionBuffer() &&
|
|
|
|
GetParent()->GetFrameMetrics().mCriticalDisplayPort.IsEmpty()) {
|
|
|
|
mValidRegion = mVisibleRegion;
|
|
|
|
mTiledBuffer.PaintThebes(this, mValidRegion, invalidRegion, aCallback, aCallbackData);
|
|
|
|
mTiledBuffer.ReadLock();
|
|
|
|
|
2012-12-04 07:24:24 -08:00
|
|
|
if (aMaskLayer) {
|
|
|
|
static_cast<BasicImplData*>(aMaskLayer->ImplData())->Paint(aContext, nullptr);
|
|
|
|
}
|
2012-11-29 05:08:40 -08:00
|
|
|
|
|
|
|
// Create a heap copy owned and released by the compositor. This is needed
|
|
|
|
// since we're sending this over an async message and content needs to be
|
|
|
|
// be able to modify the tiled buffer in the next transaction.
|
|
|
|
// TODO: Remove me once Bug 747811 lands.
|
|
|
|
BasicTiledLayerBuffer *heapCopy = new BasicTiledLayerBuffer(mTiledBuffer);
|
|
|
|
BasicManager()->PaintedTiledLayerBuffer(BasicManager()->Hold(this), heapCopy);
|
|
|
|
mTiledBuffer.ClearPaintedRegion();
|
|
|
|
|
2012-04-16 16:02:45 -07:00
|
|
|
return;
|
2012-11-29 05:08:40 -08:00
|
|
|
}
|
2012-04-16 16:02:45 -07:00
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
// Calculate everything we need to perform the paint.
|
|
|
|
BeginPaint();
|
|
|
|
if (mPaintData.mPaintFinished) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that tiles that fall outside of the visible region are
|
|
|
|
// discarded on the first update.
|
|
|
|
if (!BasicManager()->IsRepeatTransaction()) {
|
|
|
|
mValidRegion.And(mValidRegion, mVisibleRegion);
|
2012-11-21 14:34:18 -08:00
|
|
|
}
|
|
|
|
|
2012-11-21 14:34:20 -08:00
|
|
|
nsIntRegion lowPrecisionInvalidRegion;
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!mPaintData.mLayerCriticalDisplayPort.IsEmpty()) {
|
|
|
|
// Make sure that tiles that fall outside of the critical displayport are
|
|
|
|
// discarded on the first update.
|
|
|
|
if (!BasicManager()->IsRepeatTransaction()) {
|
|
|
|
mValidRegion.And(mValidRegion, mPaintData.mLayerCriticalDisplayPort);
|
|
|
|
}
|
2012-11-21 14:34:20 -08:00
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
if (gfxPlatform::UseLowPrecisionBuffer()) {
|
|
|
|
// Calculate the invalid region for the low precision buffer
|
|
|
|
lowPrecisionInvalidRegion.Sub(mVisibleRegion, mLowPrecisionValidRegion);
|
|
|
|
|
|
|
|
// Remove the valid region from the low precision valid region (we don't
|
|
|
|
// validate this part of the low precision buffer).
|
|
|
|
lowPrecisionInvalidRegion.Sub(lowPrecisionInvalidRegion, mValidRegion);
|
|
|
|
}
|
2012-11-21 14:34:18 -08:00
|
|
|
|
|
|
|
// Clip the invalid region to the critical display-port
|
2012-11-29 05:08:40 -08:00
|
|
|
invalidRegion.And(invalidRegion, mPaintData.mLayerCriticalDisplayPort);
|
2012-11-21 14:34:20 -08:00
|
|
|
if (invalidRegion.IsEmpty() && lowPrecisionInvalidRegion.IsEmpty()) {
|
2012-11-29 05:08:40 -08:00
|
|
|
EndPaint(true);
|
2012-11-21 14:34:18 -08:00
|
|
|
return;
|
2012-11-21 14:34:20 -08:00
|
|
|
}
|
2012-11-21 14:34:18 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!invalidRegion.IsEmpty() && mPaintData.mLowPrecisionPaintCount == 0) {
|
2012-11-21 14:34:20 -08:00
|
|
|
bool updatedBuffer = false;
|
|
|
|
// Only draw progressively when the resolution is unchanged.
|
|
|
|
if (gfxPlatform::UseProgressiveTilePainting() &&
|
|
|
|
!BasicManager()->HasShadowTarget() &&
|
2012-11-29 05:08:40 -08:00
|
|
|
mTiledBuffer.GetFrameResolution() == mPaintData.mResolution) {
|
2012-11-21 14:34:20 -08:00
|
|
|
// Store the old valid region, then clear it before painting.
|
|
|
|
// We clip the old valid region to the visible region, as it only gets
|
|
|
|
// used to decide stale content (currently valid and previously visible)
|
|
|
|
nsIntRegion oldValidRegion = mTiledBuffer.GetValidRegion();
|
|
|
|
oldValidRegion.And(oldValidRegion, mVisibleRegion);
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!mPaintData.mLayerCriticalDisplayPort.IsEmpty()) {
|
|
|
|
oldValidRegion.And(oldValidRegion, mPaintData.mLayerCriticalDisplayPort);
|
2012-11-21 14:34:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
updatedBuffer =
|
|
|
|
ProgressiveUpdate(mTiledBuffer, mValidRegion, invalidRegion,
|
2012-11-29 05:08:40 -08:00
|
|
|
oldValidRegion, mPaintData.mTransformScreenToLayer,
|
|
|
|
mPaintData.mCompositionBounds, mPaintData.mScrollOffset,
|
|
|
|
mPaintData.mResolution, aCallback, aCallbackData);
|
2012-11-21 14:34:20 -08:00
|
|
|
} else {
|
|
|
|
updatedBuffer = true;
|
2012-11-29 05:08:40 -08:00
|
|
|
mTiledBuffer.SetFrameResolution(mPaintData.mResolution);
|
2012-11-21 14:34:20 -08:00
|
|
|
mValidRegion = mVisibleRegion;
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!mPaintData.mLayerCriticalDisplayPort.IsEmpty()) {
|
|
|
|
mValidRegion.And(mValidRegion, mPaintData.mLayerCriticalDisplayPort);
|
2012-11-21 14:34:18 -08:00
|
|
|
}
|
2012-11-21 14:34:20 -08:00
|
|
|
mTiledBuffer.PaintThebes(this, mValidRegion, invalidRegion, aCallback, aCallbackData);
|
2012-11-21 11:16:53 -08:00
|
|
|
}
|
2012-11-21 11:16:52 -08:00
|
|
|
|
2012-11-21 14:34:20 -08:00
|
|
|
if (updatedBuffer) {
|
2012-11-29 05:08:40 -08:00
|
|
|
mFirstPaint = false;
|
2012-11-21 14:34:20 -08:00
|
|
|
mTiledBuffer.ReadLock();
|
2012-11-21 11:16:52 -08:00
|
|
|
|
2012-11-21 14:34:20 -08:00
|
|
|
// Only paint the mask layer on the first transaction.
|
|
|
|
if (aMaskLayer && !BasicManager()->IsRepeatTransaction()) {
|
|
|
|
static_cast<BasicImplData*>(aMaskLayer->ImplData())
|
|
|
|
->Paint(aContext, nullptr);
|
|
|
|
}
|
2012-11-21 11:57:02 -08:00
|
|
|
|
2012-11-21 14:34:20 -08:00
|
|
|
// TODO: Remove me once Bug 747811 lands.
|
|
|
|
BasicTiledLayerBuffer *heapCopy = new BasicTiledLayerBuffer(mTiledBuffer);
|
2012-11-21 11:57:02 -08:00
|
|
|
|
2012-11-21 14:34:20 -08:00
|
|
|
BasicManager()->PaintedTiledLayerBuffer(BasicManager()->Hold(this), heapCopy);
|
|
|
|
mTiledBuffer.ClearPaintedRegion();
|
2012-11-29 05:08:40 -08:00
|
|
|
|
|
|
|
// If there are low precision updates, mark the paint as unfinished and
|
|
|
|
// request a repeat transaction.
|
|
|
|
if (!lowPrecisionInvalidRegion.IsEmpty() && mPaintData.mPaintFinished) {
|
|
|
|
BasicManager()->SetRepeatTransaction();
|
|
|
|
mPaintData.mLowPrecisionPaintCount = 1;
|
|
|
|
mPaintData.mPaintFinished = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return so that low precision updates aren't performed in the same
|
|
|
|
// transaction as high-precision updates.
|
|
|
|
EndPaint(false);
|
|
|
|
return;
|
2012-11-21 14:34:20 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 14:34:19 -08:00
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
// Render the low precision buffer, if there's area to invalidate and the
|
|
|
|
// visible region is larger than the critical display port.
|
2012-11-21 14:34:19 -08:00
|
|
|
bool updatedLowPrecision = false;
|
2012-11-29 05:08:40 -08:00
|
|
|
if (!lowPrecisionInvalidRegion.IsEmpty() &&
|
|
|
|
!nsIntRegion(mPaintData.mLayerCriticalDisplayPort).Contains(mVisibleRegion)) {
|
2012-11-21 14:34:19 -08:00
|
|
|
nsIntRegion oldValidRegion = mLowPrecisionTiledBuffer.GetValidRegion();
|
|
|
|
oldValidRegion.And(oldValidRegion, mVisibleRegion);
|
|
|
|
|
2012-11-29 05:08:41 -08:00
|
|
|
// If the frame resolution or format have changed, invalidate the buffer
|
|
|
|
if (mLowPrecisionTiledBuffer.GetFrameResolution() != mPaintData.mResolution ||
|
|
|
|
mLowPrecisionTiledBuffer.HasFormatChanged(this)) {
|
2012-11-21 14:34:19 -08:00
|
|
|
if (!mLowPrecisionValidRegion.IsEmpty()) {
|
2012-11-21 14:34:20 -08:00
|
|
|
updatedLowPrecision = true;
|
2012-11-21 14:34:19 -08:00
|
|
|
}
|
|
|
|
oldValidRegion.SetEmpty();
|
|
|
|
mLowPrecisionValidRegion.SetEmpty();
|
2012-11-29 05:08:40 -08:00
|
|
|
mLowPrecisionTiledBuffer.SetFrameResolution(mPaintData.mResolution);
|
2012-11-29 05:08:41 -08:00
|
|
|
lowPrecisionInvalidRegion = mVisibleRegion;
|
2012-11-21 14:34:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate previously valid content that is no longer visible
|
2012-11-29 05:08:40 -08:00
|
|
|
if (mPaintData.mLowPrecisionPaintCount == 1) {
|
2012-11-21 14:34:19 -08:00
|
|
|
mLowPrecisionValidRegion.And(mLowPrecisionValidRegion, mVisibleRegion);
|
|
|
|
}
|
2012-11-29 05:08:40 -08:00
|
|
|
mPaintData.mLowPrecisionPaintCount++;
|
2012-11-21 14:34:19 -08:00
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
// Remove the valid high-precision region from the invalid low-precision
|
|
|
|
// region. We don't want to spend time drawing things twice.
|
2012-11-29 05:08:40 -08:00
|
|
|
lowPrecisionInvalidRegion.Sub(lowPrecisionInvalidRegion, mValidRegion);
|
2012-11-21 14:34:19 -08:00
|
|
|
|
2012-11-21 14:34:19 -08:00
|
|
|
if (!lowPrecisionInvalidRegion.IsEmpty()) {
|
|
|
|
updatedLowPrecision =
|
|
|
|
ProgressiveUpdate(mLowPrecisionTiledBuffer, mLowPrecisionValidRegion,
|
2012-11-29 05:08:40 -08:00
|
|
|
lowPrecisionInvalidRegion, oldValidRegion,
|
|
|
|
mPaintData.mTransformScreenToLayer,
|
|
|
|
mPaintData.mCompositionBounds, mPaintData.mScrollOffset,
|
|
|
|
mPaintData.mResolution, aCallback, aCallbackData);
|
2012-11-21 14:34:19 -08:00
|
|
|
}
|
|
|
|
} else if (!mLowPrecisionValidRegion.IsEmpty()) {
|
|
|
|
// Clear the low precision tiled buffer
|
2012-11-21 14:34:20 -08:00
|
|
|
updatedLowPrecision = true;
|
2012-11-21 14:34:19 -08:00
|
|
|
mLowPrecisionValidRegion.SetEmpty();
|
|
|
|
mLowPrecisionTiledBuffer.PaintThebes(this, mLowPrecisionValidRegion,
|
|
|
|
mLowPrecisionValidRegion, aCallback,
|
|
|
|
aCallbackData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We send a Painted callback if we clear the valid region of the low
|
|
|
|
// precision buffer, so that the shadow buffer's valid region can be updated
|
|
|
|
// and the associated resources can be freed.
|
2012-11-21 14:34:20 -08:00
|
|
|
if (updatedLowPrecision) {
|
2012-11-21 14:34:19 -08:00
|
|
|
mLowPrecisionTiledBuffer.ReadLock();
|
2012-11-29 05:08:40 -08:00
|
|
|
// TODO: Remove me once Bug 747811 lands.
|
2012-11-21 14:34:19 -08:00
|
|
|
BasicTiledLayerBuffer *heapCopy = new BasicTiledLayerBuffer(mLowPrecisionTiledBuffer);
|
|
|
|
|
|
|
|
// The GL layer manager uses the buffer resolution to distinguish calls
|
|
|
|
// to PaintedTiledLayerBuffer.
|
|
|
|
BasicManager()->PaintedTiledLayerBuffer(BasicManager()->Hold(this), heapCopy);
|
|
|
|
mLowPrecisionTiledBuffer.ClearPaintedRegion();
|
|
|
|
}
|
|
|
|
|
2012-11-29 05:08:40 -08:00
|
|
|
EndPaint(false);
|
2012-04-16 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // mozilla
|
|
|
|
} // layers
|