Bug 1372739 - Use DrawTargetCapture instead of DrawTargetRecording for omtp. r=dvander

This commit is contained in:
Mason Chang 2017-06-22 08:36:14 -07:00
Родитель 29a6af3f3d
Коммит 3895c778af
4 изменённых файлов: 31 добавлений и 43 удалений

Просмотреть файл

@ -6,8 +6,7 @@
#include "PaintThread.h"
#include "mozilla/gfx/DrawEventRecorder.h"
#include "mozilla/gfx/InlineTranslator.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/SyncRunnable.h"
namespace mozilla {
@ -95,27 +94,22 @@ PaintThread::IsOnPaintThread()
}
void
PaintThread::PaintContents(DrawEventRecorderMemory* aRecording,
PaintThread::PaintContents(DrawTargetCapture* aCapture,
DrawTarget* aTarget)
{
if (!IsOnPaintThread()) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> paintTask =
NewRunnableMethod<DrawEventRecorderMemory*, DrawTarget*>(this,
&PaintThread::PaintContents,
aRecording, aTarget);
NewRunnableMethod<DrawTargetCapture*, DrawTarget*>(this,
&PaintThread::PaintContents,
aCapture, aTarget);
SyncRunnable::DispatchToThread(mThread, paintTask);
return;
}
// Draw all the things into the actual dest target.
// This shouldn't exist in the future. For now, its just testing
// to make sure we properly record and can replay all the draw
// commands
std::istream& stream = aRecording->GetInputStream();
InlineTranslator translator(aTarget, nullptr);
translator.TranslateRecording(stream);
aTarget->DrawCapturedDT(aCapture, Matrix());
}
} // namespace layers

Просмотреть файл

@ -13,8 +13,8 @@
namespace mozilla {
namespace gfx {
class DrawEventRecorderMemory;
class DrawTarget;
class DrawTargetCapture;
};
namespace layers {
@ -25,7 +25,7 @@ public:
static void Start();
static void Shutdown();
static PaintThread* Get();
void PaintContents(gfx::DrawEventRecorderMemory* aRecording,
void PaintContents(gfx::DrawTargetCapture* aCapture,
gfx::DrawTarget* aTarget);
// Sync Runnables need threads to be ref counted,
// But this thread lives through the whole process.

Просмотреть файл

@ -114,7 +114,7 @@ ClientPaintedLayer::UpdatePaintRegion(PaintState& aState)
}
void
ClientPaintedLayer::PaintOffMainThread(DrawEventRecorderMemory* aRecorder)
ClientPaintedLayer::PaintOffMainThread(DrawTargetCapture* aCapture)
{
MOZ_ASSERT(NS_IsMainThread());
LayerIntRegion visibleRegion = GetVisibleRegion();
@ -141,7 +141,7 @@ ClientPaintedLayer::PaintOffMainThread(DrawEventRecorderMemory* aRecorder)
SetAntialiasingFlags(this, target);
// Basic version, wait for the paint thread to finish painting.
PaintThread::Get()->PaintContents(aRecorder, target);
PaintThread::Get()->PaintContents(aCapture, target);
mContentClient->ReturnDrawTargetToBuffer(target);
didUpdate = true;
@ -187,8 +187,7 @@ ClientPaintedLayer::PaintThebes(nsTArray<ReadbackProcessor::Update>* aReadbackUp
uint32_t flags = GetPaintFlags();
PaintState state =
mContentClient->BeginPaintBuffer(this, flags);
PaintState state = mContentClient->BeginPaintBuffer(this, flags);
if (!UpdatePaintRegion(state)) {
return;
}
@ -228,8 +227,8 @@ ClientPaintedLayer::PaintThebes(nsTArray<ReadbackProcessor::Update>* aReadbackUp
}
}
already_AddRefed<DrawEventRecorderMemory>
ClientPaintedLayer::RecordPaintedLayer()
already_AddRefed<DrawTargetCapture>
ClientPaintedLayer::CapturePaintedContent()
{
LayerIntRegion visibleRegion = GetVisibleRegion();
LayerIntRect bounds = visibleRegion.GetBounds();
@ -256,25 +255,19 @@ ClientPaintedLayer::RecordPaintedLayer()
return nullptr;
}
// I know this is slow and we should probably use DrawTargetCapture
// But for now, the recording draw target / replay should actually work
// Replay for WR happens in Moz2DIMageRenderer
IntSize imageSize(size.ToUnknownSize());
// DrawTargetRecording also plays back the commands while
// recording, hence the dummy DT. DummyDT will actually have
// the drawn painted layer.
RefPtr<DrawEventRecorderMemory> recorder =
MakeAndAddRef<DrawEventRecorderMemory>();
RefPtr<DrawTarget> dummyDt =
Factory::CreateDrawTarget(gfx::BackendType::SKIA, imageSize, gfx::SurfaceFormat::B8G8R8A8);
// DrawTargetCapture requires a reference DT
// That is used when some API requires a snapshot.
// TODO: Fixup so DrawTargetCapture lazily creates a reference DT
RefPtr<DrawTarget> refDT =
Factory::CreateDrawTarget(gfxPlatform::GetPlatform()->GetDefaultContentBackend(),
imageSize, gfx::SurfaceFormat::B8G8R8A8);
RefPtr<DrawTarget> dt =
Factory::CreateRecordingDrawTarget(recorder, dummyDt, imageSize);
dt->ClearRect(Rect(0, 0, imageSize.width, imageSize.height));
dt->SetTransform(Matrix().PreTranslate(-bounds.x, -bounds.y));
RefPtr<gfxContext> ctx = gfxContext::CreatePreservingTransformOrNull(dt);
RefPtr<DrawTargetCapture> captureDT = refDT->CreateCaptureDT(imageSize);
captureDT->ClearRect(Rect(0, 0, imageSize.width, imageSize.height));
captureDT->SetTransform(Matrix().PreTranslate(-bounds.x, -bounds.y));
RefPtr<gfxContext> ctx = gfxContext::CreatePreservingTransformOrNull(captureDT);
MOZ_ASSERT(ctx); // already checked the target above
ClientManager()->GetPaintedLayerCallback()(this,
@ -285,7 +278,7 @@ ClientPaintedLayer::RecordPaintedLayer()
nsIntRegion(),
ClientManager()->GetPaintedLayerCallbackData());
return recorder.forget();
return captureDT.forget();
}
void
@ -294,13 +287,13 @@ ClientPaintedLayer::RenderLayerWithReadback(ReadbackProcessor *aReadback)
RenderMaskLayers(this);
if (CanRecordLayer(aReadback)) {
RefPtr<DrawEventRecorderMemory> recorder = RecordPaintedLayer();
if (recorder) {
RefPtr<DrawTargetCapture> capture = CapturePaintedContent();
if (capture) {
if (!EnsureContentClient()) {
return;
}
PaintOffMainThread(recorder);
PaintOffMainThread(capture);
return;
}
}

Просмотреть файл

@ -20,7 +20,8 @@
namespace mozilla {
namespace gfx {
class DrawEventRecorderMemory;
class DrawEventRecorderMemory;
class DrawTargetCapture;
};
namespace layers {
@ -115,12 +116,12 @@ protected:
void RecordThebes();
bool CanRecordLayer(ReadbackProcessor* aReadback);
bool HasMaskLayers();
already_AddRefed<gfx::DrawEventRecorderMemory> RecordPaintedLayer();
bool EnsureContentClient();
uint32_t GetPaintFlags();
void UpdateContentClient(PaintState& aState);
bool UpdatePaintRegion(PaintState& aState);
void PaintOffMainThread(DrawEventRecorderMemory* aRecorder);
void PaintOffMainThread(DrawTargetCapture* aCapture);
already_AddRefed<gfx::DrawTargetCapture> CapturePaintedContent();
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;