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,
|
|
|
|
double aContentsScaleFactor = 1.0);
|
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,
|
|
|
|
double aContentsScaleFactor = 1.0);
|
2012-07-31 08:11:57 -07:00
|
|
|
|
2012-10-02 12:48:05 -07:00
|
|
|
MacIOSurface(const void *aIOSurfacePtr, double aContentsScaleFactor = 1.0)
|
|
|
|
: mIOSurfacePtr(aIOSurfacePtr), mContentsScaleFactor(aContentsScaleFactor) {}
|
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
|
|
|
|
// device pixel. Multiply display pixels by mContentsScaleFactor 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; }
|
2012-01-31 18:18:30 -08:00
|
|
|
size_t GetBytesPerRow();
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
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 *.
|
2012-02-02 16:22:34 -08:00
|
|
|
CGLError CGLTexImageIOSurface2D(void *ctxt,
|
2012-01-31 18:18:30 -08:00
|
|
|
GLenum internalFormat, GLenum format,
|
|
|
|
GLenum type, GLuint plane);
|
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,
|
|
|
|
double aContentsScaleFactor = 1.0);
|
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;
|
2012-01-31 18:18:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|