| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/surfaceless_gl_renderer.h" | 5 #include "ui/ozone/demo/surfaceless_gl_renderer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "ui/display/types/display_snapshot.h" | 13 #include "ui/display/types/display_snapshot.h" |
| 14 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
| 15 #include "ui/gl/gl_context.h" | 15 #include "ui/gl/gl_context.h" |
| 16 #include "ui/gl/gl_image.h" | 16 #include "ui/gl/gl_image.h" |
| 17 #include "ui/gl/gl_image_native_pixmap.h" |
| 17 #include "ui/gl/gl_surface.h" | 18 #include "ui/gl/gl_surface.h" |
| 18 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h" | |
| 19 #include "ui/ozone/public/ozone_platform.h" | 19 #include "ui/ozone/public/ozone_platform.h" |
| 20 #include "ui/ozone/public/surface_factory_ozone.h" | 20 #include "ui/ozone/public/surface_factory_ozone.h" |
| 21 | 21 |
| 22 namespace ui { | 22 namespace ui { |
| 23 | 23 |
| 24 SurfacelessGlRenderer::BufferWrapper::BufferWrapper() { | 24 SurfacelessGlRenderer::BufferWrapper::BufferWrapper() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 SurfacelessGlRenderer::BufferWrapper::~BufferWrapper() { | 27 SurfacelessGlRenderer::BufferWrapper::~BufferWrapper() { |
| 28 if (gl_fb_) | 28 if (gl_fb_) |
| 29 glDeleteFramebuffersEXT(1, &gl_fb_); | 29 glDeleteFramebuffersEXT(1, &gl_fb_); |
| 30 | 30 |
| 31 if (gl_tex_) { | 31 if (gl_tex_) { |
| 32 image_->ReleaseTexImage(GL_TEXTURE_2D); | 32 image_->ReleaseTexImage(GL_TEXTURE_2D); |
| 33 glDeleteTextures(1, &gl_tex_); | 33 glDeleteTextures(1, &gl_tex_); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool SurfacelessGlRenderer::BufferWrapper::Initialize( | 37 bool SurfacelessGlRenderer::BufferWrapper::Initialize( |
| 38 gfx::AcceleratedWidget widget, | 38 gfx::AcceleratedWidget widget, |
| 39 const gfx::Size& size) { | 39 const gfx::Size& size) { |
| 40 glGenFramebuffersEXT(1, &gl_fb_); | 40 glGenFramebuffersEXT(1, &gl_fb_); |
| 41 glGenTextures(1, &gl_tex_); | 41 glGenTextures(1, &gl_tex_); |
| 42 | 42 |
| 43 gfx::BufferFormat format = display::DisplaySnapshot::PrimaryFormat(); | 43 gfx::BufferFormat format = display::DisplaySnapshot::PrimaryFormat(); |
| 44 scoped_refptr<NativePixmap> pixmap = | 44 scoped_refptr<NativePixmap> pixmap = |
| 45 OzonePlatform::GetInstance() | 45 OzonePlatform::GetInstance() |
| 46 ->GetSurfaceFactoryOzone() | 46 ->GetSurfaceFactoryOzone() |
| 47 ->CreateNativePixmap(widget, size, format, gfx::BufferUsage::SCANOUT); | 47 ->CreateNativePixmap(widget, size, format, gfx::BufferUsage::SCANOUT); |
| 48 scoped_refptr<ui::GLImageOzoneNativePixmap> image( | 48 scoped_refptr<ui::GLImageNativePixmap> image( |
| 49 new ui::GLImageOzoneNativePixmap(size, GL_RGB)); | 49 new ui::GLImageNativePixmap(size, GL_RGB)); |
| 50 if (!image->Initialize(pixmap.get(), format)) { | 50 if (!image->Initialize(pixmap.get(), format)) { |
| 51 LOG(ERROR) << "Failed to create GLImage"; | 51 LOG(ERROR) << "Failed to create GLImage"; |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 image_ = image; | 54 image_ = image; |
| 55 | 55 |
| 56 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_); | 56 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_); |
| 57 glBindTexture(GL_TEXTURE_2D, gl_tex_); | 57 glBindTexture(GL_TEXTURE_2D, gl_tex_); |
| 58 image_->BindTexImage(GL_TEXTURE_2D); | 58 image_->BindTexImage(GL_TEXTURE_2D); |
| 59 | 59 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 case gfx::SwapResult::SWAP_ACK: | 156 case gfx::SwapResult::SWAP_ACK: |
| 157 GlRenderer::PostRenderFrameTask(result); | 157 GlRenderer::PostRenderFrameTask(result); |
| 158 break; | 158 break; |
| 159 case gfx::SwapResult::SWAP_FAILED: | 159 case gfx::SwapResult::SWAP_FAILED: |
| 160 LOG(FATAL) << "Failed to swap buffers"; | 160 LOG(FATAL) << "Failed to swap buffers"; |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace ui | 165 } // namespace ui |
| OLD | NEW |