1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InlineTranslator.h"
8 #include "RecordedEventImpl.h"
10 #include "mozilla/gfx/RecordingTypes.h"
12 using namespace mozilla::gfx
;
14 namespace mozilla::gfx
{
16 InlineTranslator::InlineTranslator() : mFontContext(nullptr) {}
18 InlineTranslator::InlineTranslator(DrawTarget
* aDT
, void* aFontContext
)
19 : mBaseDT(aDT
), mFontContext(aFontContext
) {}
21 bool InlineTranslator::TranslateRecording(char* aData
, size_t aLen
) {
22 MemReader
reader(aData
, aLen
);
25 ReadElement(reader
, magicInt
);
26 if (magicInt
!= mozilla::gfx::kMagicInt
) {
31 uint16_t majorRevision
;
32 ReadElement(reader
, majorRevision
);
33 if (majorRevision
!= kMajorRevision
) {
38 uint16_t minorRevision
;
39 ReadElement(reader
, minorRevision
);
40 if (minorRevision
> kMinorRevision
) {
45 uint8_t eventType
= RecordedEvent::EventType::INVALID
;
46 ReadElement(reader
, eventType
);
47 while (reader
.good()) {
48 bool success
= RecordedEvent::DoWithEvent(
49 reader
, static_cast<RecordedEvent::EventType
>(eventType
),
50 [&](RecordedEvent
* recordedEvent
) -> bool {
51 // Make sure that the whole event was read from the stream
58 if (!recordedEvent
->PlayEvent(this)) {
66 mError
= RecordedEvent::GetEventName(
67 static_cast<RecordedEvent::EventType
>(eventType
)) +
72 ReadElement(reader
, eventType
);
78 already_AddRefed
<DrawTarget
> InlineTranslator::CreateDrawTarget(
79 ReferencePtr aRefPtr
, const gfx::IntSize
& aSize
,
80 gfx::SurfaceFormat aFormat
) {
81 MOZ_ASSERT(mBaseDT
, "mBaseDT has not been initialized.");
83 RefPtr
<DrawTarget
> drawTarget
= mBaseDT
;
84 AddDrawTarget(aRefPtr
, drawTarget
);
85 return drawTarget
.forget();
88 already_AddRefed
<SourceSurface
> InlineTranslator::LookupExternalSurface(
90 if (!mExternalSurfaces
) {
93 RefPtr
<SourceSurface
> surface
= mExternalSurfaces
->Get(aKey
);
94 return surface
.forget();
97 } // namespace mozilla::gfx