2013-04-30 22:03:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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 "ClientThebesLayer.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "ClientTiledThebesLayer.h" // for ClientTiledThebesLayer
|
|
|
|
#include <stdint.h> // for uint32_t
|
2013-08-22 00:11:51 -07:00
|
|
|
#include "GeckoProfiler.h" // for PROFILER_LABEL
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "client/ClientLayerManager.h" // for ClientLayerManager, etc
|
|
|
|
#include "gfxASurface.h" // for gfxASurface, etc
|
|
|
|
#include "gfxContext.h" // for gfxContext
|
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
|
|
#include "mozilla/gfx/2D.h" // for DrawTarget
|
|
|
|
#include "mozilla/gfx/Matrix.h" // for Matrix
|
|
|
|
#include "mozilla/gfx/Rect.h" // for Rect, IntRect
|
|
|
|
#include "mozilla/gfx/Types.h" // for Float, etc
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2013-09-10 11:21:37 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
|
|
|
|
#include "nsRect.h" // for nsIntRect
|
2014-01-07 13:09:34 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2013-04-30 22:03:25 -07:00
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientThebesLayer::PaintThebes()
|
|
|
|
{
|
|
|
|
PROFILER_LABEL("ClientThebesLayer", "PaintThebes");
|
|
|
|
NS_ASSERTION(ClientManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
|
|
|
|
{
|
2014-01-12 12:07:42 -08:00
|
|
|
mContentClient->PrepareFrame();
|
|
|
|
|
2013-04-30 22:03:25 -07:00
|
|
|
uint32_t flags = 0;
|
|
|
|
#ifndef MOZ_WIDGET_ANDROID
|
|
|
|
if (ClientManager()->CompositorMightResample()) {
|
2013-11-26 16:29:46 -08:00
|
|
|
flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
|
2013-04-30 22:03:25 -07:00
|
|
|
}
|
2013-11-26 16:29:46 -08:00
|
|
|
if (!(flags & RotatedContentBuffer::PAINT_WILL_RESAMPLE)) {
|
2013-04-30 22:03:25 -07:00
|
|
|
if (MayResample()) {
|
2013-11-26 16:29:46 -08:00
|
|
|
flags |= RotatedContentBuffer::PAINT_WILL_RESAMPLE;
|
2013-04-30 22:03:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
PaintState state =
|
2014-01-12 12:07:42 -08:00
|
|
|
mContentClient->BeginPaintBuffer(this, flags);
|
2013-04-30 22:03:25 -07:00
|
|
|
mValidRegion.Sub(mValidRegion, state.mRegionToInvalidate);
|
|
|
|
|
2014-01-12 12:07:42 -08:00
|
|
|
if (DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(this, state)) {
|
2013-04-30 22:03:25 -07:00
|
|
|
// The area that became invalid and is visible needs to be repainted
|
|
|
|
// (this could be the whole visible area if our buffer switched
|
|
|
|
// from RGB to RGBA, because we might need to repaint with
|
|
|
|
// subpixel AA)
|
|
|
|
state.mRegionToInvalidate.And(state.mRegionToInvalidate,
|
|
|
|
GetEffectiveVisibleRegion());
|
2014-01-12 12:07:42 -08:00
|
|
|
SetAntialiasingFlags(this, target);
|
2013-04-30 22:03:25 -07:00
|
|
|
|
2014-01-12 12:07:42 -08:00
|
|
|
nsRefPtr<gfxContext> ctx = gfxContext::ContextForDrawTarget(target);
|
2014-01-07 13:09:34 -08:00
|
|
|
PaintBuffer(ctx,
|
2014-01-12 12:07:42 -08:00
|
|
|
state.mRegionToDraw, state.mRegionToDraw, state.mRegionToInvalidate,
|
2013-11-06 11:10:50 -08:00
|
|
|
state.mDidSelfCopy, state.mClip);
|
2013-04-30 22:03:25 -07:00
|
|
|
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) PaintThebes", this));
|
|
|
|
Mutated();
|
2014-01-07 13:09:34 -08:00
|
|
|
ctx = nullptr;
|
2014-01-23 22:58:33 -08:00
|
|
|
mContentClient->ReturnDrawTargetToBuffer(target);
|
2013-04-30 22:03:25 -07:00
|
|
|
} else {
|
|
|
|
// It's possible that state.mRegionToInvalidate is nonempty here,
|
|
|
|
// if we are shrinking the valid region to nothing. So use mRegionToDraw
|
|
|
|
// instead.
|
|
|
|
NS_WARN_IF_FALSE(state.mRegionToDraw.IsEmpty(),
|
|
|
|
"No context when we have something to draw, resource exhaustion?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientThebesLayer::RenderLayer()
|
|
|
|
{
|
|
|
|
if (GetMaskLayer()) {
|
|
|
|
ToClientLayer(GetMaskLayer())->RenderLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mContentClient) {
|
2013-11-27 07:19:34 -08:00
|
|
|
mContentClient = ContentClient::CreateContentClient(ClientManager()->AsShadowForwarder());
|
2013-04-30 22:03:25 -07:00
|
|
|
if (!mContentClient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mContentClient->Connect();
|
2013-11-27 07:19:34 -08:00
|
|
|
ClientManager()->AsShadowForwarder()->Attach(mContentClient, this);
|
2013-04-30 22:03:25 -07:00
|
|
|
MOZ_ASSERT(mContentClient->GetForwarder());
|
|
|
|
}
|
|
|
|
|
|
|
|
mContentClient->BeginPaint();
|
|
|
|
PaintThebes();
|
|
|
|
mContentClient->EndPaint();
|
2013-12-05 10:39:22 -08:00
|
|
|
// It is very important that this is called after EndPaint, because destroying
|
|
|
|
// textures is a three stage process:
|
|
|
|
// 1. We are done with the buffer and move it to ContentClient::mOldTextures,
|
|
|
|
// that happens in DestroyBuffers which is may be called indirectly from
|
|
|
|
// PaintThebes.
|
|
|
|
// 2. The content client calls RemoveTextureClient on the texture clients in
|
|
|
|
// mOldTextures and forgets them. They then become invalid. The compositable
|
|
|
|
// client keeps a record of IDs. This happens in EndPaint.
|
|
|
|
// 3. An IPC message is sent to destroy the corresponding texture host. That
|
|
|
|
// happens from OnTransaction.
|
|
|
|
// It is important that these steps happen in order.
|
|
|
|
mContentClient->OnTransaction();
|
2013-04-30 22:03:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClientThebesLayer::PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
|
|
|
const nsIntRegion& aExtendedRegionToDraw,
|
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2013-11-06 11:10:50 -08:00
|
|
|
bool aDidSelfCopy, DrawRegionClip aClip)
|
2013-04-30 22:03:25 -07:00
|
|
|
{
|
|
|
|
ContentClientRemote* contentClientRemote = static_cast<ContentClientRemote*>(mContentClient.get());
|
|
|
|
MOZ_ASSERT(contentClientRemote->GetIPDLActor());
|
|
|
|
|
|
|
|
// NB: this just throws away the entire valid region if there are
|
|
|
|
// too many rects.
|
|
|
|
mValidRegion.SimplifyInward(8);
|
|
|
|
|
|
|
|
if (!ClientManager()->GetThebesLayerCallback()) {
|
|
|
|
ClientManager()->SetTransactionIncomplete();
|
|
|
|
return;
|
|
|
|
}
|
2014-02-04 12:35:22 -08:00
|
|
|
ClientManager()->GetThebesLayerCallback()(this,
|
|
|
|
aContext,
|
2013-11-06 11:10:50 -08:00
|
|
|
aExtendedRegionToDraw,
|
|
|
|
aClip,
|
2013-04-30 22:03:25 -07:00
|
|
|
aRegionToInvalidate,
|
|
|
|
ClientManager()->GetThebesLayerCallbackData());
|
|
|
|
|
|
|
|
// Everything that's visible has been validated. Do this instead of just
|
|
|
|
// OR-ing with aRegionToDraw, since that can lead to a very complex region
|
|
|
|
// here (OR doesn't automatically simplify to the simplest possible
|
|
|
|
// representation of a region.)
|
|
|
|
nsIntRegion tmp;
|
|
|
|
tmp.Or(mVisibleRegion, aExtendedRegionToDraw);
|
|
|
|
mValidRegion.Or(mValidRegion, tmp);
|
|
|
|
|
|
|
|
// Hold(this) ensures this layer is kept alive through the current transaction
|
|
|
|
// The ContentClient assumes this layer is kept alive (e.g., in CreateBuffer,
|
|
|
|
// DestroyThebesBuffer), so deleting this Hold for whatever reason will break things.
|
|
|
|
ClientManager()->Hold(this);
|
|
|
|
contentClientRemote->Updated(aRegionToDraw,
|
|
|
|
mVisibleRegion,
|
|
|
|
aDidSelfCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
ClientLayerManager::CreateThebesLayer()
|
2013-09-17 10:55:09 -07:00
|
|
|
{
|
|
|
|
return CreateThebesLayerWithHint(NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
ClientLayerManager::CreateThebesLayerWithHint(ThebesLayerCreationHint aHint)
|
2013-04-30 22:03:25 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
2013-09-17 10:55:09 -07:00
|
|
|
if (
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
aHint == SCROLLABLE &&
|
|
|
|
#endif
|
2014-01-23 10:26:41 -08:00
|
|
|
gfxPlatform::GetPrefLayersEnableTiles() && AsShadowForwarder()->GetCompositorBackendType() == LayersBackend::LAYERS_OPENGL) {
|
2013-04-30 22:03:25 -07:00
|
|
|
nsRefPtr<ClientTiledThebesLayer> layer =
|
|
|
|
new ClientTiledThebesLayer(this);
|
|
|
|
CREATE_SHADOW(Thebes);
|
|
|
|
return layer.forget();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
nsRefPtr<ClientThebesLayer> layer =
|
|
|
|
new ClientThebesLayer(this);
|
|
|
|
CREATE_SHADOW(Thebes);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|