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

Side by Side Diff: ui/ozone/platform/drm/gpu/gl_surface_gbm_buffered_surfaceless.cc

Issue 2165303002: Convert Ozone GBM to use new surface API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ozone_impl
Patch Set: Small fixes. Created 4 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2016 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/platform/drm/gpu/gl_surface_gbm_buffered_surfaceless.h"
6
7 #include <utility>
8
9 #include "base/logging.h"
10 #include "ui/gl/gl_surface_egl.h"
11 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h"
12 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h"
13 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
14 #include "ui/ozone/public/native_pixmap.h"
15
16 namespace ui {
17
18 GLSurfaceGbmBufferedSurfaceless::GLSurfaceGbmBufferedSurfaceless(
19 std::unique_ptr<DrmWindowProxy> window,
20 GbmSurfaceFactory* surface_manager,
21 gfx::AcceleratedWidget widget)
22 : GLSurfaceGbmSurfaceless(std::move(window), surface_manager, widget),
23 context_(nullptr),
24 fbo_(0),
25 current_surface_(0) {
26 for (auto& texture : textures_)
27 texture = 0;
28 }
29
30 unsigned int GLSurfaceGbmBufferedSurfaceless::GetBackingFrameBufferObject() {
31 return fbo_;
32 }
33
34 bool GLSurfaceGbmBufferedSurfaceless::OnMakeCurrent(gl::GLContext* context) {
35 DCHECK(!context_ || context == context_);
36 context_ = context;
37 if (!fbo_) {
38 glGenFramebuffersEXT(1, &fbo_);
39 if (!fbo_)
40 return false;
41 glGenTextures(arraysize(textures_), textures_);
42 if (!CreatePixmaps())
43 return false;
44 }
45 BindFramebuffer();
46 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_);
47 return SurfacelessEGL::OnMakeCurrent(context);
48 }
49
50 bool GLSurfaceGbmBufferedSurfaceless::Resize(const gfx::Size& size,
51 float scale_factor,
52 bool has_alpha) {
53 if (size == GetSize())
54 return true;
55 // Alpha value isn't actually used in allocating buffers yet, so always use
56 // true instead.
57 return GLSurfaceGbmSurfaceless::Resize(size, scale_factor, true) &&
58 CreatePixmaps();
59 }
60
61 bool GLSurfaceGbmBufferedSurfaceless::SupportsPostSubBuffer() {
62 return false;
63 }
64
65 void GLSurfaceGbmBufferedSurfaceless::SwapBuffersAsync(
66 const SwapCompletionCallback& callback) {
67 if (!images_[current_surface_]->ScheduleOverlayPlane(
68 widget_, 0, gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE,
69 gfx::Rect(GetSize()), gfx::RectF(1, 1))) {
70 callback.Run(gfx::SwapResult::SWAP_FAILED);
71 return;
72 }
73 GLSurfaceGbmSurfaceless::SwapBuffersAsync(callback);
74 current_surface_ ^= 1;
75 BindFramebuffer();
76 }
77
78 void GLSurfaceGbmBufferedSurfaceless::Destroy() {
79 if (!context_)
80 return;
81 scoped_refptr<gl::GLContext> previous_context = gl::GLContext::GetCurrent();
82 scoped_refptr<GLSurface> previous_surface;
83
84 bool was_current = previous_context && previous_context->IsCurrent(nullptr) &&
85 GLSurface::GetCurrent() == this;
86 if (!was_current) {
87 // Only take a reference to previous surface if it's not |this|
88 // because otherwise we can take a self reference from our own dtor.
89 previous_surface = GLSurface::GetCurrent();
90 context_->MakeCurrent(this);
91 }
92
93 glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
94 if (fbo_) {
95 glDeleteTextures(arraysize(textures_), textures_);
96 for (auto& texture : textures_)
97 texture = 0;
98 glDeleteFramebuffersEXT(1, &fbo_);
99 fbo_ = 0;
100 }
101 for (auto image : images_) {
102 if (image)
103 image->Destroy(true);
104 }
105
106 if (!was_current) {
107 if (previous_context) {
108 previous_context->MakeCurrent(previous_surface.get());
109 } else {
110 context_->ReleaseCurrent(this);
111 }
112 }
113 }
114
115 bool GLSurfaceGbmBufferedSurfaceless::IsSurfaceless() const {
116 return false;
117 }
118
119 GLSurfaceGbmBufferedSurfaceless::~GLSurfaceGbmBufferedSurfaceless() {
120 Destroy();
121 }
122
123 void GLSurfaceGbmBufferedSurfaceless::BindFramebuffer() {
124 gl::ScopedFrameBufferBinder fb(fbo_);
125 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
126 textures_[current_surface_], 0);
127 }
128
129 bool GLSurfaceGbmBufferedSurfaceless::CreatePixmaps() {
130 if (!fbo_)
131 return true;
132 for (size_t i = 0; i < arraysize(textures_); i++) {
133 scoped_refptr<NativePixmap> pixmap = surface_manager_->CreateNativePixmap(
134 widget_, GetSize(), gfx::BufferFormat::BGRA_8888,
135 gfx::BufferUsage::SCANOUT);
136 if (!pixmap)
137 return false;
138 scoped_refptr<GLImageOzoneNativePixmap> image =
139 new GLImageOzoneNativePixmap(GetSize(), GL_BGRA_EXT);
140 if (!image->Initialize(pixmap.get(), gfx::BufferFormat::BGRA_8888))
141 return false;
142 // GLImage must have Destroy() called before destructor is called.
143 if (images_[i])
144 images_[i]->Destroy(true);
145 images_[i] = image;
146 // Bind image to texture.
147 gl::ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]);
148 if (!images_[i]->BindTexImage(GL_TEXTURE_2D))
149 return false;
150 }
151 return true;
152 }
153
154 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698