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

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

Issue 1258713002: ozone: unify GpuMemoryBufferFactoryOzoneNativePixmap in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linux_chromium_gn_dgb build 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/surfaceless_gl_renderer.h ('k') | ui/ozone/gpu/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/gl/gl_bindings.h" 8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_context.h" 9 #include "ui/gl/gl_context.h"
10 #include "ui/gl/gl_image.h" 10 #include "ui/gl/gl_image.h"
11 #include "ui/gl/gl_image_ozone_native_pixmap.h"
11 #include "ui/gl/gl_surface.h" 12 #include "ui/gl/gl_surface.h"
12 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h" 13 #include "ui/ozone/public/ozone_platform.h"
14 #include "ui/ozone/public/surface_factory_ozone.h"
13 15
14 namespace ui { 16 namespace ui {
15 17
16 SurfacelessGlRenderer::BufferWrapper::BufferWrapper() { 18 SurfacelessGlRenderer::BufferWrapper::BufferWrapper() {
17 } 19 }
18 20
19 SurfacelessGlRenderer::BufferWrapper::~BufferWrapper() { 21 SurfacelessGlRenderer::BufferWrapper::~BufferWrapper() {
20 if (gl_fb_) 22 if (gl_fb_)
21 glDeleteFramebuffersEXT(1, &gl_fb_); 23 glDeleteFramebuffersEXT(1, &gl_fb_);
22 24
23 if (gl_tex_) { 25 if (gl_tex_) {
24 image_->ReleaseTexImage(GL_TEXTURE_2D); 26 image_->ReleaseTexImage(GL_TEXTURE_2D);
25 glDeleteTextures(1, &gl_tex_); 27 glDeleteTextures(1, &gl_tex_);
26 image_->Destroy(true); 28 image_->Destroy(true);
27 } 29 }
28 } 30 }
29 31
30 bool SurfacelessGlRenderer::BufferWrapper::Initialize( 32 bool SurfacelessGlRenderer::BufferWrapper::Initialize(
31 GpuMemoryBufferFactoryOzoneNativePixmap* buffer_factory,
32 gfx::AcceleratedWidget widget, 33 gfx::AcceleratedWidget widget,
33 const gfx::Size& size) { 34 const gfx::Size& size) {
34 glGenFramebuffersEXT(1, &gl_fb_); 35 glGenFramebuffersEXT(1, &gl_fb_);
35 glGenTextures(1, &gl_tex_); 36 glGenTextures(1, &gl_tex_);
36 37
37 static int buffer_id_generator = 1; 38 scoped_refptr<NativePixmap> pixmap =
38 int id = buffer_id_generator++; 39 OzonePlatform::GetInstance()
39 40 ->GetSurfaceFactoryOzone()
40 buffer_factory->CreateGpuMemoryBuffer( 41 ->CreateNativePixmap(widget, size, SurfaceFactoryOzone::RGBX_8888,
41 id, size, gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT, 42 SurfaceFactoryOzone::SCANOUT);
42 1, widget); 43 scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
43 image_ = buffer_factory->CreateImageForGpuMemoryBuffer( 44 new gfx::GLImageOzoneNativePixmap(size, GL_RGB));
44 id, size, gfx::GpuMemoryBuffer::RGBX_8888, GL_RGB, 1); 45 if (!image->Initialize(pixmap.get(), gfx::GpuMemoryBuffer::RGBX_8888)) {
45 // Now that we have a reference to |image_|; we can just remove it from the 46 LOG(ERROR) << "Failed to create GLImage";
46 // factory mapping.
47 buffer_factory->DestroyGpuMemoryBuffer(id, widget);
48
49 if (!image_) {
50 LOG(ERROR) << "Failed to create GL image";
51 return false; 47 return false;
52 } 48 }
49 image_ = image;
53 50
54 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_); 51 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_);
55 glBindTexture(GL_TEXTURE_2D, gl_tex_); 52 glBindTexture(GL_TEXTURE_2D, gl_tex_);
56 image_->BindTexImage(GL_TEXTURE_2D); 53 image_->BindTexImage(GL_TEXTURE_2D);
57 54
58 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 55 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
59 gl_tex_, 0); 56 gl_tex_, 0);
60 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { 57 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
61 LOG(ERROR) << "Failed to create framebuffer " 58 LOG(ERROR) << "Failed to create framebuffer "
62 << glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 59 << glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
63 return false; 60 return false;
64 } 61 }
65 62
66 widget_ = widget; 63 widget_ = widget;
67 size_ = size; 64 size_ = size;
68 65
69 return true; 66 return true;
70 } 67 }
71 68
72 void SurfacelessGlRenderer::BufferWrapper::BindFramebuffer() { 69 void SurfacelessGlRenderer::BufferWrapper::BindFramebuffer() {
73 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_); 70 glBindFramebufferEXT(GL_FRAMEBUFFER, gl_fb_);
74 } 71 }
75 72
76 void SurfacelessGlRenderer::BufferWrapper::SchedulePlane() { 73 void SurfacelessGlRenderer::BufferWrapper::SchedulePlane() {
77 image_->ScheduleOverlayPlane(widget_, 0, gfx::OVERLAY_TRANSFORM_NONE, 74 image_->ScheduleOverlayPlane(widget_, 0, gfx::OVERLAY_TRANSFORM_NONE,
78 gfx::Rect(size_), gfx::RectF(0, 0, 1, 1)); 75 gfx::Rect(size_), gfx::RectF(0, 0, 1, 1));
79 } 76 }
80 77
81 SurfacelessGlRenderer::SurfacelessGlRenderer( 78 SurfacelessGlRenderer::SurfacelessGlRenderer(gfx::AcceleratedWidget widget,
82 gfx::AcceleratedWidget widget, 79 const gfx::Size& size)
83 const gfx::Size& size, 80 : GlRenderer(widget, size), weak_ptr_factory_(this) {}
84 GpuMemoryBufferFactoryOzoneNativePixmap* buffer_factory)
85 : GlRenderer(widget, size),
86 buffer_factory_(buffer_factory),
87 weak_ptr_factory_(this) {}
88 81
89 SurfacelessGlRenderer::~SurfacelessGlRenderer() { 82 SurfacelessGlRenderer::~SurfacelessGlRenderer() {
90 // Need to make current when deleting the framebuffer resources allocated in 83 // Need to make current when deleting the framebuffer resources allocated in
91 // the buffers. 84 // the buffers.
92 context_->MakeCurrent(surface_.get()); 85 context_->MakeCurrent(surface_.get());
93 } 86 }
94 87
95 bool SurfacelessGlRenderer::Initialize() { 88 bool SurfacelessGlRenderer::Initialize() {
96 if (!GlRenderer::Initialize()) 89 if (!GlRenderer::Initialize())
97 return false; 90 return false;
98 91
99 for (size_t i = 0; i < arraysize(buffers_); ++i) 92 for (size_t i = 0; i < arraysize(buffers_); ++i)
100 if (!buffers_[i].Initialize(buffer_factory_, widget_, size_)) 93 if (!buffers_[i].Initialize(widget_, size_))
101 return false; 94 return false;
102 95
103 PostRenderFrameTask(gfx::SwapResult::SWAP_ACK); 96 PostRenderFrameTask(gfx::SwapResult::SWAP_ACK);
104 return true; 97 return true;
105 } 98 }
106 99
107 void SurfacelessGlRenderer::RenderFrame() { 100 void SurfacelessGlRenderer::RenderFrame() {
108 float fraction = NextFraction(); 101 float fraction = NextFraction();
109 102
110 context_->MakeCurrent(surface_.get()); 103 context_->MakeCurrent(surface_.get());
111 buffers_[back_buffer_].BindFramebuffer(); 104 buffers_[back_buffer_].BindFramebuffer();
112 105
113 glViewport(0, 0, size_.width(), size_.height()); 106 glViewport(0, 0, size_.width(), size_.height());
114 glClearColor(1 - fraction, 0.0, fraction, 1.0); 107 glClearColor(1 - fraction, 0.0, fraction, 1.0);
115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 108 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
116 109
117 buffers_[back_buffer_].SchedulePlane(); 110 buffers_[back_buffer_].SchedulePlane();
118 back_buffer_ ^= 1; 111 back_buffer_ ^= 1;
119 if (!surface_->SwapBuffersAsync(base::Bind(&GlRenderer::PostRenderFrameTask, 112 if (!surface_->SwapBuffersAsync(base::Bind(&GlRenderer::PostRenderFrameTask,
120 weak_ptr_factory_.GetWeakPtr()))) 113 weak_ptr_factory_.GetWeakPtr())))
121 LOG(FATAL) << "Failed to swap buffers"; 114 LOG(FATAL) << "Failed to swap buffers";
122 } 115 }
123 116
124 scoped_refptr<gfx::GLSurface> SurfacelessGlRenderer::CreateSurface() { 117 scoped_refptr<gfx::GLSurface> SurfacelessGlRenderer::CreateSurface() {
125 return gfx::GLSurface::CreateSurfacelessViewGLSurface(widget_); 118 return gfx::GLSurface::CreateSurfacelessViewGLSurface(widget_);
126 } 119 }
127 120
128 } // namespace ui 121 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/demo/surfaceless_gl_renderer.h ('k') | ui/ozone/gpu/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698