summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/gfxWindowsSurface.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /gfx/thebes/gfxWindowsSurface.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/thebes/gfxWindowsSurface.cpp')
-rw-r--r--gfx/thebes/gfxWindowsSurface.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/gfx/thebes/gfxWindowsSurface.cpp b/gfx/thebes/gfxWindowsSurface.cpp
new file mode 100644
index 0000000000..419c9ee696
--- /dev/null
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 20; 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 "gfxWindowsSurface.h"
+#include "gfxContext.h"
+#include "gfxPlatform.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/HelpersCairo.h"
+#include "mozilla/gfx/Logging.h"
+
+#include "cairo.h"
+#include "cairo-win32.h"
+
+#include "nsString.h"
+
+gfxWindowsSurface::gfxWindowsSurface(HDC dc, uint32_t flags)
+ : mOwnsDC(false), mDC(dc), mWnd(nullptr) {
+ InitWithDC(flags);
+}
+
+void gfxWindowsSurface::MakeInvalid(mozilla::gfx::IntSize& size) {
+ size = mozilla::gfx::IntSize(-1, -1);
+}
+
+gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize,
+ gfxImageFormat imageFormat)
+ : mOwnsDC(false), mWnd(nullptr) {
+ mozilla::gfx::IntSize size(realSize);
+ if (!mozilla::gfx::Factory::CheckSurfaceSize(size)) MakeInvalid(size);
+
+ cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
+ cairo_surface_t* surf =
+ cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
+
+ Init(surf);
+
+ if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
+ mDC = cairo_win32_surface_get_dc(CairoSurface());
+ RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
+ } else {
+ mDC = nullptr;
+ }
+}
+
+gfxWindowsSurface::gfxWindowsSurface(cairo_surface_t* csurf)
+ : mOwnsDC(false), mWnd(nullptr) {
+ if (cairo_surface_status(csurf) == 0)
+ mDC = cairo_win32_surface_get_dc(csurf);
+ else
+ mDC = nullptr;
+
+ MOZ_ASSERT(cairo_surface_get_type(csurf) !=
+ CAIRO_SURFACE_TYPE_WIN32_PRINTING);
+
+ Init(csurf, true);
+}
+
+void gfxWindowsSurface::InitWithDC(uint32_t flags) {
+ if (flags & FLAG_IS_TRANSPARENT) {
+ Init(cairo_win32_surface_create_with_format(mDC, CAIRO_FORMAT_ARGB32));
+ } else {
+ Init(cairo_win32_surface_create(mDC));
+ }
+}
+
+gfxWindowsSurface::~gfxWindowsSurface() {
+ if (mOwnsDC) {
+ if (mWnd)
+ ::ReleaseDC(mWnd, mDC);
+ else
+ ::DeleteDC(mDC);
+ }
+}
+
+HDC gfxWindowsSurface::GetDC() {
+ return cairo_win32_surface_get_dc(CairoSurface());
+}
+
+already_AddRefed<gfxImageSurface> gfxWindowsSurface::GetAsImageSurface() {
+ if (!mSurfaceValid) {
+ NS_WARNING(
+ "GetImageSurface on an invalid (null) surface; who's calling this "
+ "without checking for surface errors?");
+ return nullptr;
+ }
+
+ NS_ASSERTION(
+ CairoSurface() != nullptr,
+ "CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
+
+ cairo_surface_t* isurf = cairo_win32_surface_get_image(CairoSurface());
+ if (!isurf) return nullptr;
+
+ RefPtr<gfxImageSurface> result =
+ gfxASurface::Wrap(isurf).downcast<gfxImageSurface>();
+ result->SetOpaqueRect(GetOpaqueRect());
+
+ return result.forget();
+}
+
+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?");
+ return mozilla::gfx::IntSize(-1, -1);
+ }
+
+ NS_ASSERTION(
+ mSurface != nullptr,
+ "CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!");
+
+ 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);
+}