Bug 1233619 (part 2) - Moz2Dify BeginUpdate() and BeginUpdateBackground() functions. r=roc.

The only non-trivial change is in BasicPaintedLayer::Validate().
This commit is contained in:
Nicholas Nethercote 2015-12-17 19:39:10 -08:00
parent 8566095ec7
commit bb44e657ca
16 changed files with 48 additions and 39 deletions

View File

@ -304,13 +304,13 @@ PluginPRLibrary::SetBackgroundUnknown(NPP instance)
}
nsresult
PluginPRLibrary::BeginUpdateBackground(NPP instance,
const nsIntRect&, gfxContext** aCtx)
PluginPRLibrary::BeginUpdateBackground(NPP instance, const nsIntRect&,
DrawTarget** aDrawTarget)
{
nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
NS_ERROR("Unexpected use of async APIs for in-process plugin.");
*aCtx = nullptr;
*aDrawTarget = nullptr;
return NS_OK;
}

View File

@ -117,8 +117,8 @@ public:
virtual nsresult ContentsScaleFactorChanged(NPP aInstance, double aContentsScaleFactor) override;
#endif
virtual nsresult SetBackgroundUnknown(NPP instance) override;
virtual nsresult BeginUpdateBackground(NPP instance,
const nsIntRect&, gfxContext** aCtx) override;
virtual nsresult BeginUpdateBackground(NPP instance, const nsIntRect&,
DrawTarget** aDrawTarget) override;
virtual nsresult EndUpdateBackground(NPP instance,
const nsIntRect&) override;
virtual void DidComposite(NPP aInstance) override { }

View File

@ -1250,7 +1250,7 @@ nsNPAPIPluginInstance::SetBackgroundUnknown()
nsresult
nsNPAPIPluginInstance::BeginUpdateBackground(nsIntRect* aRect,
gfxContext** aContext)
DrawTarget** aDrawTarget)
{
if (RUNNING != mRunning)
return NS_OK;
@ -1259,7 +1259,7 @@ nsNPAPIPluginInstance::BeginUpdateBackground(nsIntRect* aRect,
if (!library)
return NS_ERROR_FAILURE;
return library->BeginUpdateBackground(&mNPP, *aRect, aContext);
return library->BeginUpdateBackground(&mNPP, *aRect, aDrawTarget);
}
nsresult

View File

@ -83,6 +83,8 @@ private:
typedef mozilla::PluginLibrary PluginLibrary;
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsNPAPIPluginInstance)
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
@ -108,7 +110,7 @@ public:
nsresult NotifyPainted(void);
nsresult GetIsOOP(bool* aIsOOP);
nsresult SetBackgroundUnknown();
nsresult BeginUpdateBackground(nsIntRect* aRect, gfxContext** aContext);
nsresult BeginUpdateBackground(nsIntRect* aRect, DrawTarget** aContext);
nsresult EndUpdateBackground(nsIntRect* aRect);
nsresult IsTransparent(bool* isTransparent);
nsresult GetFormValue(nsAString& aValue);

View File

@ -268,14 +268,14 @@ nsPluginInstanceOwner::SetBackgroundUnknown()
}
}
already_AddRefed<gfxContext>
already_AddRefed<mozilla::gfx::DrawTarget>
nsPluginInstanceOwner::BeginUpdateBackground(const nsIntRect& aRect)
{
nsIntRect rect = aRect;
RefPtr<gfxContext> ctx;
RefPtr<DrawTarget> dt;
if (mInstance &&
NS_SUCCEEDED(mInstance->BeginUpdateBackground(&rect, getter_AddRefs(ctx)))) {
return ctx.forget();
NS_SUCCEEDED(mInstance->BeginUpdateBackground(&rect, getter_AddRefs(dt)))) {
return dt.forget();
}
return nullptr;
}

View File

@ -28,6 +28,10 @@ class nsPluginDOMContextMenuListener;
class nsPluginFrame;
class nsDisplayListBuilder;
#if defined(MOZ_X11) || defined(ANDROID)
class gfxContext;
#endif
namespace mozilla {
class TextComposition;
namespace dom {
@ -54,6 +58,8 @@ class nsPluginInstanceOwner final : public nsIPluginInstanceOwner,
public nsSupportsWeakReference
{
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
nsPluginInstanceOwner();
NS_DECL_ISUPPORTS
@ -236,7 +242,7 @@ public:
// The eventual target of these operations is PluginInstanceParent,
// but it takes several hops to get there.
void SetBackgroundUnknown();
already_AddRefed<gfxContext> BeginUpdateBackground(const nsIntRect& aRect);
already_AddRefed<DrawTarget> BeginUpdateBackground(const nsIntRect& aRect);
void EndUpdateBackground(const nsIntRect& aRect);
bool UseAsyncRendering();

View File

@ -1130,7 +1130,7 @@ PluginInstanceParent::SetBackgroundUnknown()
nsresult
PluginInstanceParent::BeginUpdateBackground(const nsIntRect& aRect,
gfxContext** aCtx)
DrawTarget** aDrawTarget)
{
PLUGIN_LOG_DEBUG(
("[InstanceParent][%p] BeginUpdateBackground for <x=%d,y=%d, w=%d,h=%d>",
@ -1144,7 +1144,7 @@ PluginInstanceParent::BeginUpdateBackground(const nsIntRect& aRect,
MOZ_ASSERT(aRect.TopLeft() == nsIntPoint(0, 0),
"Expecting rect for whole frame");
if (!CreateBackground(aRect.Size())) {
*aCtx = nullptr;
*aDrawTarget = nullptr;
return NS_OK;
}
}
@ -1157,8 +1157,7 @@ PluginInstanceParent::BeginUpdateBackground(const nsIntRect& aRect,
RefPtr<gfx::DrawTarget> dt = gfxPlatform::GetPlatform()->
CreateDrawTargetForSurface(mBackground, gfx::IntSize(sz.width, sz.height));
RefPtr<gfxContext> ctx = new gfxContext(dt);
ctx.forget(aCtx);
dt.forget(aDrawTarget);
return NS_OK;
}

View File

@ -60,6 +60,8 @@ public:
#endif // defined(XP_WIN)
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
const nsCString& mimeType,
@ -338,7 +340,7 @@ public:
#endif
nsresult SetBackgroundUnknown();
nsresult BeginUpdateBackground(const nsIntRect& aRect,
gfxContext** aCtx);
DrawTarget** aDrawTarget);
nsresult EndUpdateBackground(const nsIntRect& aRect);
void DidComposite();

View File

@ -17,11 +17,13 @@
#include "nsSize.h"
#include "nsRect.h"
class gfxContext;
class nsCString;
class nsNPAPIPlugin;
namespace mozilla {
namespace gfx {
class DrawTarget;
}
namespace layers {
class Image;
class ImageContainer;
@ -43,6 +45,8 @@ namespace mozilla {
class PluginLibrary
{
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
virtual ~PluginLibrary() { }
/**
@ -91,13 +95,12 @@ public:
*/
virtual nsresult SetBackgroundUnknown(NPP instance) = 0;
virtual nsresult BeginUpdateBackground(NPP instance,
const nsIntRect&, gfxContext**) = 0;
const nsIntRect&, DrawTarget**) = 0;
virtual nsresult EndUpdateBackground(NPP instance, const nsIntRect&) = 0;
virtual nsresult GetRunID(uint32_t* aRunID) = 0;
virtual void SetHasLocalInstance() = 0;
};
} // namespace mozilla
#endif // ifndef mozilla_PluginLibrary_h

View File

@ -1994,13 +1994,13 @@ PluginModuleParent::SetBackgroundUnknown(NPP instance)
nsresult
PluginModuleParent::BeginUpdateBackground(NPP instance,
const nsIntRect& aRect,
gfxContext** aCtx)
DrawTarget** aDrawTarget)
{
PluginInstanceParent* i = PluginInstanceParent::Cast(instance);
if (!i)
return NS_ERROR_FAILURE;
return i->BeginUpdateBackground(aRect, aCtx);
return i->BeginUpdateBackground(aRect, aDrawTarget);
}
nsresult

View File

@ -255,7 +255,7 @@ protected:
virtual nsresult SetBackgroundUnknown(NPP instance) override;
virtual nsresult BeginUpdateBackground(NPP instance,
const nsIntRect& aRect,
gfxContext** aCtx) override;
DrawTarget** aDrawTarget) override;
virtual nsresult EndUpdateBackground(NPP instance,
const nsIntRect& aRect) override;

View File

@ -58,7 +58,7 @@ public:
* We don't support partially unknown backgrounds. Therefore, the
* first BeginUpdate after a SetUnknown will have the complete background.
*/
virtual already_AddRefed<gfxContext>
virtual already_AddRefed<gfx::DrawTarget>
BeginUpdate(const gfx::IntRect& aRect, uint64_t aSequenceNumber) = 0;
/**
* EndUpdate must be called immediately after BeginUpdate, without returning

View File

@ -114,14 +114,13 @@ ReadbackProcessor::BuildUpdatesForLayer(ReadbackLayer* aLayer)
aLayer->mBackgroundColor = colorLayer->GetColor();
NS_ASSERTION(aLayer->mBackgroundColor.a == 1.f,
"Color layer said it was opaque!");
RefPtr<gfxContext> ctx =
RefPtr<DrawTarget> dt =
aLayer->mSink->BeginUpdate(aLayer->GetRect(),
aLayer->AllocateSequenceNumber());
if (ctx) {
if (dt) {
ColorPattern color(ToDeviceColor(aLayer->mBackgroundColor));
IntSize size = aLayer->GetSize();
ctx->GetDrawTarget()->FillRect(Rect(0, 0, size.width, size.height),
color);
dt->FillRect(Rect(0, 0, size.width, size.height), color);
aLayer->mSink->EndUpdate(aLayer->GetRect());
}
}

View File

@ -203,15 +203,15 @@ BasicPaintedLayer::Validate(LayerManager::DrawPaintedLayerCallback aCallback,
for (uint32_t i = 0; i < readbackUpdates.Length(); ++i) {
ReadbackProcessor::Update& update = readbackUpdates[i];
nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset();
RefPtr<gfxContext> ctx =
RefPtr<DrawTarget> dt =
update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset,
update.mSequenceCounter);
if (ctx) {
if (dt) {
NS_ASSERTION(GetEffectiveOpacity() == 1.0, "Should only read back opaque layers");
NS_ASSERTION(!GetMaskLayer(), "Should only read back layers without masks");
ctx->SetMatrix(ctx->CurrentMatrix().Translate(offset.x, offset.y));
mContentClient->DrawTo(this, ctx->GetDrawTarget(), 1.0,
ctx->CurrentOp(), nullptr, nullptr);
dt->SetTransform(dt->GetTransform().PreTranslate(offset.x, offset.y));
mContentClient->DrawTo(this, dt, 1.0, CompositionOp::OP_OVER,
nullptr, nullptr);
update.mLayer->GetSink()->EndUpdate(update.mUpdateRect + offset);
}
}

View File

@ -185,14 +185,12 @@ public:
continue;
}
RefPtr<gfxContext> ctx =
RefPtr<DrawTarget> dt =
sink->BeginUpdate(update.mUpdateRect + offset, update.mSequenceCounter);
if (!ctx) {
if (!dt) {
continue;
}
DrawTarget* dt = ctx->GetDrawTarget();
dt->SetTransform(Matrix::Translation(offset.x, offset.y));
rotBuffer.DrawBufferWithRotation(dt, RotatedBuffer::BUFFER_BLACK);

View File

@ -119,7 +119,7 @@ public:
mFrame->mInstanceOwner->SetBackgroundUnknown();
}
virtual already_AddRefed<gfxContext>
virtual already_AddRefed<DrawTarget>
BeginUpdate(const nsIntRect& aRect, uint64_t aSequenceNumber)
{
if (!AcceptUpdate(aSequenceNumber))