/src/mozilla-central/gfx/2d/InlineTranslator.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "InlineTranslator.h" |
8 | | #include "RecordedEventImpl.h" |
9 | | #include "DrawEventRecorder.h" |
10 | | |
11 | | #include "gfxContext.h" |
12 | | #include "nsDeviceContext.h" |
13 | | #include "mozilla/gfx/RecordingTypes.h" |
14 | | #include "mozilla/UniquePtr.h" |
15 | | |
16 | | using namespace mozilla::gfx; |
17 | | |
18 | | namespace mozilla { |
19 | | namespace gfx { |
20 | | |
21 | | InlineTranslator::InlineTranslator(DrawTarget* aDT, void* aFontContext) |
22 | | : mBaseDT(aDT) |
23 | | , mFontContext(aFontContext) |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | | bool |
28 | | InlineTranslator::TranslateRecording(char *aData, size_t aLen) |
29 | 0 | { |
30 | 0 | // an istream like class for reading from memory |
31 | 0 | struct MemReader { |
32 | 0 | MemReader(char *aData, size_t aLen) : mData(aData), mEnd(aData + aLen) {} |
33 | 0 | void read(char* s, std::streamsize n) { |
34 | 0 | if (n <= (mEnd - mData)) { |
35 | 0 | memcpy(s, mData, n); |
36 | 0 | mData += n; |
37 | 0 | } else { |
38 | 0 | // We've requested more data than is available |
39 | 0 | // set the Reader into an eof state |
40 | 0 | mData = mEnd + 1; |
41 | 0 | } |
42 | 0 | } |
43 | 0 | bool eof() { |
44 | 0 | return mData > mEnd; |
45 | 0 | } |
46 | 0 | bool good() { |
47 | 0 | return !eof(); |
48 | 0 | } |
49 | 0 |
|
50 | 0 | char *mData; |
51 | 0 | char *mEnd; |
52 | 0 | }; |
53 | 0 | MemReader reader(aData, aLen); |
54 | 0 |
|
55 | 0 |
|
56 | 0 | uint32_t magicInt; |
57 | 0 | ReadElement(reader, magicInt); |
58 | 0 | if (magicInt != mozilla::gfx::kMagicInt) { |
59 | 0 | return false; |
60 | 0 | } |
61 | 0 | |
62 | 0 | uint16_t majorRevision; |
63 | 0 | ReadElement(reader, majorRevision); |
64 | 0 | if (majorRevision != kMajorRevision) { |
65 | 0 | return false; |
66 | 0 | } |
67 | 0 | |
68 | 0 | uint16_t minorRevision; |
69 | 0 | ReadElement(reader, minorRevision); |
70 | 0 | if (minorRevision > kMinorRevision) { |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | |
74 | 0 | int32_t eventType; |
75 | 0 | ReadElement(reader, eventType); |
76 | 0 | while (reader.good()) { |
77 | 0 | bool success = RecordedEvent::DoWithEvent(reader, static_cast<RecordedEvent::EventType>(eventType), |
78 | 0 | [&] (RecordedEvent *recordedEvent) { |
79 | 0 | // Make sure that the whole event was read from the stream successfully. |
80 | 0 | if (!reader.good()) { |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 | |
84 | 0 | if (!recordedEvent->PlayEvent(this)) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | |
88 | 0 | return true; |
89 | 0 | }); |
90 | 0 | if (!success) { |
91 | 0 | return false; |
92 | 0 | } |
93 | 0 | |
94 | 0 | ReadElement(reader, eventType); |
95 | 0 | } |
96 | 0 |
|
97 | 0 | return true; |
98 | 0 | } |
99 | | |
100 | | already_AddRefed<DrawTarget> |
101 | | InlineTranslator::CreateDrawTarget(ReferencePtr aRefPtr, |
102 | | const gfx::IntSize &aSize, |
103 | | gfx::SurfaceFormat aFormat) |
104 | 0 | { |
105 | 0 | RefPtr<DrawTarget> drawTarget = mBaseDT; |
106 | 0 | AddDrawTarget(aRefPtr, drawTarget); |
107 | 0 | return drawTarget.forget(); |
108 | 0 | } |
109 | | |
110 | | } // namespace gfx |
111 | | } // namespace mozilla |