gpu: Initialize masked alpha values to 1.0.
[chromium-blink-merge.git] / printing / pdf_metafile_cg_mac.h
blob26aed5cc876eeb8c3ae644ef0849a6acbefe8e67
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_PDF_METAFILE_CG_MAC_H_
6 #define PRINTING_PDF_METAFILE_CG_MAC_H_
8 #include <ApplicationServices/ApplicationServices.h>
9 #include <CoreFoundation/CoreFoundation.h>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/threading/thread_checker.h"
15 #include "printing/metafile.h"
17 namespace base {
18 class FilePath;
21 namespace gfx {
22 class Rect;
23 class Size;
26 namespace printing {
28 // This class creates a graphics context that renders into a PDF data stream.
29 class PRINTING_EXPORT PdfMetafileCg : public Metafile {
30 public:
31 PdfMetafileCg();
32 ~PdfMetafileCg() override;
34 // Metafile methods.
35 bool Init() override;
36 bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
38 // Not implemented on mac.
39 bool StartPage(const gfx::Size& page_size,
40 const gfx::Rect& content_area,
41 const float& scale_factor) override;
42 bool FinishPage() override;
43 bool FinishDocument() override;
45 uint32 GetDataSize() const override;
46 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
48 gfx::Rect GetPageBounds(unsigned int page_number) const override;
49 unsigned int GetPageCount() const override;
51 // Note: The returned context *must not be retained* past Close(). If it is,
52 // the data returned from GetData will not be valid PDF data.
53 CGContextRef context() const override;
55 bool RenderPage(unsigned int page_number,
56 gfx::NativeDrawingContext context,
57 const CGRect rect,
58 const MacRenderPageParams& params) const override;
60 private:
61 // Returns a CGPDFDocumentRef version of pdf_data_.
62 CGPDFDocumentRef GetPDFDocument() const;
64 base::ThreadChecker thread_checker_;
66 // Context for rendering to the pdf.
67 base::ScopedCFTypeRef<CGContextRef> context_;
69 // PDF backing store.
70 base::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
72 // Lazily-created CGPDFDocument representation of pdf_data_.
73 mutable base::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
75 // Whether or not a page is currently open.
76 bool page_is_open_;
78 // Whether this instantiation of the PdfMetafileCg owns the thread_pdf_docs.
79 bool thread_pdf_docs_owned_;
81 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCg);
84 } // namespace printing
86 #endif // PRINTING_PDF_METAFILE_CG_MAC_H_