diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /gfx/ipc/SharedDIBSurface.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/ipc/SharedDIBSurface.cpp')
-rw-r--r-- | gfx/ipc/SharedDIBSurface.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/gfx/ipc/SharedDIBSurface.cpp b/gfx/ipc/SharedDIBSurface.cpp new file mode 100644 index 000000000..696bb300c --- /dev/null +++ b/gfx/ipc/SharedDIBSurface.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; 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/. */ + +#include "SharedDIBSurface.h" + +#include "cairo.h" + +namespace mozilla { +namespace gfx { + +static const cairo_user_data_key_t SHAREDDIB_KEY = {0}; + +bool +SharedDIBSurface::Create(HDC adc, uint32_t aWidth, uint32_t aHeight, + 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 +SharedDIBSurface::Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight, + 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 +SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight, + bool aTransparent) +{ + long stride = long(aWidth * SharedDIB::kBytesPerPixel); + unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits()); + + gfxImageFormat format = aTransparent ? SurfaceFormat::A8R8G8B8_UINT32 : SurfaceFormat::X8R8G8B8_UINT32; + + gfxImageSurface::InitWithData(data, IntSize(aWidth, aHeight), + stride, format); + + cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr); +} + +bool +SharedDIBSurface::IsSharedDIBSurface(gfxASurface* aSurface) +{ + return aSurface && + aSurface->GetType() == gfxSurfaceType::Image && + aSurface->GetData(&SHAREDDIB_KEY); +} + +} // namespace gfx +} // namespace mozilla |