From 5b963d0f04a1e4baf5bf9a371890bbb698520f7d Mon Sep 17 00:00:00 2001 From: "robertshield@chromium.org" Date: Fri, 7 Sep 2012 19:17:08 +0000 Subject: Integrate the Windows 8 code into the Chromium tree (take 2). This time, also: fix invalid path in metro_driver.gyp. Also, set executable bit on check_sdk_patch.py and post_build.bat. This reverts "Revert 155429 - Integrate the Windows 8 code into the Chromium tree." Original CL: https://chromiumcodereview.appspot.com/10875008 BUG=127799 TEST=A Chromium build can run as the immersive browser on Windows 8. TBR=ben Review URL: https://chromiumcodereview.appspot.com/10912152 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155444 0039d316-1c4b-4281-b951-d872f2087c98 --- win8/metro_driver/print_document_source.h | 164 ++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 win8/metro_driver/print_document_source.h (limited to 'win8/metro_driver/print_document_source.h') diff --git a/win8/metro_driver/print_document_source.h b/win8/metro_driver/print_document_source.h new file mode 100644 index 0000000..fed333e --- /dev/null +++ b/win8/metro_driver/print_document_source.h @@ -0,0 +1,164 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_METRO_DRIVER_PRINT_DOCUMENT_SOURCE_H_ +#define CHROME_BROWSER_UI_METRO_DRIVER_PRINT_DOCUMENT_SOURCE_H_ + +#include +#include +#include + +#include + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/synchronization/condition_variable.h" +#include "base/synchronization/waitable_event.h" +#include "win8/metro_driver/winrt_utils.h" + +// Hack to be removed once we don't need to build with an SDK earlier than +// 8441 where the name of the interface has been changed. +// TODO(mad): remove once we don't run mixed SDK/OS anymore. +#ifndef __IPrintPreviewDxgiPackageTarget_FWD_DEFINED__ +typedef IPrintPreviewDXGIPackageTarget IPrintPreviewDxgiPackageTarget; +#endif + + +namespace base { +class Lock; +}; // namespace base + +namespace metro_driver { + +// This class is given to Metro as a source for print documents. +// The methodless IPrintDocumentSource interface is used to identify it as such. +// Then, the other interfaces are used to generate preview and print documents. +// It also exposes a few methods for the print handler to control the document. +class PrintDocumentSource + : public mswr::RuntimeClass< + mswr::RuntimeClassFlags, + wingfx::Printing::IPrintDocumentSource, + IPrintDocumentPageSource, + IPrintPreviewPageCollection> { + public: + // A set of interfaces for the DirectX context that our parent owns + // and that don't need to change from document to document. + struct DirectXContext { + DirectXContext() {} + DirectXContext(ID3D11Device1* device_3d, + ID2D1Factory1* factory_2d, + ID2D1Device* device_2d, + ID2D1DeviceContext* context_2d, + IWICImagingFactory2* factory_wic) + : d3d_device(device_3d), + d2d_factory(factory_2d), + d2d_device(device_2d), + d2d_context(context_2d), + wic_factory(factory_wic) { + } + DirectXContext(const DirectXContext& other) + : d3d_device(other.d3d_device), + d2d_factory(other.d2d_factory), + d2d_device(other.d2d_device), + d2d_context(other.d2d_context), + wic_factory(other.wic_factory) { + } + mswr::ComPtr d3d_device; + mswr::ComPtr d2d_factory; + mswr::ComPtr d2d_device; + mswr::ComPtr d2d_context; + mswr::ComPtr wic_factory; + }; + + // Construction / Initialization. + explicit PrintDocumentSource(); + HRESULT RuntimeClassInitialize(const DirectXContext& directx_context, + base::Lock* parent_lock); + // Aborts any pending asynchronous operation. + void Abort(); + + // classic COM interface IPrintDocumentPageSource methods + STDMETHOD(GetPreviewPageCollection) ( + IPrintDocumentPackageTarget* package_target, + IPrintPreviewPageCollection** page_collection); + STDMETHOD(MakeDocument)(IInspectable* options, + IPrintDocumentPackageTarget* package_target); + + // classic COM interface IPrintPreviewPageCollection methods + STDMETHOD(Paginate)(uint32 page, IInspectable* options); + STDMETHOD(MakePage)(uint32 desired_page, float width, float height); + + // If the screen DPI changes, we must be warned here. + void ResetDpi(float dpi); + + // When the page count is known, this is called and we can setup our data. + void SetPageCount(size_t page_count); + + // Every time a page is ready, this is called and we can read the data if + // we were waiting for it, or store it for later use. + void AddPage(size_t page_number, IStream* metafile_stream); + + private: + // Print the page given in the metafile stream to the given print control. + HRESULT PrintPage(ID2D1PrintControl* print_control, + ID2D1GdiMetafile* metafile_stream, + D2D1_SIZE_F pageSize); + + // Helper function to wait for the page count to be ready. + // Returns 0 when aborted. + size_t WaitAndGetPageCount(); + + // Helper function to wait for a given page to be ready. + // Returns S_FALSE when aborted. + HRESULT WaitAndGetPage(size_t page_number, + ID2D1GdiMetafile** metafile_stream); + + DirectXContext directx_context_; + + // Once page data is available, it's added to this vector. + std::vector> pages_; + + // When page count is set, the size of this vector is set to that number. + // Then, every time page data is added to pages_, the associated condition + // variable in this vector is signaled. This is only filled when we receive + // the page count, so we must wait on page_count_ready_ before accessing + // the content of this vector. + std::vector > pages_ready_state_; + + // This event is signaled when we receive a page count from Chrome. We should + // not receive any page data before the count, so we can check this event + // while waiting for pages too, in case we ask for page data before we got + // the count, so before we properly initialized pages_ready_state_. + base::WaitableEvent page_count_ready_; + + // The preview target interface set from within GetPreviewPageCollection + // but used from within MakePage. + mswr::ComPtr dxgi_preview_target_; + + // Our parent's lock (to make sure it is initialized and destroyed early + // enough), which we use to protect access to our data members. + base::Lock* parent_lock_; + + // The width/height requested in Paginate and used in MakePage. + // TODO(mad): Height is currently not used, and width is only used for + // scaling. We need to add a way to specify width and height when we request + // pages from Chrome. + float height_; + float width_; + + // The DPI is set by Windows and we need to give it to DirectX. + float dpi_; + + // A flag identiying that we have been aborted. Needed to properly handle + // asynchronous callbacks. + bool aborted_; + + // TODO(mad): remove once we don't run mixed SDK/OS anymore. + bool using_old_preview_interface_; +}; + +} // namespace metro_driver + +#endif // CHROME_BROWSER_UI_METRO_DRIVER_PRINT_DOCUMENT_SOURCE_H_ -- cgit v1.1