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 "PrintTranslator.h"
9 #include "gfxContext.h"
10 #include "nsDeviceContext.h"
11 #include "mozilla/gfx/RecordedEvent.h"
12 #include "mozilla/gfx/RecordingTypes.h"
13 #include "mozilla/ProfilerMarkers.h"
14 #include "mozilla/UniquePtr.h"
15 #include "InlineTranslator.h"
17 using namespace mozilla::gfx
;
22 PrintTranslator::PrintTranslator(nsDeviceContext
* aDeviceContext
)
23 : mDeviceContext(aDeviceContext
) {
24 UniquePtr
<gfxContext
> context
=
25 mDeviceContext
->CreateReferenceRenderingContext();
26 mBaseDT
= context
->GetDrawTarget();
29 bool PrintTranslator::TranslateRecording(PRFileDescStream
& aRecording
) {
30 AUTO_PROFILER_MARKER_TEXT("PrintTranslator", LAYOUT_Printing
, {},
31 "PrintTranslator::TranslateRecording"_ns
);
34 ReadElement(aRecording
, magicInt
);
35 if (magicInt
!= mozilla::gfx::kMagicInt
) {
39 uint16_t majorRevision
;
40 ReadElement(aRecording
, majorRevision
);
41 if (majorRevision
!= kMajorRevision
) {
45 uint16_t minorRevision
;
46 ReadElement(aRecording
, minorRevision
);
47 if (minorRevision
> kMinorRevision
) {
51 uint8_t eventType
= RecordedEvent::EventType::INVALID
;
52 ReadElement(aRecording
, eventType
);
53 while (aRecording
.good()) {
54 bool success
= RecordedEvent::DoWithEventFromStream(
55 aRecording
, static_cast<RecordedEvent::EventType
>(eventType
),
56 [&](RecordedEvent
* recordedEvent
) -> bool {
57 // Make sure that the whole event was read from the stream.
58 if (!aRecording
.good()) {
62 return recordedEvent
->PlayEvent(this);
69 ReadElement(aRecording
, eventType
);
75 already_AddRefed
<DrawTarget
> PrintTranslator::CreateDrawTarget(
76 ReferencePtr aRefPtr
, const gfx::IntSize
& aSize
,
77 gfx::SurfaceFormat aFormat
) {
78 UniquePtr
<gfxContext
> context
= mDeviceContext
->CreateRenderingContext();
80 NS_WARNING("Failed to create rendering context for print.");
84 RefPtr
<DrawTarget
> drawTarget
= context
->GetDrawTarget();
85 AddDrawTarget(aRefPtr
, drawTarget
);
86 return drawTarget
.forget();
90 } // namespace mozilla