summaryrefslogtreecommitdiffstats
path: root/gpu/demos/framework
diff options
context:
space:
mode:
Diffstat (limited to 'gpu/demos/framework')
-rw-r--r--gpu/demos/framework/platform.h25
-rw-r--r--gpu/demos/framework/window.cc143
-rw-r--r--gpu/demos/framework/window.h16
-rw-r--r--gpu/demos/framework/window_linux.cc24
-rw-r--r--gpu/demos/framework/window_mac.mm24
-rw-r--r--gpu/demos/framework/window_win.cc100
6 files changed, 192 insertions, 140 deletions
diff --git a/gpu/demos/framework/platform.h b/gpu/demos/framework/platform.h
deleted file mode 100644
index cd6c003..0000000
--- a/gpu/demos/framework/platform.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Platform-specific types and definitions for native widget handles.
-
-#ifndef GPU_DEMOS_FRAMEWORK_PLATFORM_H_
-#define GPU_DEMOS_FRAMEWORK_PLATFORM_H_
-
-#ifdef _WINDOWS
-#include <windows.h>
-#endif // _WINDOWS
-
-#include "build/build_config.h"
-
-namespace gpu {
-namespace demos {
-
-#if defined(OS_WIN)
-typedef HWND NativeWindowHandle;
-#endif // defined(OS_WIN)
-
-} // namespace demos
-} // namespace gpu
-#endif // GPU_DEMOS_FRAMEWORK_PLATFORM_H_
diff --git a/gpu/demos/framework/window.cc b/gpu/demos/framework/window.cc
index 41538d5..d258792 100644
--- a/gpu/demos/framework/window.cc
+++ b/gpu/demos/framework/window.cc
@@ -8,6 +8,7 @@
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "gpu/command_buffer/service/gpu_processor.h"
+#include "gpu/demos/framework/demo.h"
#include "gpu/demos/framework/demo_factory.h"
using gpu::Buffer;
@@ -16,81 +17,39 @@ using gpu::GPUProcessor;
using gpu::gles2::GLES2CmdHelper;
using gpu::gles2::GLES2Implementation;
-// TODO(alokp): Make this class cross-platform. Investigate using SDL.
namespace {
const int32 kCommandBufferSize = 1024 * 1024;
const int32 kTransferBufferSize = 512 * 1024;
+} // namespace.
-LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
- WPARAM w_param, LPARAM l_param) {
- LRESULT result = 0;
- switch (msg) {
- case WM_CLOSE:
- ::DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- ::PostQuitMessage(0);
- break;
- case WM_ERASEBKGND:
- break;
- case WM_PAINT: {
- gpu::demos::Window* window = reinterpret_cast<gpu::demos::Window*>(
- GetWindowLongPtr(hwnd, GWL_USERDATA));
- if (window != NULL) window->OnPaint();
- ::ValidateRect(hwnd, NULL);
- break;
- }
- default:
- result = ::DefWindowProc(hwnd, msg, w_param, l_param);
- break;
- }
- return result;
+namespace gpu {
+namespace demos {
+
+Window::Window()
+ : window_handle_(NULL),
+ demo_(CreateDemo()) {
+}
+
+Window::~Window() {
}
-HWND CreateNativeWindow(const wchar_t* title, int width, int height,
- LONG_PTR user_data) {
- WNDCLASS wnd_class = {0};
- HINSTANCE instance = GetModuleHandle(NULL);
- wnd_class.style = CS_OWNDC;
- wnd_class.lpfnWndProc = WindowProc;
- wnd_class.hInstance = instance;
- wnd_class.hbrBackground =
- reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
- wnd_class.lpszClassName = L"gpu_demo";
- if (!RegisterClass(&wnd_class)) return NULL;
-
- DWORD wnd_style = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
- RECT wnd_rect;
- wnd_rect.left = 0;
- wnd_rect.top = 0;
- wnd_rect.right = width;
- wnd_rect.bottom = height;
- AdjustWindowRect(&wnd_rect, wnd_style, FALSE);
-
- HWND hwnd = CreateWindow(
- wnd_class.lpszClassName,
- title,
- wnd_style,
- 0,
- 0,
- wnd_rect.right - wnd_rect.left,
- wnd_rect.bottom - wnd_rect.top,
- NULL,
- NULL,
- instance,
- NULL);
- if (hwnd == NULL) return NULL;
-
- ShowWindow(hwnd, SW_SHOWNORMAL);
- // Set this to the GWL_USERDATA so that it is available to WindowProc.
- SetWindowLongPtr(hwnd, GWL_USERDATA, user_data);
-
- return hwnd;
+bool Window::Init(int width, int height) {
+ window_handle_ = CreateNativeWindow(demo_->Title(), width, height);
+ if (window_handle_ == NULL)
+ return false;
+ if (!CreateRenderContext(PluginWindow(window_handle_)))
+ return false;
+
+ demo_->InitWindowSize(width, height);
+ return demo_->InitGL();
}
-bool InitRenderContext(HWND hwnd) {
- CHECK(hwnd);
+void Window::OnPaint() {
+ demo_->Draw();
+ ::gles2::GetGLContext()->SwapBuffers();
+}
+bool Window::CreateRenderContext(gfx::PluginWindowHandle hwnd) {
scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService);
if (!command_buffer->Initialize(kCommandBufferSize)) {
return false;
@@ -117,54 +76,14 @@ bool InitRenderContext(HWND hwnd) {
command_buffer->GetTransferBuffer(transfer_buffer_id);
if (transfer_buffer.ptr == NULL) return false;
- gles2::Initialize();
- gles2::SetGLContext(new GLES2Implementation(helper,
- transfer_buffer.size,
- transfer_buffer.ptr,
- transfer_buffer_id));
+ ::gles2::Initialize();
+ ::gles2::SetGLContext(new GLES2Implementation(helper,
+ transfer_buffer.size,
+ transfer_buffer.ptr,
+ transfer_buffer_id));
return command_buffer.release() != NULL;
}
-} // namespace.
-
-namespace gpu {
-namespace demos {
-
-Window::Window()
- : window_handle_(NULL),
- demo_(CreateDemo()) {
-}
-
-Window::~Window() {
-}
-
-bool Window::Init(int width, int height) {
- window_handle_ = CreateNativeWindow(demo_->Title(), width, height,
- reinterpret_cast<LONG_PTR>(this));
- if (window_handle_ == NULL) return false;
- if (!InitRenderContext(window_handle_)) return false;
-
- demo_->InitWindowSize(width, height);
- return demo_->InitGL();
-}
-
-void Window::MainLoop() {
- MSG msg;
- bool done = false;
- while (!done) {
- while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message == WM_QUIT) done = true;
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- // Message queue is empty and application has not quit yet - keep painting.
- if (!done) ::UpdateWindow(window_handle_);
- }
-}
-
-void Window::OnPaint() {
- demo_->Draw();
- ::gles2::GetGLContext()->SwapBuffers();
-}
} // namespace demos
} // namespace gpu
+
diff --git a/gpu/demos/framework/window.h b/gpu/demos/framework/window.h
index dade945..a84ecf8 100644
--- a/gpu/demos/framework/window.h
+++ b/gpu/demos/framework/window.h
@@ -5,13 +5,14 @@
#ifndef GPU_DEMOS_FRAMEWORK_WINDOW_H_
#define GPU_DEMOS_FRAMEWORK_WINDOW_H_
+#include "app/gfx/native_widget_types.h"
#include "base/scoped_ptr.h"
-#include "gpu/demos/framework/demo.h"
-#include "gpu/demos/framework/platform.h"
namespace gpu {
namespace demos {
+class Demo;
+
// Acts as a framework for standalone demos. It creates a window and delegates
// all events to demo to perform rendering and other tasks.
class Window {
@@ -28,7 +29,15 @@ class Window {
void OnPaint();
private:
- NativeWindowHandle window_handle_;
+ // Creates and shows a native window with the given title and dimensions.
+ gfx::NativeWindow CreateNativeWindow(const wchar_t* title,
+ int width, int height);
+ // Converts native window handle to NPAPI plugin window handle.
+ gfx::PluginWindowHandle PluginWindow(gfx::NativeWindow hwnd);
+ // Creates an OpenGL ES 2.0 rendering context for the given window.
+ bool CreateRenderContext(gfx::PluginWindowHandle hwnd);
+
+ gfx::NativeWindow window_handle_;
scoped_ptr<Demo> demo_;
DISALLOW_COPY_AND_ASSIGN(Window);
@@ -37,3 +46,4 @@ class Window {
} // namespace demos
} // namespace gpu
#endif // GPU_DEMOS_FRAMEWORK_WINDOW_H_
+
diff --git a/gpu/demos/framework/window_linux.cc b/gpu/demos/framework/window_linux.cc
new file mode 100644
index 0000000..4f07a24
--- /dev/null
+++ b/gpu/demos/framework/window_linux.cc
@@ -0,0 +1,24 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/demos/framework/window.h"
+
+namespace gpu {
+namespace demos {
+
+void Window::MainLoop() {
+}
+
+gfx::NativeWindow Window::CreateNativeWindow(const wchar_t* title,
+ int width, int height) {
+ return NULL;
+}
+
+gfx::PluginWindowHandle Window::PluginWindow(gfx::NativeWindow hwnd) {
+ return gfx::kNullPluginWindow;
+}
+
+} // namespace demos
+} // namespace gpu
+
diff --git a/gpu/demos/framework/window_mac.mm b/gpu/demos/framework/window_mac.mm
new file mode 100644
index 0000000..4f07a24
--- /dev/null
+++ b/gpu/demos/framework/window_mac.mm
@@ -0,0 +1,24 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/demos/framework/window.h"
+
+namespace gpu {
+namespace demos {
+
+void Window::MainLoop() {
+}
+
+gfx::NativeWindow Window::CreateNativeWindow(const wchar_t* title,
+ int width, int height) {
+ return NULL;
+}
+
+gfx::PluginWindowHandle Window::PluginWindow(gfx::NativeWindow hwnd) {
+ return gfx::kNullPluginWindow;
+}
+
+} // namespace demos
+} // namespace gpu
+
diff --git a/gpu/demos/framework/window_win.cc b/gpu/demos/framework/window_win.cc
new file mode 100644
index 0000000..62b2771
--- /dev/null
+++ b/gpu/demos/framework/window_win.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/demos/framework/window.h"
+
+namespace {
+LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
+ WPARAM w_param, LPARAM l_param) {
+ LRESULT result = 0;
+ switch (msg) {
+ case WM_CLOSE:
+ ::DestroyWindow(hwnd);
+ break;
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ break;
+ case WM_ERASEBKGND:
+ break;
+ case WM_PAINT: {
+ gpu::demos::Window* window = reinterpret_cast<gpu::demos::Window*>(
+ GetWindowLongPtr(hwnd, GWL_USERDATA));
+ if (window != NULL) window->OnPaint();
+ ::ValidateRect(hwnd, NULL);
+ break;
+ }
+ default:
+ result = ::DefWindowProc(hwnd, msg, w_param, l_param);
+ break;
+ }
+ return result;
+}
+} // namespace.
+
+namespace gpu {
+namespace demos {
+
+void Window::MainLoop() {
+ // Set this to the GWL_USERDATA so that it is available to WindowProc.
+ SetWindowLongPtr(window_handle_, GWL_USERDATA,
+ reinterpret_cast<LONG_PTR>(this));
+
+ MSG msg;
+ bool done = false;
+ while (!done) {
+ while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT) done = true;
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+ }
+ // Message queue is empty and application has not quit yet - keep painting.
+ if (!done) ::UpdateWindow(window_handle_);
+ }
+}
+
+gfx::NativeWindow Window::CreateNativeWindow(const wchar_t* title,
+ int width, int height) {
+ WNDCLASS wnd_class = {0};
+ HINSTANCE instance = GetModuleHandle(NULL);
+ wnd_class.style = CS_OWNDC;
+ wnd_class.lpfnWndProc = WindowProc;
+ wnd_class.hInstance = instance;
+ wnd_class.hbrBackground =
+ reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
+ wnd_class.lpszClassName = L"gpu_demo";
+ if (!RegisterClass(&wnd_class)) return NULL;
+
+ DWORD wnd_style = WS_VISIBLE | WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION;
+ RECT wnd_rect;
+ wnd_rect.left = 0;
+ wnd_rect.top = 0;
+ wnd_rect.right = width;
+ wnd_rect.bottom = height;
+ AdjustWindowRect(&wnd_rect, wnd_style, FALSE);
+
+ HWND hwnd = CreateWindow(
+ wnd_class.lpszClassName,
+ title,
+ wnd_style,
+ 0,
+ 0,
+ wnd_rect.right - wnd_rect.left,
+ wnd_rect.bottom - wnd_rect.top,
+ NULL,
+ NULL,
+ instance,
+ NULL);
+ if (hwnd == NULL) return NULL;
+
+ ShowWindow(hwnd, SW_SHOWNORMAL);
+ return hwnd;
+}
+
+gfx::PluginWindowHandle Window::PluginWindow(gfx::NativeWindow hwnd) {
+ return hwnd;
+}
+
+} // namespace demos
+} // namespace gpu
+