OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/demo/gl_renderer.h" | 5 #include "content/common/gpu/media/gl_renderer.h" |
6 | 6 |
7 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
8 #include "ui/gl/gl_context.h" | 8 #include "ui/gl/gl_context.h" |
9 #include "ui/gl/gl_surface.h" | 9 #include "ui/gl/gl_surface.h" |
10 | 10 |
11 namespace ui { | 11 namespace content { |
12 | 12 |
13 GlRenderer::GlRenderer(gfx::AcceleratedWidget widget, const gfx::Size& size) | 13 GlRenderer::GlRenderer(gfx::AcceleratedWidget widget, const gfx::Size& size) |
14 : RendererBase(widget, size) { | 14 : widget_(widget), size_(size) { |
15 } | 15 } |
16 | 16 |
17 GlRenderer::~GlRenderer() { | 17 GlRenderer::~GlRenderer() { |
18 } | 18 } |
19 | 19 |
20 bool GlRenderer::Initialize() { | 20 bool GlRenderer::Initialize() { |
21 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | 21 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); |
22 if (!surface_.get()) { | 22 if (!surface_.get()) { |
23 LOG(ERROR) << "Failed to create GL surface"; | 23 LOG(FATAL) << "Failed to create GL surface"; |
24 return false; | 24 return false; |
25 } | 25 } |
26 | 26 |
27 context_ = gfx::GLContext::CreateGLContext(NULL, surface_.get(), | 27 context_ = gfx::GLContext::CreateGLContext(NULL, surface_.get(), |
28 gfx::PreferIntegratedGpu); | 28 gfx::PreferIntegratedGpu); |
29 if (!context_.get()) { | 29 if (!context_.get()) { |
30 LOG(ERROR) << "Failed to create GL context"; | 30 LOG(FATAL) << "Failed to create GL context"; |
31 return false; | 31 return false; |
32 } | 32 } |
33 | 33 |
34 surface_->Resize(size_); | 34 surface_->Resize(size_); |
35 | 35 |
36 if (!context_->MakeCurrent(surface_.get())) { | 36 if (!context_->MakeCurrent(surface_.get())) { |
37 LOG(ERROR) << "Failed to make GL context current"; | 37 LOG(FATAL) << "Failed to make GL context current"; |
38 return false; | 38 return false; |
39 } | 39 } |
40 | 40 |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 void GlRenderer::RenderFrame() { | 44 bool GlRenderer::MakeCurrent() { |
45 float fraction = NextFraction(); | 45 return context_->MakeCurrent(surface_.get()); |
| 46 } |
46 | 47 |
47 context_->MakeCurrent(surface_.get()); | 48 void GlRenderer::SwapBuffers() { |
48 | |
49 glViewport(0, 0, size_.width(), size_.height()); | |
50 glClearColor(1 - fraction, fraction, 0.0, 1.0); | |
51 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
52 | |
53 if (!surface_->SwapBuffers()) | 49 if (!surface_->SwapBuffers()) |
54 LOG(FATAL) << "Failed to swap buffers"; | 50 LOG(FATAL) << "Failed to swap buffers"; |
55 } | 51 } |
56 | 52 |
57 } // namespace ui | 53 bool GlRenderer::IsFlipped() { |
| 54 return false; |
| 55 } |
| 56 |
| 57 void GlRenderer::BindFramebuffer(uint32_t fbo) { |
| 58 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); |
| 59 } |
| 60 |
| 61 void GlRenderer::UnbindFramebuffer() { |
| 62 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |