PrintTranslator.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_layout_PrintTranslator_h
  6. #define mozilla_layout_PrintTranslator_h
  7. #include <istream>
  8. #include "mozilla/gfx/2D.h"
  9. #include "mozilla/gfx/Filters.h"
  10. #include "mozilla/gfx/RecordedEvent.h"
  11. #include "nsRefPtrHashtable.h"
  12. class nsDeviceContext;
  13. namespace mozilla {
  14. namespace layout {
  15. using gfx::Translator;
  16. using gfx::ReferencePtr;
  17. using gfx::DrawTarget;
  18. using gfx::Path;
  19. using gfx::SourceSurface;
  20. using gfx::FilterNode;
  21. using gfx::GradientStops;
  22. using gfx::ScaledFont;
  23. using gfx::NativeFontResource;
  24. class PrintTranslator final : public Translator
  25. {
  26. public:
  27. explicit PrintTranslator(nsDeviceContext* aDeviceContext);
  28. bool TranslateRecording(std::istream& aRecording);
  29. DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final
  30. {
  31. DrawTarget* result = mDrawTargets.GetWeak(aRefPtr);
  32. MOZ_ASSERT(result);
  33. return result;
  34. }
  35. Path* LookupPath(ReferencePtr aRefPtr) final
  36. {
  37. Path* result = mPaths.GetWeak(aRefPtr);
  38. MOZ_ASSERT(result);
  39. return result;
  40. }
  41. SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final
  42. {
  43. SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
  44. MOZ_ASSERT(result);
  45. return result;
  46. }
  47. FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final
  48. {
  49. FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
  50. MOZ_ASSERT(result);
  51. return result;
  52. }
  53. GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final
  54. {
  55. GradientStops* result = mGradientStops.GetWeak(aRefPtr);
  56. MOZ_ASSERT(result);
  57. return result;
  58. }
  59. ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final
  60. {
  61. ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
  62. MOZ_ASSERT(result);
  63. return result;
  64. }
  65. NativeFontResource* LookupNativeFontResource(uint64_t aKey) final
  66. {
  67. NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
  68. MOZ_ASSERT(result);
  69. return result;
  70. }
  71. void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) final
  72. {
  73. mDrawTargets.Put(aRefPtr, aDT);
  74. }
  75. void AddPath(ReferencePtr aRefPtr, Path *aPath) final
  76. {
  77. mPaths.Put(aRefPtr, aPath);
  78. }
  79. void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aSurface) final
  80. {
  81. mSourceSurfaces.Put(aRefPtr, aSurface);
  82. }
  83. void AddFilterNode(ReferencePtr aRefPtr, FilterNode *aFilter) final
  84. {
  85. mFilterNodes.Put(aRefPtr, aFilter);
  86. }
  87. void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aStops) final
  88. {
  89. mGradientStops.Put(aRefPtr, aStops);
  90. }
  91. void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) final
  92. {
  93. mScaledFonts.Put(aRefPtr, aScaledFont);
  94. }
  95. void AddNativeFontResource(uint64_t aKey,
  96. NativeFontResource *aScaledFontResouce) final
  97. {
  98. mNativeFontResources.Put(aKey, aScaledFontResouce);
  99. }
  100. void RemoveDrawTarget(ReferencePtr aRefPtr) final
  101. {
  102. mDrawTargets.Remove(aRefPtr);
  103. }
  104. void RemovePath(ReferencePtr aRefPtr) final
  105. {
  106. mPaths.Remove(aRefPtr);
  107. }
  108. void RemoveSourceSurface(ReferencePtr aRefPtr) final
  109. {
  110. mSourceSurfaces.Remove(aRefPtr);
  111. }
  112. void RemoveFilterNode(ReferencePtr aRefPtr) final
  113. {
  114. mFilterNodes.Remove(aRefPtr);
  115. }
  116. void RemoveGradientStops(ReferencePtr aRefPtr) final
  117. {
  118. mGradientStops.Remove(aRefPtr);
  119. }
  120. void RemoveScaledFont(ReferencePtr aRefPtr) final
  121. {
  122. mScaledFonts.Remove(aRefPtr);
  123. }
  124. already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
  125. const gfx::IntSize &aSize,
  126. gfx::SurfaceFormat aFormat) final;
  127. mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; }
  128. mozilla::gfx::FontType GetDesiredFontType() final;
  129. private:
  130. RefPtr<nsDeviceContext> mDeviceContext;
  131. RefPtr<DrawTarget> mBaseDT;
  132. nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
  133. nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
  134. nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
  135. nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
  136. nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
  137. nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
  138. nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
  139. };
  140. } // namespace layout
  141. } // namespace mozilla
  142. #endif // mozilla_layout_PrintTranslator_h