Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / printing / pdf_metafile_cg_mac.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_PDF_METAFILE_CG_MAC_H_
6 #define PRINTING_PDF_METAFILE_CG_MAC_H_
7
8 #include <CoreFoundation/CoreFoundation.h>
9 #include <CoreGraphics/CoreGraphics.h>
10 #include <stdint.h>
11
12 #include "base/apple/scoped_cftyperef.h"
13 #include "base/component_export.h"
14 #include "printing/metafile.h"
15
16 namespace printing {
17
18 // This class creates a graphics context that renders into a PDF data stream.
19 class COMPONENT_EXPORT(PRINTING_METAFILE) PdfMetafileCg : public Metafile {
20  public:
21   PdfMetafileCg();
22   PdfMetafileCg(const PdfMetafileCg&) = delete;
23   PdfMetafileCg& operator=(const PdfMetafileCg&) = delete;
24   ~PdfMetafileCg() override;
25
26   // Metafile methods.
27   bool Init() override;
28   bool InitFromData(base::span<const uint8_t> data) override;
29   void StartPage(const gfx::Size& page_size,
30                  const gfx::Rect& content_area,
31                  float scale_factor,
32                  mojom::PageOrientation page_orientation) override;
33   bool FinishPage() override;
34   bool FinishDocument() override;
35
36   uint32_t GetDataSize() const override;
37   bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
38   bool ShouldCopySharedMemoryRegionData() const override;
39   mojom::MetafileDataType GetDataType() const override;
40
41   gfx::Rect GetPageBounds(unsigned int page_number) const override;
42   unsigned int GetPageCount() const override;
43
44   // Note: The returned context *must not be retained* past Close(). If it is,
45   // the data returned from GetData will not be valid PDF data.
46   CGContextRef context() const override;
47
48   bool RenderPage(unsigned int page_number,
49                   printing::NativeDrawingContext context,
50                   const CGRect& rect,
51                   bool autorotate,
52                   bool fit_to_page) const override;
53
54  private:
55   // Returns a CGPDFDocumentRef version of `pdf_data_`.
56   CGPDFDocumentRef GetPDFDocument() const;
57
58   // Context for rendering to the pdf.
59   base::apple::ScopedCFTypeRef<CGContextRef> context_;
60
61   // PDF backing store.
62   base::apple::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
63
64   // Lazily-created CGPDFDocument representation of `pdf_data_`.
65   mutable base::apple::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
66
67   // Whether or not a page is currently open.
68   bool page_is_open_ = false;
69 };
70
71 }  // namespace printing
72
73 #endif  // PRINTING_PDF_METAFILE_CG_MAC_H_