2017-04-26 23:31:59 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 "InlineTranslator.h"
|
2017-07-04 18:53:35 +03:00
|
|
|
#include "RecordedEventImpl.h"
|
|
|
|
#include "DrawEventRecorder.h"
|
2017-04-26 23:31:59 +03:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "mozilla/gfx/RecordingTypes.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2017-05-18 04:56:58 +03:00
|
|
|
InlineTranslator::InlineTranslator(DrawTarget* aDT, void* aFontContext)
|
|
|
|
: mBaseDT(aDT)
|
|
|
|
, mFontContext(aFontContext)
|
2017-04-26 23:31:59 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-07-04 22:36:05 +03:00
|
|
|
InlineTranslator::TranslateRecording(char *aData, size_t aLen)
|
2017-04-26 23:31:59 +03:00
|
|
|
{
|
2017-07-04 22:36:05 +03:00
|
|
|
// an istream like class for reading from memory
|
|
|
|
struct MemReader {
|
|
|
|
MemReader(char *aData, size_t aLen) : mData(aData), mEnd(aData + aLen) {}
|
2017-07-17 21:54:50 +03:00
|
|
|
void read(char* s, std::streamsize n) {
|
2017-07-04 22:36:05 +03:00
|
|
|
if (n <= (mEnd - mData)) {
|
|
|
|
memcpy(s, mData, n);
|
|
|
|
mData += n;
|
|
|
|
} else {
|
|
|
|
// We've requested more data than is available
|
|
|
|
// set the Reader into an eof state
|
|
|
|
mData = mEnd + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool eof() {
|
|
|
|
return mData > mEnd;
|
|
|
|
}
|
|
|
|
bool good() {
|
|
|
|
return !eof();
|
|
|
|
}
|
|
|
|
|
|
|
|
char *mData;
|
|
|
|
char *mEnd;
|
|
|
|
};
|
|
|
|
MemReader reader(aData, aLen);
|
|
|
|
|
2017-10-28 01:21:27 +03:00
|
|
|
|
2017-04-26 23:31:59 +03:00
|
|
|
uint32_t magicInt;
|
2017-07-04 22:36:05 +03:00
|
|
|
ReadElement(reader, magicInt);
|
2017-04-26 23:31:59 +03:00
|
|
|
if (magicInt != mozilla::gfx::kMagicInt) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t majorRevision;
|
2017-07-04 22:36:05 +03:00
|
|
|
ReadElement(reader, majorRevision);
|
2017-04-26 23:31:59 +03:00
|
|
|
if (majorRevision != kMajorRevision) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t minorRevision;
|
2017-07-04 22:36:05 +03:00
|
|
|
ReadElement(reader, minorRevision);
|
2017-04-26 23:31:59 +03:00
|
|
|
if (minorRevision > kMinorRevision) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t eventType;
|
2017-07-04 22:36:05 +03:00
|
|
|
ReadElement(reader, eventType);
|
|
|
|
while (reader.good()) {
|
2017-08-18 20:03:09 +03:00
|
|
|
bool success = RecordedEvent::DoWithEvent(reader, static_cast<RecordedEvent::EventType>(eventType),
|
|
|
|
[&] (RecordedEvent *recordedEvent) {
|
|
|
|
// Make sure that the whole event was read from the stream successfully.
|
|
|
|
if (!reader.good()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!recordedEvent->PlayEvent(this)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (!success) {
|
2017-05-06 06:51:35 +03:00
|
|
|
return false;
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 22:36:05 +03:00
|
|
|
ReadElement(reader, eventType);
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DrawTarget>
|
|
|
|
InlineTranslator::CreateDrawTarget(ReferencePtr aRefPtr,
|
|
|
|
const gfx::IntSize &aSize,
|
|
|
|
gfx::SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
RefPtr<DrawTarget> drawTarget = mBaseDT;
|
2017-05-05 04:33:10 +03:00
|
|
|
AddDrawTarget(aRefPtr, drawTarget);
|
2017-04-26 23:31:59 +03:00
|
|
|
return drawTarget.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|