1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "WindowSurfaceX11.h"
8 #include "gfxPlatform.h"
9 #include "X11UndefineNone.h"
10 
11 namespace mozilla {
12 namespace widget {
13 
WindowSurfaceX11(Display * aDisplay,Window aWindow,Visual * aVisual,unsigned int aDepth)14 WindowSurfaceX11::WindowSurfaceX11(Display* aDisplay, Window aWindow,
15                                    Visual* aVisual, unsigned int aDepth)
16     : mDisplay(aDisplay),
17       mWindow(aWindow),
18       mVisual(aVisual),
19       mDepth(aDepth),
20       mFormat(GetVisualFormat(aVisual, aDepth)) {}
21 
22 /* static */
GetVisualFormat(const Visual * aVisual,unsigned int aDepth)23 gfx::SurfaceFormat WindowSurfaceX11::GetVisualFormat(const Visual* aVisual,
24                                                      unsigned int aDepth) {
25   switch (aDepth) {
26     case 32:
27       if (aVisual->red_mask == 0xff0000 && aVisual->green_mask == 0xff00 &&
28           aVisual->blue_mask == 0xff) {
29         return gfx::SurfaceFormat::B8G8R8A8;
30       }
31       break;
32     case 24:
33       if (aVisual->red_mask == 0xff0000 && aVisual->green_mask == 0xff00 &&
34           aVisual->blue_mask == 0xff) {
35         return gfx::SurfaceFormat::B8G8R8X8;
36       }
37       break;
38     case 16:
39       if (aVisual->red_mask == 0xf800 && aVisual->green_mask == 0x07e0 &&
40           aVisual->blue_mask == 0x1f) {
41         return gfx::SurfaceFormat::R5G6B5_UINT16;
42       }
43       break;
44   }
45 
46   return gfx::SurfaceFormat::UNKNOWN;
47 }
48 
49 }  // namespace widget
50 }  // namespace mozilla
51