2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2011-05-26 19:41:33 +00:00
|
|
|
|
|
|
|
#include "SharedDIBSurface.h"
|
|
|
|
|
|
|
|
#include "cairo.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
static const cairo_user_data_key_t SHAREDDIB_KEY = {0};
|
|
|
|
|
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
SharedDIBSurface::Create(HDC adc, uint32_t aWidth, uint32_t aHeight,
|
2011-05-26 19:41:33 +00:00
|
|
|
bool aTransparent)
|
|
|
|
{
|
|
|
|
nsresult rv = mSharedDIB.Create(adc, aWidth, aHeight, aTransparent);
|
|
|
|
if (NS_FAILED(rv) || !mSharedDIB.IsValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InitSurface(aWidth, aHeight, aTransparent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
SharedDIBSurface::Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
|
2011-05-26 19:41:33 +00:00
|
|
|
bool aTransparent)
|
|
|
|
{
|
|
|
|
nsresult rv = mSharedDIB.Attach(aHandle, aWidth, aHeight, aTransparent);
|
|
|
|
if (NS_FAILED(rv) || !mSharedDIB.IsValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
InitSurface(aWidth, aHeight, aTransparent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight,
|
2011-05-26 19:41:33 +00:00
|
|
|
bool aTransparent)
|
|
|
|
{
|
2015-08-14 03:46:47 +00:00
|
|
|
long stride = long(aWidth * SharedDIB::kBytesPerPixel);
|
2011-05-26 19:41:33 +00:00
|
|
|
unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits());
|
|
|
|
|
2016-01-08 04:57:38 +00:00
|
|
|
gfxImageFormat format = aTransparent ? SurfaceFormat::A8R8G8B8_UINT32 : SurfaceFormat::X8R8G8B8_UINT32;
|
2011-05-26 19:41:33 +00:00
|
|
|
|
2015-05-28 11:58:41 +00:00
|
|
|
gfxImageSurface::InitWithData(data, IntSize(aWidth, aHeight),
|
2011-05-26 19:41:33 +00:00
|
|
|
stride, format);
|
|
|
|
|
2013-07-20 08:48:55 +00:00
|
|
|
cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr);
|
2011-05-26 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SharedDIBSurface::IsSharedDIBSurface(gfxASurface* aSurface)
|
|
|
|
{
|
|
|
|
return aSurface &&
|
2014-01-23 18:26:40 +00:00
|
|
|
aSurface->GetType() == gfxSurfaceType::Image &&
|
2011-05-26 19:41:33 +00:00
|
|
|
aSurface->GetData(&SHAREDDIB_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|