[M120 Migration][MM] Fix EME AD insert issue
[platform/framework/web/chromium-efl.git] / printing / metafile_skia.h
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PRINTING_METAFILE_SKIA_H_
6 #define PRINTING_METAFILE_SKIA_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11
12 #include "base/gtest_prod_util.h"
13 #include "build/build_config.h"
14 #include "cc/paint/paint_canvas.h"
15 #include "printing/common/metafile_utils.h"
16 #include "printing/metafile.h"
17 #include "printing/mojom/print.mojom-forward.h"
18 #include "skia/ext/platform_canvas.h"
19 #include "third_party/skia/include/core/SkRefCnt.h"
20 #include "ui/accessibility/ax_tree_update.h"
21
22 #if BUILDFLAG(IS_WIN)
23 #include <windows.h>
24 #endif
25
26 class SkCanvas;
27 class SkPicture;
28 class SkStreamAsset;
29
30 namespace base {
31 class UnguessableToken;
32 }  // namespace base
33
34 namespace printing {
35
36 struct MetafileSkiaData;
37
38 // This class uses Skia graphics library to generate a PDF or MSKP document.
39 class COMPONENT_EXPORT(PRINTING_METAFILE) MetafileSkia : public Metafile {
40  public:
41   // Default constructor, for mojom::SkiaDocumentType::kPDF type only.
42   // TODO(weili): we should split up this use case into a different class, see
43   //              comments before InitFromData()'s implementation.
44   MetafileSkia();
45   MetafileSkia(mojom::SkiaDocumentType type, int document_cookie);
46   MetafileSkia(const MetafileSkia&) = delete;
47   MetafileSkia& operator=(const MetafileSkia&) = delete;
48   ~MetafileSkia() override;
49
50   // Metafile methods.
51   bool Init() override;
52   bool InitFromData(base::span<const uint8_t> data) override;
53
54   void StartPage(const gfx::Size& page_size,
55                  const gfx::Rect& content_area,
56                  float scale_factor,
57                  mojom::PageOrientation page_orientation) override;
58   bool FinishPage() override;
59   bool FinishDocument() override;
60
61   uint32_t GetDataSize() const override;
62   bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
63   bool ShouldCopySharedMemoryRegionData() const override;
64   mojom::MetafileDataType GetDataType() const override;
65
66   gfx::Rect GetPageBounds(unsigned int page_number) const override;
67   unsigned int GetPageCount() const override;
68
69   printing::NativeDrawingContext context() const override;
70
71 #if BUILDFLAG(IS_WIN)
72   bool Playback(printing::NativeDrawingContext hdc,
73                 const RECT* rect) const override;
74   bool SafePlayback(printing::NativeDrawingContext hdc) const override;
75 #elif BUILDFLAG(IS_APPLE)
76   bool RenderPage(unsigned int page_number,
77                   printing::NativeDrawingContext context,
78                   const CGRect& rect,
79                   bool autorotate,
80                   bool fit_to_page) const override;
81 #endif
82
83 #if BUILDFLAG(IS_ANDROID)
84   bool SaveToFileDescriptor(int fd) const override;
85 #else
86   bool SaveTo(base::File* file) const override;
87 #endif  // BUILDFLAG(IS_ANDROID)
88
89   // Unlike FinishPage() or FinishDocument(), this is for out-of-process
90   // subframe printing. It will just serialize the content into SkPicture
91   // format and store it as final data.
92   void FinishFrameContent();
93
94   // Return a new metafile containing just the current page in draft mode.
95   std::unique_ptr<MetafileSkia> GetMetafileForCurrentPage(
96       mojom::SkiaDocumentType type);
97
98   // This method calls StartPage and then returns an appropriate
99   // PlatformCanvas implementation bound to the context created by
100   // StartPage or NULL on error.  The PaintCanvas pointer that
101   // is returned is owned by this MetafileSkia object and does not
102   // need to be ref()ed or unref()ed.  The canvas will remain valid
103   // until FinishPage() or FinishDocument() is called.
104   cc::PaintCanvas* GetVectorCanvasForNewPage(
105       const gfx::Size& page_size,
106       const gfx::Rect& content_area,
107       float scale_factor,
108       mojom::PageOrientation page_orientation);
109
110   // This is used for painting content of out-of-process subframes.
111   // For such a subframe, since the content is in another process, we create a
112   // place holder picture now, and replace it with actual content by pdf
113   // compositor service later.
114   uint32_t CreateContentForRemoteFrame(
115       const gfx::Rect& rect,
116       const base::UnguessableToken& render_proxy_token);
117
118   int GetDocumentCookie() const;
119   const ContentToProxyTokenMap& GetSubframeContentInfo() const;
120
121   void UtilizeTypefaceContext(ContentProxySet* typeface_content_info);
122
123   const ui::AXTreeUpdate& accessibility_tree() const {
124     return accessibility_tree_;
125   }
126   ui::AXTreeUpdate& accessibility_tree() { return accessibility_tree_; }
127
128  private:
129   FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, FrameContent);
130   FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, GetPageBounds);
131   FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, MultiPictureDocumentTypefaces);
132
133   void AppendPage(const SkSize& page_size, cc::PaintRecord record);
134   void AppendSubframeInfo(uint32_t content_id,
135                           const base::UnguessableToken& proxy_token,
136                           sk_sp<SkPicture> subframe_pic_holder);
137
138   // This is used for tests only.
139   SkStreamAsset* GetPdfData() const;
140
141   // Callback function used during page content drawing to replace a custom
142   // data holder with corresponding place holder SkPicture.
143   void CustomDataToSkPictureCallback(SkCanvas* canvas, uint32_t content_id);
144
145   std::unique_ptr<MetafileSkiaData> data_;
146
147   ui::AXTreeUpdate accessibility_tree_;
148 };
149
150 }  // namespace printing
151
152 #endif  // PRINTING_METAFILE_SKIA_H_