diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /gfx/2d/InlineTranslator.cpp | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/2d/InlineTranslator.cpp')
-rw-r--r-- | gfx/2d/InlineTranslator.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/gfx/2d/InlineTranslator.cpp b/gfx/2d/InlineTranslator.cpp new file mode 100644 index 0000000000..8b264c2146 --- /dev/null +++ b/gfx/2d/InlineTranslator.cpp @@ -0,0 +1,117 @@ +/* -*- 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" +#include "RecordedEventImpl.h" + +#include "mozilla/gfx/RecordingTypes.h" + +using namespace mozilla::gfx; + +namespace mozilla::gfx { + +InlineTranslator::InlineTranslator() : mFontContext(nullptr) {} + +InlineTranslator::InlineTranslator(DrawTarget* aDT, void* aFontContext) + : mBaseDT(aDT), mFontContext(aFontContext) {} + +bool InlineTranslator::TranslateRecording(char* aData, size_t aLen) { + // an istream like class for reading from memory + struct MemReader { + MemReader(char* aData, size_t aLen) : mData(aData), mEnd(aData + aLen) {} + void read(char* s, std::streamsize n) { + 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 + SetIsBad(); + } + } + bool eof() { return mData > mEnd; } + bool good() { return !eof(); } + void SetIsBad() { mData = mEnd + 1; } + + char* mData; + char* mEnd; + }; + MemReader reader(aData, aLen); + + uint32_t magicInt; + ReadElement(reader, magicInt); + if (magicInt != mozilla::gfx::kMagicInt) { + mError = "Magic"; + return false; + } + + uint16_t majorRevision; + ReadElement(reader, majorRevision); + if (majorRevision != kMajorRevision) { + mError = "Major"; + return false; + } + + uint16_t minorRevision; + ReadElement(reader, minorRevision); + if (minorRevision > kMinorRevision) { + mError = "Minor"; + return false; + } + + int32_t eventType; + ReadElement(reader, eventType); + while (reader.good()) { + bool success = RecordedEvent::DoWithEvent( + reader, static_cast<RecordedEvent::EventType>(eventType), + [&](RecordedEvent* recordedEvent) -> bool { + // Make sure that the whole event was read from the stream + // successfully. + if (!reader.good()) { + mError = " READ"; + return false; + } + + if (!recordedEvent->PlayEvent(this)) { + mError = " PLAY"; + return false; + } + + return true; + }); + if (!success) { + mError = RecordedEvent::GetEventName( + static_cast<RecordedEvent::EventType>(eventType)) + + mError; + return false; + } + + ReadElement(reader, eventType); + } + + return true; +} + +already_AddRefed<DrawTarget> InlineTranslator::CreateDrawTarget( + ReferencePtr aRefPtr, const gfx::IntSize& aSize, + gfx::SurfaceFormat aFormat) { + MOZ_ASSERT(mBaseDT, "mBaseDT has not been initialized."); + + RefPtr<DrawTarget> drawTarget = mBaseDT; + AddDrawTarget(aRefPtr, drawTarget); + return drawTarget.forget(); +} + +already_AddRefed<SourceSurface> InlineTranslator::LookupExternalSurface( + uint64_t aKey) { + if (!mExternalSurfaces) { + return nullptr; + } + RefPtr<SourceSurface> surface = mExternalSurfaces->Get(aKey); + return surface.forget(); +} + +} // namespace mozilla::gfx |