Bug 887791 - Add MacIOSurfaceImage. r=roc

This commit is contained in:
Matt Woodrow 2013-11-01 14:54:14 +13:00
parent 9cd72931be
commit 770c0c7a31
4 changed files with 70 additions and 0 deletions

View File

@ -22,6 +22,7 @@
#ifdef XP_MACOSX
#include "mozilla/gfx/QuartzSupport.h"
#include "MacIOSurfaceImage.h"
#endif
#ifdef XP_WIN
@ -74,6 +75,12 @@ ImageFactory::CreateImage(const ImageFormat *aFormats,
img = new SharedTextureImage();
return img.forget();
}
#ifdef XP_MACOSX
if (FormatInList(aFormats, aNumFormats, MAC_IOSURFACE)) {
img = new MacIOSurfaceImage();
return img.forget();
}
#endif
#ifdef XP_WIN
if (FormatInList(aFormats, aNumFormats, D3D9_RGB32_TEXTURE)) {
img = new D3D9SurfaceImage();

View File

@ -45,6 +45,11 @@ enum ImageFormat {
*/
CAIRO_SURFACE,
/**
* A MacIOSurface object.
*/
MAC_IOSURFACE,
/**
* An bitmap image that can be shared with a remote process.
*/

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#ifndef GFX_MACIOSURFACEIMAGE_H
#define GFX_MACIOSURFACEIMAGE_H
#include "mozilla/gfx/MacIOSurface.h"
#include "gfxImageSurface.h"
namespace mozilla {
namespace layers {
class MacIOSurfaceImage : public Image {
public:
void SetSurface(MacIOSurface* aSurface) { mSurface = aSurface; }
MacIOSurface* GetSurface() { return mSurface; }
gfxIntSize GetSize() {
return gfxIntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
}
virtual already_AddRefed<gfxASurface> GetAsSurface() {
mSurface->Lock();
size_t bytesPerRow = mSurface->GetBytesPerRow();
size_t ioWidth = mSurface->GetDevicePixelWidth();
size_t ioHeight = mSurface->GetDevicePixelHeight();
unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
nsRefPtr<gfxImageSurface> imgSurface =
new gfxImageSurface(gfxIntSize(ioWidth, ioHeight), gfxImageFormatARGB32);
for (size_t i = 0; i < ioHeight; i++) {
memcpy(imgSurface->Data() + i * imgSurface->Stride(),
ioData + i * bytesPerRow, ioWidth * 4);
}
mSurface->Unlock();
return imgSurface.forget();
}
MacIOSurfaceImage() : Image(nullptr, MAC_IOSURFACE) {}
private:
RefPtr<MacIOSurface> mSurface;
};
} // layers
} // mozilla
#endif // GFX_SHAREDTEXTUREIMAGE_H

View File

@ -161,6 +161,9 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
EXPORTS.mozilla.layers += [
'opengl/GLManager.h',
]
EXPORTS += [
'MacIOSurfaceImage.h',
]
SOURCES += [
'ipc/ShadowLayerUtilsMac.cpp',
'opengl/GLManager.cpp',