michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: // vim:set ts=2 sts=2 sw=2 et cin: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef dom_plugins_PluginUtilsOSX_h michael@0: #define dom_plugins_PluginUtilsOSX_h 1 michael@0: michael@0: #include "npapi.h" michael@0: #include "mozilla/gfx/QuartzSupport.h" michael@0: michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: namespace PluginUtilsOSX { michael@0: michael@0: // Need to call back into the browser's message loop to process event. michael@0: typedef void (*RemoteProcessEvents) (void*); michael@0: michael@0: NPError ShowCocoaContextMenu(void* aMenu, int aX, int aY, void* pluginModule, RemoteProcessEvents remoteEvent); michael@0: michael@0: void InvokeNativeEventLoop(); michael@0: michael@0: // Need to call back and send a cocoa draw event to the plugin. michael@0: typedef void (*DrawPluginFunc) (CGContextRef, void*, nsIntRect aUpdateRect); michael@0: michael@0: void* GetCGLayer(DrawPluginFunc aFunc, void* aPluginInstance, michael@0: bool aAvoidCGCrashes, double aContentsScaleFactor); michael@0: void ReleaseCGLayer(void* cgLayer); michael@0: void Repaint(void* cgLayer, nsIntRect aRect); michael@0: michael@0: bool SetProcessName(const char* aProcessName); michael@0: michael@0: /* michael@0: * Provides a wrapper around nsCARenderer to manage double buffering michael@0: * without having to unbind nsCARenderer on every surface swaps. michael@0: * michael@0: * The double buffer renderer begins with no initialize surfaces. michael@0: * The buffers can be initialized and cleared individually. michael@0: * Swapping still occurs regardless if the buffers are initialized. michael@0: */ michael@0: class nsDoubleBufferCARenderer { michael@0: public: michael@0: nsDoubleBufferCARenderer() : mCALayer(nullptr), mContentsScaleFactor(1.0) {} michael@0: // Returns width in "display pixels". A "display pixel" is the smallest michael@0: // fully addressable part of a display. But in HiDPI modes each "display michael@0: // pixel" corresponds to more than one device pixel. Multiply display pixels michael@0: // by mContentsScaleFactor to get device pixels. michael@0: size_t GetFrontSurfaceWidth(); michael@0: // Returns height in "display pixels". Multiply by michael@0: // mContentsScaleFactor to get device pixels. michael@0: size_t GetFrontSurfaceHeight(); michael@0: double GetFrontSurfaceContentsScaleFactor(); michael@0: // Returns width in "display pixels". Multiply by michael@0: // mContentsScaleFactor to get device pixels. michael@0: size_t GetBackSurfaceWidth(); michael@0: // Returns height in "display pixels". Multiply by michael@0: // mContentsScaleFactor to get device pixels. michael@0: size_t GetBackSurfaceHeight(); michael@0: double GetBackSurfaceContentsScaleFactor(); michael@0: IOSurfaceID GetFrontSurfaceID(); michael@0: michael@0: bool HasBackSurface(); michael@0: bool HasFrontSurface(); michael@0: bool HasCALayer(); michael@0: michael@0: void SetCALayer(void *aCALayer); michael@0: // aWidth and aHeight are in "display pixels". Multiply by michael@0: // aContentsScaleFactor to get device pixels. michael@0: bool InitFrontSurface(size_t aWidth, size_t aHeight, michael@0: double aContentsScaleFactor, michael@0: AllowOfflineRendererEnum aAllowOfflineRenderer); michael@0: void Render(); michael@0: void SwapSurfaces(); michael@0: void ClearFrontSurface(); michael@0: void ClearBackSurface(); michael@0: michael@0: double GetContentsScaleFactor() { return mContentsScaleFactor; } michael@0: michael@0: private: michael@0: void *mCALayer; michael@0: RefPtr mCARenderer; michael@0: RefPtr mFrontSurface; michael@0: RefPtr mBackSurface; michael@0: double mContentsScaleFactor; michael@0: }; michael@0: michael@0: } // namespace PluginUtilsOSX michael@0: } // namespace plugins michael@0: } // namespace mozilla michael@0: michael@0: #endif //dom_plugins_PluginUtilsOSX_h