Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: ui/ozone/demo/gl_renderer.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/demo/gl_renderer.h ('k') | ui/ozone/demo/ozone_demo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "ui/ozone/demo/gl_renderer.h"
6
7 #include "base/location.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/gl_context.h"
11 #include "ui/gl/gl_surface.h"
12
13 namespace ui {
14
15 GlRenderer::GlRenderer(gfx::AcceleratedWidget widget, const gfx::Size& size)
16 : RendererBase(widget, size), weak_ptr_factory_(this) {
17 }
18
19 GlRenderer::~GlRenderer() {
20 }
21
22 bool GlRenderer::Initialize() {
23 surface_ = CreateSurface();
24 if (!surface_.get()) {
25 LOG(ERROR) << "Failed to create GL surface";
26 return false;
27 }
28
29 context_ = gfx::GLContext::CreateGLContext(NULL, surface_.get(),
30 gfx::PreferIntegratedGpu);
31 if (!context_.get()) {
32 LOG(ERROR) << "Failed to create GL context";
33 return false;
34 }
35
36 if (!surface_->Resize(size_)) {
37 LOG(ERROR) << "Failed to resize GL surface";
38 return false;
39 }
40
41 if (!context_->MakeCurrent(surface_.get())) {
42 LOG(ERROR) << "Failed to make GL context current";
43 return false;
44 }
45
46 PostRenderFrameTask(gfx::SwapResult::SWAP_ACK);
47 return true;
48 }
49
50 void GlRenderer::RenderFrame() {
51 float fraction = NextFraction();
52
53 context_->MakeCurrent(surface_.get());
54
55 glViewport(0, 0, size_.width(), size_.height());
56 glClearColor(1 - fraction, fraction, 0.0, 1.0);
57 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
58
59 if (!surface_->SwapBuffersAsync(base::Bind(&GlRenderer::PostRenderFrameTask,
60 weak_ptr_factory_.GetWeakPtr())))
61 LOG(FATAL) << "Failed to swap buffers";
62 }
63
64 void GlRenderer::PostRenderFrameTask(gfx::SwapResult result) {
65 base::ThreadTaskRunnerHandle::Get()->PostTask(
66 FROM_HERE,
67 base::Bind(&GlRenderer::RenderFrame, weak_ptr_factory_.GetWeakPtr()));
68 }
69
70 scoped_refptr<gfx::GLSurface> GlRenderer::CreateSurface() {
71 gfx::SurfaceConfiguration config;
72 return gfx::GLSurface::CreateViewGLSurface(widget_, config);
73 }
74
75 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/demo/gl_renderer.h ('k') | ui/ozone/demo/ozone_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698