michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxD2DSurface.h" michael@0: #include "cairo.h" michael@0: #include "cairo-win32.h" michael@0: #include "gfxWindowsPlatform.h" michael@0: michael@0: gfxD2DSurface::gfxD2DSurface(HWND aWnd, gfxContentType aContent) michael@0: { michael@0: Init(cairo_d2d_surface_create_for_hwnd( michael@0: gfxWindowsPlatform::GetPlatform()->GetD2DDevice(), michael@0: aWnd, michael@0: (cairo_content_t)(int)aContent)); michael@0: } michael@0: michael@0: gfxD2DSurface::gfxD2DSurface(HANDLE handle, gfxContentType aContent) michael@0: { michael@0: Init(cairo_d2d_surface_create_for_handle( michael@0: gfxWindowsPlatform::GetPlatform()->GetD2DDevice(), michael@0: handle, michael@0: (cairo_content_t)(int)aContent)); michael@0: } michael@0: michael@0: gfxD2DSurface::gfxD2DSurface(ID3D10Texture2D *texture, gfxContentType aContent) michael@0: { michael@0: Init(cairo_d2d_surface_create_for_texture( michael@0: gfxWindowsPlatform::GetPlatform()->GetD2DDevice(), michael@0: texture, michael@0: (cairo_content_t)(int)aContent)); michael@0: } michael@0: michael@0: gfxD2DSurface::gfxD2DSurface(cairo_surface_t *csurf) michael@0: { michael@0: Init(csurf, true); michael@0: } michael@0: michael@0: gfxD2DSurface::gfxD2DSurface(const gfxIntSize& size, michael@0: gfxImageFormat imageFormat) michael@0: { michael@0: Init(cairo_d2d_surface_create( michael@0: gfxWindowsPlatform::GetPlatform()->GetD2DDevice(), michael@0: (cairo_format_t)(int)imageFormat, michael@0: size.width, size.height)); michael@0: } michael@0: michael@0: gfxD2DSurface::~gfxD2DSurface() michael@0: { michael@0: } michael@0: michael@0: void michael@0: gfxD2DSurface::Present() michael@0: { michael@0: cairo_d2d_present_backbuffer(CairoSurface()); michael@0: } michael@0: michael@0: void michael@0: gfxD2DSurface::Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip) michael@0: { michael@0: cairo_rectangle_t rect; michael@0: rect.x = aClip.x; michael@0: rect.y = aClip.y; michael@0: rect.width = aClip.width; michael@0: rect.height = aClip.height; michael@0: cairo_d2d_scroll(CairoSurface(), aDelta.x, aDelta.y, &rect); michael@0: } michael@0: michael@0: ID3D10Texture2D* michael@0: gfxD2DSurface::GetTexture() michael@0: { michael@0: return cairo_d2d_surface_get_texture(CairoSurface()); michael@0: } michael@0: michael@0: HDC michael@0: gfxD2DSurface::GetDC(bool aRetainContents) michael@0: { michael@0: return cairo_d2d_get_dc(CairoSurface(), aRetainContents); michael@0: } michael@0: michael@0: void michael@0: gfxD2DSurface::ReleaseDC(const nsIntRect *aUpdatedRect) michael@0: { michael@0: if (!aUpdatedRect) { michael@0: return cairo_d2d_release_dc(CairoSurface(), nullptr); michael@0: } michael@0: michael@0: cairo_rectangle_int_t rect; michael@0: rect.x = aUpdatedRect->x; michael@0: rect.y = aUpdatedRect->y; michael@0: rect.width = aUpdatedRect->width; michael@0: rect.height = aUpdatedRect->height; michael@0: cairo_d2d_release_dc(CairoSurface(), &rect); michael@0: } michael@0: michael@0: const gfxIntSize gfxD2DSurface::GetSize() const michael@0: { michael@0: return gfxIntSize(cairo_d2d_surface_get_width(mSurface), michael@0: cairo_d2d_surface_get_height(mSurface)); michael@0: }