зеркало из https://github.com/mozilla/gecko-dev.git
Bug 950371 - Convert the Cocoa widget consumers of imgIContainer::GetFrame to act on a Moz2D SourceSurface instead of a Thebes gfxASurface. r=mattwoodrow,mstange. Relanding after accidental backout during m-c merge in ce1a691650ef.
This commit is contained in:
Родитель
df9fcaac14
Коммит
4eec0bd2f7
|
@ -8,6 +8,7 @@
|
|||
#endif
|
||||
#include "prlog.h"
|
||||
|
||||
#include "gfxPlatform.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsClipboard.h"
|
||||
#include "nsString.h"
|
||||
|
@ -24,6 +25,10 @@
|
|||
#include "imgIContainer.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
using mozilla::gfx::DataSourceSurface;
|
||||
using mozilla::gfx::SourceSurface;
|
||||
using mozilla::RefPtr;
|
||||
|
||||
// Screenshots use the (undocumented) png pasteboard type.
|
||||
#define IMAGE_PASTEBOARD_TYPES NSTIFFPboardType, @"Apple PNG pasteboard type", nil
|
||||
|
||||
|
@ -461,18 +466,20 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
|
|||
continue;
|
||||
}
|
||||
|
||||
nsRefPtr<gfxASurface> surface =
|
||||
nsRefPtr<gfxASurface> thebesSurface =
|
||||
image->GetFrame(imgIContainer::FRAME_CURRENT,
|
||||
imgIContainer::FLAG_SYNC_DECODE);
|
||||
if (!thebesSurface) {
|
||||
continue;
|
||||
}
|
||||
RefPtr<SourceSurface> surface =
|
||||
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(
|
||||
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget(), thebesSurface);
|
||||
if (!surface) {
|
||||
continue;
|
||||
}
|
||||
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());
|
||||
if (!frame) {
|
||||
continue;
|
||||
}
|
||||
CGImageRef imageRef = NULL;
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &imageRef);
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(surface, &imageRef);
|
||||
if (NS_FAILED(rv) || !imageRef) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
|
||||
class nsIWidget;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class SourceSurface;
|
||||
}
|
||||
}
|
||||
|
||||
// Used to retain a Cocoa object for the remainder of a method's execution.
|
||||
class nsAutoRetainCocoaObject {
|
||||
public:
|
||||
|
@ -102,7 +108,9 @@ struct KeyBindingsCommand
|
|||
|
||||
class nsCocoaUtils
|
||||
{
|
||||
public:
|
||||
typedef mozilla::gfx::SourceSurface SourceSurface;
|
||||
|
||||
public:
|
||||
|
||||
// Get the backing scale factor from an object that supports this selector
|
||||
// (NSView/Window/Screen, on 10.7 or later), returning 1.0 if not supported
|
||||
|
@ -226,7 +234,8 @@ class nsCocoaUtils
|
|||
@param aResult the resulting CGImageRef
|
||||
@return NS_OK if the conversion worked, NS_ERROR_FAILURE otherwise
|
||||
*/
|
||||
static nsresult CreateCGImageFromSurface(gfxImageSurface *aFrame, CGImageRef *aResult);
|
||||
static nsresult CreateCGImageFromSurface(SourceSurface* aSurface,
|
||||
CGImageRef* aResult);
|
||||
|
||||
/** Creates a Cocoa <code>NSImage</code> from a <code>CGImageRef</code>.
|
||||
Copies the pixel data from the <code>CGImageRef</code> into a new <code>NSImage</code>.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsChildView.h"
|
||||
#include "nsMenuBarX.h"
|
||||
|
@ -17,6 +18,7 @@
|
|||
#include "nsMenuUtilsX.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsCRT.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/MiscEvents.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/TextEvents.h"
|
||||
|
@ -24,6 +26,11 @@
|
|||
using namespace mozilla;
|
||||
using namespace mozilla::widget;
|
||||
|
||||
using mozilla::gfx::DataSourceSurface;
|
||||
using mozilla::gfx::IntSize;
|
||||
using mozilla::gfx::SurfaceFormat;
|
||||
using mozilla::gfx::SourceSurface;
|
||||
|
||||
static float
|
||||
MenuBarScreenHeight()
|
||||
{
|
||||
|
@ -258,29 +265,49 @@ void nsCocoaUtils::CleanUpAfterNativeAppModalDialog()
|
|||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
nsresult nsCocoaUtils::CreateCGImageFromSurface(gfxImageSurface *aFrame, CGImageRef *aResult)
|
||||
void data_ss_release_callback(void *aDataSourceSurface,
|
||||
const void *data,
|
||||
size_t size)
|
||||
{
|
||||
if (aDataSourceSurface) {
|
||||
static_cast<DataSourceSurface*>(aDataSourceSurface)->Unmap();
|
||||
static_cast<DataSourceSurface*>(aDataSourceSurface)->Release();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t width = aFrame->Width();
|
||||
int32_t stride = aFrame->Stride();
|
||||
int32_t height = aFrame->Height();
|
||||
if ((stride % 4 != 0) || (height < 1) || (width < 1)) {
|
||||
nsresult nsCocoaUtils::CreateCGImageFromSurface(SourceSurface* aSurface,
|
||||
CGImageRef* aResult)
|
||||
{
|
||||
RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
|
||||
|
||||
MOZ_ASSERT(dataSurface->GetFormat() == SurfaceFormat::B8G8R8A8,
|
||||
"We assume B8G8R8A8 when calling CGImageCreate");
|
||||
|
||||
int32_t width = dataSurface->GetSize().width;
|
||||
int32_t height = dataSurface->GetSize().height;
|
||||
if (height < 1 || width < 1) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
DataSourceSurface::MappedSurface map;
|
||||
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// The Unmap() call happens in data_ss_release_callback
|
||||
|
||||
// Create a CGImageRef with the bits from the image, taking into account
|
||||
// the alpha ordering and endianness of the machine so we don't have to
|
||||
// touch the bits ourselves.
|
||||
CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(NULL,
|
||||
aFrame->Data(),
|
||||
stride * height,
|
||||
NULL);
|
||||
CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(dataSurface.forget().drop(),
|
||||
map.mData,
|
||||
map.mStride * height,
|
||||
data_ss_release_callback);
|
||||
CGColorSpaceRef colorSpace = ::CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
||||
*aResult = ::CGImageCreate(width,
|
||||
height,
|
||||
8,
|
||||
32,
|
||||
stride,
|
||||
map.mStride,
|
||||
colorSpace,
|
||||
kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst,
|
||||
dataProvider,
|
||||
|
@ -348,7 +375,7 @@ nsresult nsCocoaUtils::CreateNSImageFromCGImage(CGImageRef aInputImage, NSImage
|
|||
|
||||
nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, uint32_t aWhichFrame, NSImage **aResult, CGFloat scaleFactor)
|
||||
{
|
||||
nsRefPtr<gfxImageSurface> frame;
|
||||
RefPtr<SourceSurface> surface;
|
||||
int32_t width = 0, height = 0;
|
||||
aImage->GetWidth(&width);
|
||||
aImage->GetHeight(&height);
|
||||
|
@ -358,7 +385,8 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, ui
|
|||
int scaledWidth = (int)ceilf(width * scaleFactor);
|
||||
int scaledHeight = (int)ceilf(height * scaleFactor);
|
||||
|
||||
frame = new gfxImageSurface(gfxIntSize(scaledWidth, scaledHeight), gfxImageFormat::ARGB32);
|
||||
nsRefPtr<gfxImageSurface> frame =
|
||||
new gfxImageSurface(gfxIntSize(scaledWidth, scaledHeight), gfxImageFormat::ARGB32);
|
||||
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<gfxContext> context = new gfxContext(frame);
|
||||
|
@ -369,19 +397,27 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, ui
|
|||
nsIntRect(0, 0, width, height),
|
||||
nsIntSize(scaledWidth, scaledHeight),
|
||||
nullptr, aWhichFrame, imgIContainer::FLAG_SYNC_DECODE);
|
||||
}
|
||||
|
||||
else {
|
||||
nsRefPtr<gfxASurface> surface =
|
||||
surface =
|
||||
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, frame);
|
||||
} else {
|
||||
nsRefPtr<gfxASurface> thebesSurface =
|
||||
aImage->GetFrame(aWhichFrame, imgIContainer::FLAG_SYNC_DECODE);
|
||||
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_TRUE(thebesSurface, NS_ERROR_FAILURE);
|
||||
|
||||
frame = surface->GetAsReadableARGB32ImageSurface();
|
||||
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
||||
nsRefPtr<gfxImageSurface> thebesImageSurface =
|
||||
thebesSurface->GetAsReadableARGB32ImageSurface();
|
||||
NS_ENSURE_TRUE(thebesImageSurface, NS_ERROR_FAILURE);
|
||||
|
||||
surface =
|
||||
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr,
|
||||
thebesImageSurface);
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
|
||||
|
||||
CGImageRef imageRef = NULL;
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &imageRef);
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(surface, &imageRef);
|
||||
if (NS_FAILED(rv) || !imageRef) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,14 @@
|
|||
#include "imgRequestProxy.h"
|
||||
#include "nsMenuItemX.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
using mozilla::gfx::SourceSurface;
|
||||
using mozilla::RefPtr;
|
||||
|
||||
static const uint32_t kIconWidth = 16;
|
||||
static const uint32_t kIconHeight = 16;
|
||||
static const uint32_t kIconBitsPerComponent = 8;
|
||||
|
@ -385,18 +388,20 @@ nsMenuItemIconX::OnStopFrame(imgIRequest* aRequest)
|
|||
mImageRegionRect.SetRect(0, 0, origWidth, origHeight);
|
||||
}
|
||||
|
||||
nsRefPtr<gfxASurface> surface =
|
||||
nsRefPtr<gfxASurface> thebesSurface =
|
||||
imageContainer->GetFrame(imgIContainer::FRAME_CURRENT,
|
||||
imgIContainer::FLAG_NONE);
|
||||
if (!surface) {
|
||||
if (!thebesSurface) {
|
||||
[mNativeMenuItem setImage:nil];
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsRefPtr<gfxImageSurface> frame(surface->GetAsReadableARGB32ImageSurface());
|
||||
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
||||
RefPtr<SourceSurface> surface =
|
||||
gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr,
|
||||
thebesSurface);
|
||||
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
|
||||
|
||||
CGImageRef origImage = NULL;
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(frame, &origImage);
|
||||
nsresult rv = nsCocoaUtils::CreateCGImageFromSurface(surface, &origImage);
|
||||
if (NS_FAILED(rv) || !origImage) {
|
||||
[mNativeMenuItem setImage:nil];
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче