Fix race condition in WebstoreInstallHelper.
[chromium-blink-merge.git] / printing / pdf_metafile_skia.h
blobcab518accd7a433e1b767fe4fb23088ebc510d8f
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_SKIA_H_
6 #define PRINTING_PDF_METAFILE_SKIA_H_
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "build/build_config.h"
12 #include "printing/metafile.h"
13 #include "skia/ext/platform_canvas.h"
15 #if defined(OS_WIN)
16 #include <windows.h>
17 #endif
19 class SkBaseDevice;
21 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
22 namespace base {
23 struct FileDescriptor;
25 #endif
27 namespace printing {
29 struct PdfMetafileSkiaData;
31 // This class uses Skia graphics library to generate a PDF document.
32 class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
33 public:
34 PdfMetafileSkia();
35 ~PdfMetafileSkia() override;
37 // Metafile methods.
38 bool Init() override;
39 bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
41 bool StartPage(const gfx::Size& page_size,
42 const gfx::Rect& content_area,
43 const float& scale_factor) override;
44 bool FinishPage() override;
45 bool FinishDocument() override;
47 uint32 GetDataSize() const override;
48 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
50 gfx::Rect GetPageBounds(unsigned int page_number) const override;
51 unsigned int GetPageCount() const override;
53 gfx::NativeDrawingContext context() const override;
55 #if defined(OS_WIN)
56 bool Playback(gfx::NativeDrawingContext hdc,
57 const RECT* rect) const override;
58 bool SafePlayback(gfx::NativeDrawingContext hdc) const override;
59 #elif defined(OS_MACOSX)
60 bool RenderPage(unsigned int page_number,
61 gfx::NativeDrawingContext context,
62 const CGRect rect,
63 const MacRenderPageParams& params) const override;
64 #endif
66 bool SaveTo(base::File* file) const override;
68 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
69 // TODO(vitalybuka): replace with SaveTo().
70 bool SaveToFD(const base::FileDescriptor& fd) const;
71 #endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
73 // Return a new metafile containing just the current page in draft mode.
74 scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
76 // This method calls StartPage and then returns an appropriate
77 // PlatformCanvas implementation bound to the context created by
78 // StartPage or NULL on error. The skia::PlatformCanvas pointer that
79 // is returned is owned by this PdfMetafileSkia object and does not
80 // need to be ref()ed or unref()ed. The canvas will remain valid
81 // until FinishPage() or FinishDocument() is called.
82 skia::PlatformCanvas* GetVectorCanvasForNewPage(const gfx::Size& page_size,
83 const gfx::Rect& content_area,
84 const float& scale_factor);
86 private:
87 scoped_ptr<PdfMetafileSkiaData> data_;
89 DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
92 } // namespace printing
94 #endif // PRINTING_PDF_METAFILE_SKIA_H_