1a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block//
2a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// Use of this source code is governed by a BSD-style license that can be
4a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// found in the LICENSE file.
5a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block//
6a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
7a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// Config.h: Defines the egl::Config class, describing the format, type
8a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// and size for an egl::Surface. Implements EGLConfig and related functionality.
9a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// [EGL 1.4] section 3.4 page 15.
10a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
11a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#ifndef INCLUDE_CONFIG_H_
12a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#define INCLUDE_CONFIG_H_
13a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
14a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#define EGLAPI
15a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <EGL/egl.h>
16a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <d3d9.h>
17a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
18a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include <set>
19a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
20a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#include "common/angleutils.h"
21a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
22a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blocknamespace egl
23a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{
24a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockclass Display;
25a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
26a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockclass Config
27a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{
28a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block  public:
29a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    Config(D3DDISPLAYMODE displayMode, EGLint minSwapInterval, EGLint maxSwapInterval, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat, EGLint multiSample);
30a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
31a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    void setDefaults();
32a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    void set(D3DDISPLAYMODE displayMode, EGLint minSwapInterval, EGLint maxSwapInterval, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat, EGLint multiSample);
33a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLConfig getHandle() const;
34a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
35a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    const D3DDISPLAYMODE mDisplayMode;
36a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    const D3DFORMAT mRenderTargetFormat;
37a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    const D3DFORMAT mDepthStencilFormat;
38a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    const EGLint mMultiSample;
39a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
40a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mBufferSize;              // Depth of the color buffer
41a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mRedSize;                 // Bits of Red in the color buffer
42a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mGreenSize;               // Bits of Green in the color buffer
43a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mBlueSize;                // Bits of Blue in the color buffer
44a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mLuminanceSize;           // Bits of Luminance in the color buffer
45a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mAlphaSize;               // Bits of Alpha in the color buffer
46a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mAlphaMaskSize;           // Bits of Alpha Mask in the mask buffer
47a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLBoolean mBindToTextureRGB;    // True if bindable to RGB textures.
48a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLBoolean mBindToTextureRGBA;   // True if bindable to RGBA textures.
49a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLenum mColorBufferType;        // Color buffer type
50a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLenum mConfigCaveat;           // Any caveats for the configuration
51a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mConfigID;                // Unique EGLConfig identifier
52a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mConformant;              // Whether contexts created with this config are conformant
53a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mDepthSize;               // Bits of Z in the depth buffer
54a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mLevel;                   // Frame buffer level
55a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLBoolean mMatchNativePixmap;   // Match the native pixmap format
56a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mMaxPBufferWidth;         // Maximum width of pbuffer
57a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mMaxPBufferHeight;        // Maximum height of pbuffer
58a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mMaxPBufferPixels;        // Maximum size of pbuffer
59a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mMaxSwapInterval;         // Maximum swap interval
60a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mMinSwapInterval;         // Minimum swap interval
61a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLBoolean mNativeRenderable;    // EGL_TRUE if native rendering APIs can render to surface
62a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mNativeVisualID;          // Handle of corresponding native visual
63a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mNativeVisualType;        // Native visual type of the associated visual
64a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mRenderableType;          // Which client rendering APIs are supported.
65a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mSampleBuffers;           // Number of multisample buffers
66a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mSamples;                 // Number of samples per pixel
67a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mStencilSize;             // Bits of Stencil in the stencil buffer
68a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mSurfaceType;             // Which types of EGL surfaces are supported.
69a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLenum mTransparentType;        // Type of transparency supported
70a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mTransparentRedValue;     // Transparent red value
71a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mTransparentGreenValue;   // Transparent green value
72a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint mTransparentBlueValue;    // Transparent blue value
73a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block};
74a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
75a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block// Function object used by STL sorting routines for ordering Configs according to [EGL] section 3.4.1 page 24.
76a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockclass SortConfig
77a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{
78a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block  public:
79a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    explicit SortConfig(const EGLint *attribList);
80a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
81a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool operator()(const Config *x, const Config *y) const;
82a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool operator()(const Config &x, const Config &y) const;
83a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
84a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block  private:
85a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    void scanForWantedComponents(const EGLint *attribList);
86a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    EGLint wantedComponentsSize(const Config &config) const;
87a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
88a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool mWantRed;
89a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool mWantGreen;
90a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool mWantBlue;
91a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool mWantAlpha;
92a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool mWantLuminance;
93a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block};
94a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
95a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Blockclass ConfigSet
96a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block{
97a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    friend Display;
98a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
99a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block  public:
100a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    ConfigSet();
101a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
102a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    void add(D3DDISPLAYMODE displayMode, EGLint minSwapInterval, EGLint maxSwapInterval, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat, EGLint multiSample);
103a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    size_t size() const;
104a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
105a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    const egl::Config *get(EGLConfig configHandle);
106a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
107a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block  private:
108a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    DISALLOW_COPY_AND_ASSIGN(ConfigSet);
109a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
110a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    typedef std::set<Config, SortConfig> Set;
111a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    typedef Set::iterator Iterator;
112a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    Set mSet;
113a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
114a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block    static const EGLint mSortAttribs[];
115a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block};
116a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block}
117a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block
118a9bfd6c4a32dfd9cc032cb67c6ccb8d09c16f579Steve Block#endif   // INCLUDE_CONFIG_H_
119