1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SharedDIBSurface.h"
13 static const cairo_user_data_key_t SHAREDDIB_KEY
= {0};
15 static const long kBytesPerPixel
= 4;
18 SharedDIBSurface::Create(HDC adc
, uint32_t aWidth
, uint32_t aHeight
,
21 nsresult rv
= mSharedDIB
.Create(adc
, aWidth
, aHeight
, aTransparent
);
22 if (NS_FAILED(rv
) || !mSharedDIB
.IsValid())
25 InitSurface(aWidth
, aHeight
, aTransparent
);
30 SharedDIBSurface::Attach(Handle aHandle
, uint32_t aWidth
, uint32_t aHeight
,
33 nsresult rv
= mSharedDIB
.Attach(aHandle
, aWidth
, aHeight
, aTransparent
);
34 if (NS_FAILED(rv
) || !mSharedDIB
.IsValid())
37 InitSurface(aWidth
, aHeight
, aTransparent
);
42 SharedDIBSurface::InitSurface(uint32_t aWidth
, uint32_t aHeight
,
45 long stride
= long(aWidth
* kBytesPerPixel
);
46 unsigned char* data
= reinterpret_cast<unsigned char*>(mSharedDIB
.GetBits());
48 gfxImageFormat format
= aTransparent
? gfxImageFormat::ARGB32
: gfxImageFormat::RGB24
;
50 gfxImageSurface::InitWithData(data
, gfxIntSize(aWidth
, aHeight
),
53 cairo_surface_set_user_data(mSurface
, &SHAREDDIB_KEY
, this, nullptr);
57 SharedDIBSurface::IsSharedDIBSurface(gfxASurface
* aSurface
)
60 aSurface
->GetType() == gfxSurfaceType::Image
&&
61 aSurface
->GetData(&SHAREDDIB_KEY
);
65 } // namespace mozilla