2017-04-26 23:31:59 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_layout_InlineTranslator_h
|
|
|
|
#define mozilla_layout_InlineTranslator_h
|
|
|
|
|
|
|
|
#include <istream>
|
2018-11-13 13:38:24 +03:00
|
|
|
#include <string>
|
2017-04-26 23:31:59 +03:00
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/Filters.h"
|
|
|
|
#include "mozilla/gfx/RecordedEvent.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
using gfx::DrawTarget;
|
|
|
|
using gfx::FilterNode;
|
|
|
|
using gfx::GradientStops;
|
|
|
|
using gfx::NativeFontResource;
|
|
|
|
using gfx::Path;
|
|
|
|
using gfx::ReferencePtr;
|
|
|
|
using gfx::ScaledFont;
|
|
|
|
using gfx::SourceSurface;
|
|
|
|
using gfx::Translator;
|
|
|
|
|
2018-04-27 02:00:16 +03:00
|
|
|
class InlineTranslator : public Translator {
|
2017-04-26 23:31:59 +03:00
|
|
|
public:
|
2019-09-10 05:06:28 +03:00
|
|
|
InlineTranslator();
|
|
|
|
|
2017-05-18 04:56:58 +03:00
|
|
|
explicit InlineTranslator(DrawTarget* aDT, void* aFontContext = nullptr);
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2017-07-04 22:36:05 +03:00
|
|
|
bool TranslateRecording(char*, size_t len);
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2018-09-25 05:43:41 +03:00
|
|
|
void SetExternalSurfaces(
|
|
|
|
nsRefPtrHashtable<nsUint64HashKey, SourceSurface>* aExternalSurfaces) {
|
|
|
|
mExternalSurfaces = aExternalSurfaces;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final {
|
2017-05-05 04:33:10 +03:00
|
|
|
DrawTarget* result = mDrawTargets.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
2017-04-26 23:31:59 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
Path* LookupPath(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
Path* result = mPaths.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final {
|
2019-08-30 20:14:22 +03:00
|
|
|
DebugOnly<bool> found;
|
|
|
|
GradientStops* result = mGradientStops.GetWeak(aRefPtr
|
|
|
|
#if defined(DEBUG)
|
|
|
|
,
|
|
|
|
&found
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
// GradientStops can be null in some circumstances.
|
|
|
|
MOZ_ASSERT(found);
|
2017-04-26 23:31:59 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:50:00 +03:00
|
|
|
UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
NativeFontResource* LookupNativeFontResource(uint64_t aKey) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-25 05:43:41 +03:00
|
|
|
already_AddRefed<SourceSurface> LookupExternalSurface(
|
|
|
|
uint64_t aKey) override {
|
|
|
|
return mExternalSurfaces->Get(aKey);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget* aDT) final {
|
2017-05-05 04:33:10 +03:00
|
|
|
mDrawTargets.Put(aRefPtr, aDT);
|
|
|
|
}
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddPath(ReferencePtr aRefPtr, Path* aPath) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mPaths.Put(aRefPtr, aPath);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface* aSurface) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mSourceSurfaces.Put(aRefPtr, aSurface);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddFilterNode(ReferencePtr aRefPtr, FilterNode* aFilter) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mFilterNodes.Put(aRefPtr, aFilter);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddGradientStops(ReferencePtr aRefPtr, GradientStops* aStops) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mGradientStops.Put(aRefPtr, aStops);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddScaledFont(ReferencePtr aRefPtr, ScaledFont* aScaledFont) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mScaledFonts.Put(aRefPtr, aScaledFont);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void AddUnscaledFont(ReferencePtr aRefPtr,
|
|
|
|
UnscaledFont* aUnscaledFont) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mUnscaledFonts.Put(aRefPtr, aUnscaledFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddNativeFontResource(uint64_t aKey,
|
2018-02-06 09:46:57 +03:00
|
|
|
NativeFontResource* aScaledFontResouce) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mNativeFontResources.Put(aKey, aScaledFontResouce);
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:17:12 +03:00
|
|
|
void RemoveDrawTarget(ReferencePtr aRefPtr) override {
|
2017-05-05 04:33:10 +03:00
|
|
|
mDrawTargets.Remove(aRefPtr);
|
|
|
|
}
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void RemovePath(ReferencePtr aRefPtr) final { mPaths.Remove(aRefPtr); }
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2018-12-02 17:17:12 +03:00
|
|
|
void RemoveSourceSurface(ReferencePtr aRefPtr) override {
|
2017-04-26 23:31:59 +03:00
|
|
|
mSourceSurfaces.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void RemoveFilterNode(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mFilterNodes.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void RemoveGradientStops(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mGradientStops.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void RemoveScaledFont(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mScaledFonts.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void RemoveUnscaledFont(ReferencePtr aRefPtr) final {
|
2017-04-26 23:31:59 +03:00
|
|
|
mUnscaledFonts.Remove(aRefPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DrawTarget> CreateDrawTarget(
|
|
|
|
ReferencePtr aRefPtr, const gfx::IntSize& aSize,
|
2018-12-02 17:17:12 +03:00
|
|
|
gfx::SurfaceFormat aFormat) override;
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2019-09-10 05:06:28 +03:00
|
|
|
mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final {
|
|
|
|
MOZ_ASSERT(mBaseDT, "mBaseDT has not been initialized.");
|
|
|
|
return mBaseDT;
|
|
|
|
}
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
void* GetFontContext() final { return mFontContext; }
|
2018-11-13 13:38:24 +03:00
|
|
|
std::string GetError() { return mError; }
|
2017-05-18 04:56:58 +03:00
|
|
|
|
2019-09-10 05:06:28 +03:00
|
|
|
protected:
|
2017-04-26 23:31:59 +03:00
|
|
|
RefPtr<DrawTarget> mBaseDT;
|
2019-09-10 05:06:28 +03:00
|
|
|
|
|
|
|
private:
|
2017-05-18 04:56:58 +03:00
|
|
|
void* mFontContext;
|
2018-11-13 13:38:24 +03:00
|
|
|
std::string mError;
|
2017-04-26 23:31:59 +03:00
|
|
|
|
2017-05-05 04:33:10 +03:00
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
|
2017-04-26 23:31:59 +03:00
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, UnscaledFont> mUnscaledFonts;
|
|
|
|
nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
|
2018-09-25 05:43:41 +03:00
|
|
|
nsRefPtrHashtable<nsUint64HashKey, SourceSurface>* mExternalSurfaces;
|
2017-04-26 23:31:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_layout_InlineTranslator_h
|