- add sources.
[platform/framework/web/crosswalk.git] / src / gpu / gles2_conform_support / native / egl_native_win.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 extern "C" {
6 #if defined(GLES2_CONFORM_SUPPORT_ONLY)
7 #include "gpu/gles2_conform_support/gtf/gtf_stubs.h"
8 #else
9 #include "third_party/gles2_conform/GTF_ES/glsl/GTF/Source/eglNative.h"
10 #endif
11 }
12
13 #include <string>
14
15 namespace {
16 LPCTSTR kWindowClassName = TEXT("ES2CONFORM");
17
18 LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
19                             WPARAM w_param, LPARAM l_param) {
20   LRESULT result = 0;
21   switch (msg) {
22     case WM_CLOSE:
23       ::DestroyWindow(hwnd);
24       break;
25     case WM_DESTROY:
26       ::PostQuitMessage(0);
27       break;
28     case WM_ERASEBKGND:
29       // Return a non-zero value to indicate that the background has been
30       // erased.
31       result = 1;
32       break;
33     default:
34       result = ::DefWindowProc(hwnd, msg, w_param, l_param);
35       break;
36   }
37   return result;
38 }
39 }  // namespace.
40
41 extern "C" {
42
43 GTFbool GTFNativeCreateDisplay(EGLNativeDisplayType *pNativeDisplay) {
44   *pNativeDisplay = EGL_DEFAULT_DISPLAY;
45   return GTFtrue;
46 }
47
48 void GTFNativeDestroyDisplay(EGLNativeDisplayType nativeDisplay) {
49   // Nothing to destroy since we are using EGL_DEFAULT_DISPLAY
50 }
51
52 GTFbool GTFNativeCreateWindow(EGLNativeDisplayType nativeDisplay,
53                               EGLDisplay eglDisplay, EGLConfig eglConfig,
54                               const char* title, int width, int height,
55                               EGLNativeWindowType *pNativeWindow) {
56   WNDCLASS wnd_class = {0};
57   HINSTANCE instance = GetModuleHandle(NULL);
58   wnd_class.style = CS_OWNDC;
59   wnd_class.lpfnWndProc = WindowProc;
60   wnd_class.hInstance = instance;
61   wnd_class.hbrBackground =
62       reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
63   wnd_class.lpszClassName = kWindowClassName;
64   if (!RegisterClass(&wnd_class))
65     return GTFfalse;
66
67   DWORD wnd_style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
68   RECT wnd_rect;
69   wnd_rect.left = 0;
70   wnd_rect.top = 0;
71   wnd_rect.right = width;
72   wnd_rect.bottom = height;
73   if (!AdjustWindowRect(&wnd_rect, wnd_style, FALSE))
74     return GTFfalse;
75
76 #ifdef UNICODE
77   // Convert ascii string to wide string.
78   const std::wstring wnd_title(title, title + strlen(title));
79 #else
80   const std::string wnd_title = title;
81 #endif  // UNICODE
82
83   HWND hwnd = CreateWindow(
84       wnd_class.lpszClassName,
85       wnd_title.c_str(),
86       wnd_style,
87       0,
88       0,
89       wnd_rect.right - wnd_rect.left,
90       wnd_rect.bottom - wnd_rect.top,
91       NULL,
92       NULL,
93       instance,
94       NULL);
95   if (hwnd == NULL)
96     return GTFfalse;
97
98   ShowWindow(hwnd, SW_SHOWNORMAL);
99   *pNativeWindow = hwnd;
100   return GTFtrue;
101 }
102
103 void GTFNativeDestroyWindow(EGLNativeDisplayType nativeDisplay,
104                             EGLNativeWindowType nativeWindow) {
105   DestroyWindow(nativeWindow);
106   UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
107 }
108
109 EGLImageKHR GTFCreateEGLImage(int width, int height,
110                               GLenum format, GLenum type) {
111   return (EGLImageKHR)NULL;
112 }
113
114 void GTFDestroyEGLImage(EGLImageKHR image) {
115 }
116
117 }  // extern "C"