2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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/. */
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2005-04-07 23:12:19 +04:00
|
|
|
#include "gfxWindowsSurface.h"
|
2006-08-10 02:43:06 +04:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2016-06-10 15:32:01 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2016-01-08 07:57:38 +03:00
|
|
|
#include "mozilla/gfx/HelpersCairo.h"
|
2015-06-18 09:18:00 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2006-08-10 02:43:06 +04:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
#include "cairo.h"
|
|
|
|
#include "cairo-win32.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
2006-04-05 01:54:22 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxWindowsSurface::gfxWindowsSurface(HDC dc, uint32_t flags)
|
2016-06-14 21:26:35 +03:00
|
|
|
: mOwnsDC(false), mDC(dc), mWnd(nullptr) {
|
2010-07-16 01:08:10 +04:00
|
|
|
InitWithDC(flags);
|
2005-08-20 09:36:47 +04:00
|
|
|
}
|
|
|
|
|
2015-06-01 11:26:19 +03:00
|
|
|
void gfxWindowsSurface::MakeInvalid(mozilla::gfx::IntSize& size) {
|
|
|
|
size = mozilla::gfx::IntSize(-1, -1);
|
2011-09-13 18:49:01 +04:00
|
|
|
}
|
|
|
|
|
2015-06-01 11:26:19 +03:00
|
|
|
gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize,
|
|
|
|
gfxImageFormat imageFormat)
|
2016-06-14 21:26:35 +03:00
|
|
|
: mOwnsDC(false), mWnd(nullptr) {
|
2015-06-01 11:26:19 +03:00
|
|
|
mozilla::gfx::IntSize size(realSize);
|
2016-06-10 15:32:01 +03:00
|
|
|
if (!mozilla::gfx::Factory::CheckSurfaceSize(size)) MakeInvalid(size);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-08 07:57:38 +03:00
|
|
|
cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
|
2015-09-29 07:11:52 +03:00
|
|
|
cairo_surface_t* surf =
|
|
|
|
cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-08-10 02:43:06 +04:00
|
|
|
Init(surf);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-25 06:14:39 +04:00
|
|
|
if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
|
2007-10-04 01:27:42 +04:00
|
|
|
mDC = cairo_win32_surface_get_dc(CairoSurface());
|
2013-09-25 06:14:39 +04:00
|
|
|
RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mDC = nullptr;
|
2013-09-25 06:14:39 +04:00
|
|
|
}
|
2006-08-10 02:43:06 +04:00
|
|
|
}
|
|
|
|
|
2006-04-05 01:54:22 +04:00
|
|
|
gfxWindowsSurface::gfxWindowsSurface(cairo_surface_t* csurf)
|
2016-06-14 21:26:35 +03:00
|
|
|
: mOwnsDC(false), mWnd(nullptr) {
|
2007-10-04 01:27:42 +04:00
|
|
|
if (cairo_surface_status(csurf) == 0)
|
|
|
|
mDC = cairo_win32_surface_get_dc(csurf);
|
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
mDC = nullptr;
|
2006-04-05 01:54:22 +04:00
|
|
|
|
2016-06-14 21:26:35 +03:00
|
|
|
MOZ_ASSERT(cairo_surface_get_type(csurf) !=
|
|
|
|
CAIRO_SURFACE_TYPE_WIN32_PRINTING);
|
2007-09-25 02:50:44 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
Init(csurf, true);
|
2006-04-05 01:54:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void gfxWindowsSurface::InitWithDC(uint32_t flags) {
|
2010-07-16 01:08:10 +04:00
|
|
|
if (flags & FLAG_IS_TRANSPARENT) {
|
2021-04-29 17:33:36 +03:00
|
|
|
Init(cairo_win32_surface_create_with_format(mDC, CAIRO_FORMAT_ARGB32));
|
2010-07-16 01:08:10 +04:00
|
|
|
} else {
|
|
|
|
Init(cairo_win32_surface_create(mDC));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 23:12:19 +04:00
|
|
|
gfxWindowsSurface::~gfxWindowsSurface() {
|
2006-01-31 03:00:12 +03:00
|
|
|
if (mOwnsDC) {
|
|
|
|
if (mWnd)
|
|
|
|
::ReleaseDC(mWnd, mDC);
|
|
|
|
else
|
|
|
|
::DeleteDC(mDC);
|
|
|
|
}
|
2005-04-06 05:54:26 +04:00
|
|
|
}
|
2006-02-01 08:21:59 +03:00
|
|
|
|
2013-09-05 00:53:54 +04:00
|
|
|
HDC gfxWindowsSurface::GetDC() {
|
|
|
|
return cairo_win32_surface_get_dc(CairoSurface());
|
|
|
|
}
|
|
|
|
|
2010-11-11 23:31:22 +03:00
|
|
|
already_AddRefed<gfxImageSurface> gfxWindowsSurface::GetAsImageSurface() {
|
2008-01-28 22:05:44 +03:00
|
|
|
if (!mSurfaceValid) {
|
|
|
|
NS_WARNING(
|
|
|
|
"GetImageSurface on an invalid (null) surface; who's calling this "
|
|
|
|
"without checking for surface errors?");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-01-28 22:05:44 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
CairoSurface() != nullptr,
|
|
|
|
"CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
|
2008-01-28 22:05:44 +03:00
|
|
|
|
2006-08-10 02:43:06 +04:00
|
|
|
cairo_surface_t* isurf = cairo_win32_surface_get_image(CairoSurface());
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!isurf) return nullptr;
|
2006-08-10 02:43:06 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxImageSurface> result =
|
|
|
|
gfxASurface::Wrap(isurf).downcast<gfxImageSurface>();
|
2013-09-20 13:50:05 +04:00
|
|
|
result->SetOpaqueRect(GetOpaqueRect());
|
|
|
|
|
|
|
|
return result.forget();
|
2006-08-10 02:43:06 +04:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:00:37 +04:00
|
|
|
const mozilla::gfx::IntSize gfxWindowsSurface::GetSize() const {
|
|
|
|
if (!mSurfaceValid) {
|
|
|
|
NS_WARNING(
|
|
|
|
"GetImageSurface on an invalid (null) surface; who's calling this "
|
|
|
|
"without checking for surface errors?");
|
2015-06-01 11:26:19 +03:00
|
|
|
return mozilla::gfx::IntSize(-1, -1);
|
2011-11-18 08:00:37 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
mSurface != nullptr,
|
|
|
|
"CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
|
2011-11-18 08:00:37 +04:00
|
|
|
|
2021-04-29 17:33:36 +03:00
|
|
|
int width, height;
|
|
|
|
if (cairo_win32_surface_get_size(mSurface, &width, &height) !=
|
|
|
|
CAIRO_STATUS_SUCCESS) {
|
|
|
|
return mozilla::gfx::IntSize(-1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mozilla::gfx::IntSize(width, height);
|
2011-11-18 08:00:37 +04:00
|
|
|
}
|