Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 "gfxD2DSurface.h"
7 #include "cairo.h"
8 #include "cairo-win32.h"
9 #include "gfxWindowsPlatform.h"
11 gfxD2DSurface::gfxD2DSurface(HWND aWnd, gfxContentType aContent)
12 {
13 Init(cairo_d2d_surface_create_for_hwnd(
14 gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
15 aWnd,
16 (cairo_content_t)(int)aContent));
17 }
19 gfxD2DSurface::gfxD2DSurface(HANDLE handle, gfxContentType aContent)
20 {
21 Init(cairo_d2d_surface_create_for_handle(
22 gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
23 handle,
24 (cairo_content_t)(int)aContent));
25 }
27 gfxD2DSurface::gfxD2DSurface(ID3D10Texture2D *texture, gfxContentType aContent)
28 {
29 Init(cairo_d2d_surface_create_for_texture(
30 gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
31 texture,
32 (cairo_content_t)(int)aContent));
33 }
35 gfxD2DSurface::gfxD2DSurface(cairo_surface_t *csurf)
36 {
37 Init(csurf, true);
38 }
40 gfxD2DSurface::gfxD2DSurface(const gfxIntSize& size,
41 gfxImageFormat imageFormat)
42 {
43 Init(cairo_d2d_surface_create(
44 gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
45 (cairo_format_t)(int)imageFormat,
46 size.width, size.height));
47 }
49 gfxD2DSurface::~gfxD2DSurface()
50 {
51 }
53 void
54 gfxD2DSurface::Present()
55 {
56 cairo_d2d_present_backbuffer(CairoSurface());
57 }
59 void
60 gfxD2DSurface::Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip)
61 {
62 cairo_rectangle_t rect;
63 rect.x = aClip.x;
64 rect.y = aClip.y;
65 rect.width = aClip.width;
66 rect.height = aClip.height;
67 cairo_d2d_scroll(CairoSurface(), aDelta.x, aDelta.y, &rect);
68 }
70 ID3D10Texture2D*
71 gfxD2DSurface::GetTexture()
72 {
73 return cairo_d2d_surface_get_texture(CairoSurface());
74 }
76 HDC
77 gfxD2DSurface::GetDC(bool aRetainContents)
78 {
79 return cairo_d2d_get_dc(CairoSurface(), aRetainContents);
80 }
82 void
83 gfxD2DSurface::ReleaseDC(const nsIntRect *aUpdatedRect)
84 {
85 if (!aUpdatedRect) {
86 return cairo_d2d_release_dc(CairoSurface(), nullptr);
87 }
89 cairo_rectangle_int_t rect;
90 rect.x = aUpdatedRect->x;
91 rect.y = aUpdatedRect->y;
92 rect.width = aUpdatedRect->width;
93 rect.height = aUpdatedRect->height;
94 cairo_d2d_release_dc(CairoSurface(), &rect);
95 }
97 const gfxIntSize gfxD2DSurface::GetSize() const
98 {
99 return gfxIntSize(cairo_d2d_surface_get_width(mSurface),
100 cairo_d2d_surface_get_height(mSurface));
101 }