Chromium Code Reviews| Index: ui/ozone/demo/egl_demo.cc |
| diff --git a/ui/ozone/demo/egl_demo.cc b/ui/ozone/demo/egl_demo.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1687a4465b483e526b2aea71cd82588b0a9d58d |
| --- /dev/null |
| +++ b/ui/ozone/demo/egl_demo.cc |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2014 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 "base/at_exit.h" |
| +#include "base/command_line.h" |
| +#include "ui/gfx/geometry/size.h" |
| +#include "ui/gl/gl_bindings.h" |
| +#include "ui/gl/gl_context.h" |
| +#include "ui/gl/gl_surface.h" |
| +#include "ui/ozone/ozone_platform.h" |
| +#include "ui/ozone/public/surface_factory_ozone.h" |
| + |
| +int main(int argc, char** argv) { |
| + CommandLine::Init(argc, argv); |
| + base::AtExitManager exit_manager; |
| + |
| + ui::OzonePlatform::InitializeForUI(); |
| + if (!gfx::GLSurface::InitializeOneOff()) { |
| + LOG(ERROR) << "Failed to initialize GL"; |
| + return 1; |
| + } |
| + |
| + gfx::AcceleratedWidget widget = |
| + ui::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(); |
| + scoped_refptr<gfx::GLSurface> surface = |
| + gfx::GLSurface::CreateViewGLSurface(widget); |
|
spang
2014/07/03 18:33:23
this can fail.
dnicoara
2014/07/03 18:51:36
Done.
|
| + scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( |
| + NULL, surface.get(), gfx::PreferIntegratedGpu); |
|
spang
2014/07/03 18:33:23
also can fail.
dnicoara
2014/07/03 18:51:36
Done.
|
| + |
| + const gfx::Size window_size(800, 600); |
| + int iterations = 120; |
| + |
| + surface->Resize(window_size); |
| + context->MakeCurrent(surface.get()); |
|
spang
2014/07/03 18:33:23
can fail.
dnicoara
2014/07/03 18:51:36
Done.
|
| + |
| + for (int i = 0; i < iterations; ++i) { |
| + glViewport(0, 0, window_size.width(), window_size.height()); |
| + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| + float fraction = static_cast<float>(i) / iterations; |
| + glClearColor(1 - fraction, fraction, 0.0, 1.0); |
| + |
| + if (!surface->SwapBuffers()) { |
| + LOG(ERROR) << "Failed to swap buffers"; |
|
spang
2014/07/03 18:33:23
maybe just LOG(FATAL) ?
dnicoara
2014/07/03 18:51:36
Done.
|
| + return 1; |
| + } |
| + } |
| + |
| + return 0; |
| +} |