InlineTranslator.cpp (2694B)
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 10 #include "mozilla/gfx/RecordingTypes.h" 11 12 using namespace mozilla::gfx; 13 14 namespace mozilla::gfx { 15 16 InlineTranslator::InlineTranslator() : mFontContext(nullptr) {} 17 18 InlineTranslator::InlineTranslator(DrawTarget* aDT, void* aFontContext) 19 : mBaseDT(aDT), mFontContext(aFontContext) {} 20 21 bool InlineTranslator::TranslateRecording(char* aData, size_t aLen) { 22 MemReader reader(aData, aLen); 23 24 uint32_t magicInt; 25 ReadElement(reader, magicInt); 26 if (magicInt != mozilla::gfx::kMagicInt) { 27 mError = "Magic"; 28 return false; 29 } 30 31 uint16_t majorRevision; 32 ReadElement(reader, majorRevision); 33 if (majorRevision != kMajorRevision) { 34 mError = "Major"; 35 return false; 36 } 37 38 uint16_t minorRevision; 39 ReadElement(reader, minorRevision); 40 if (minorRevision > kMinorRevision) { 41 mError = "Minor"; 42 return false; 43 } 44 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 52 // successfully. 53 if (!reader.good()) { 54 mError = " READ"; 55 return false; 56 } 57 58 if (!recordedEvent->PlayEvent(this)) { 59 mError = " PLAY"; 60 return false; 61 } 62 63 return true; 64 }); 65 if (!success) { 66 mError = RecordedEvent::GetEventName( 67 static_cast<RecordedEvent::EventType>(eventType)) + 68 mError; 69 return false; 70 } 71 72 ReadElement(reader, eventType); 73 } 74 75 return true; 76 } 77 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."); 82 83 RefPtr<DrawTarget> drawTarget = mBaseDT; 84 AddDrawTarget(aRefPtr, drawTarget); 85 return drawTarget.forget(); 86 } 87 88 already_AddRefed<SourceSurface> InlineTranslator::LookupExternalSurface( 89 uint64_t aKey) { 90 if (!mExternalSurfaces) { 91 return nullptr; 92 } 93 RefPtr<SourceSurface> surface = mExternalSurfaces->Get(aKey); 94 return surface.forget(); 95 } 96 97 } // namespace mozilla::gfx