2012-01-31 18:18:30 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
#ifndef MacIOSurface_h__
|
|
|
|
#define MacIOSurface_h__
|
2012-01-31 18:18:30 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
|
|
|
#import <OpenGL/OpenGL.h>
|
2012-07-31 08:11:57 -07:00
|
|
|
#include "2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
class gfxASurface;
|
2012-02-16 05:20:51 -08:00
|
|
|
struct _CGLContextObject;
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
typedef _CGLContextObject* CGLContextObj;
|
2012-07-31 08:11:57 -07:00
|
|
|
typedef struct CGContext* CGContextRef;
|
|
|
|
typedef struct CGImage* CGImageRef;
|
2012-01-31 18:18:30 -08:00
|
|
|
typedef uint32_t IOSurfaceID;
|
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
class MacIOSurface : public mozilla::RefCounted<MacIOSurface> {
|
2012-01-31 18:18:30 -08:00
|
|
|
public:
|
2012-07-31 08:11:57 -07:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> CreateIOSurface(int aWidth, int aHeight,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 08:11:57 -07:00
|
|
|
static void ReleaseIOSurface(MacIOSurface *aIOSurface);
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> LookupSurface(IOSurfaceID aSurfaceID,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 08:11:57 -07:00
|
|
|
|
2013-07-17 20:24:14 -07:00
|
|
|
MacIOSurface(const void *aIOSurfacePtr, double aContentsScaleFactor = 1.0, bool aHasAlpha = true)
|
|
|
|
: mIOSurfacePtr(aIOSurfacePtr), mContentsScaleFactor(aContentsScaleFactor), mHasAlpha(aHasAlpha) {}
|
2012-07-31 08:11:57 -07:00
|
|
|
~MacIOSurface();
|
2012-01-31 18:18:30 -08:00
|
|
|
IOSurfaceID GetIOSurfaceID();
|
|
|
|
void *GetBaseAddress();
|
2012-10-02 12:48:05 -07:00
|
|
|
// GetWidth() and GetHeight() return values in "display pixels". A
|
|
|
|
// "display pixel" is the smallest fully addressable part of a display.
|
|
|
|
// But in HiDPI modes each "display pixel" corresponds to more than one
|
2013-04-24 15:31:12 -07:00
|
|
|
// device pixel. Use GetDevicePixel**() to get device pixels.
|
2012-01-31 18:18:30 -08:00
|
|
|
size_t GetWidth();
|
|
|
|
size_t GetHeight();
|
2012-10-02 12:48:05 -07:00
|
|
|
double GetContentsScaleFactor() { return mContentsScaleFactor; }
|
2013-04-24 15:31:12 -07:00
|
|
|
size_t GetDevicePixelWidth();
|
|
|
|
size_t GetDevicePixelHeight();
|
2012-01-31 18:18:30 -08:00
|
|
|
size_t GetBytesPerRow();
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
2013-07-17 20:24:14 -07:00
|
|
|
bool HasAlpha() { return mHasAlpha; }
|
2012-02-14 06:22:23 -08:00
|
|
|
// We would like to forward declare NSOpenGLContext, but it is an @interface
|
|
|
|
// and this file is also used from c++, so we use a void *.
|
2013-07-17 20:24:14 -07:00
|
|
|
CGLError CGLTexImageIOSurface2D(void *ctxt);
|
2012-07-31 08:11:57 -07:00
|
|
|
mozilla::TemporaryRef<SourceSurface> GetAsSurface();
|
|
|
|
CGContextRef CreateIOSurfaceContext();
|
|
|
|
|
|
|
|
// FIXME This doesn't really belong here
|
|
|
|
static CGImageRef CreateImageFromIOSurfaceContext(CGContextRef aContext);
|
2012-10-02 12:48:05 -07:00
|
|
|
static mozilla::TemporaryRef<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext,
|
2013-07-17 20:24:14 -07:00
|
|
|
double aContentsScaleFactor = 1.0,
|
|
|
|
bool aHasAlpha = true);
|
2012-07-31 08:11:57 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
private:
|
|
|
|
friend class nsCARenderer;
|
|
|
|
const void* mIOSurfacePtr;
|
2012-10-02 12:48:05 -07:00
|
|
|
double mContentsScaleFactor;
|
2013-07-17 20:24:14 -07:00
|
|
|
bool mHasAlpha;
|
2012-01-31 18:18:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|