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

Side by Side Diff: ui/ozone/platform/dri/gbm_surface.cc

Issue 403043004: [Ozone-DRI] Remove unneeded wrappers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/ozone/platform/dri/gbm_surface.h ('k') | ui/ozone/platform/dri/gbm_surface_factory.cc » ('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/platform/dri/gbm_surface.h" 5 #include "ui/ozone/platform/dri/gbm_surface.h"
6 6
7 #include <gbm.h> 7 #include <gbm.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkImageInfo.h"
11 #include "ui/ozone/platform/dri/dri_buffer.h" 10 #include "ui/ozone/platform/dri/dri_buffer.h"
12 #include "ui/ozone/platform/dri/dri_wrapper.h" 11 #include "ui/ozone/platform/dri/dri_wrapper.h"
13 #include "ui/ozone/platform/dri/gbm_buffer_base.h" 12 #include "ui/ozone/platform/dri/gbm_buffer_base.h"
14 #include "ui/ozone/platform/dri/hardware_display_controller.h"
15 #include "ui/ozone/platform/dri/scanout_buffer.h" 13 #include "ui/ozone/platform/dri/scanout_buffer.h"
16 14
17 namespace ui { 15 namespace ui {
18 16
19 namespace { 17 namespace {
20 18
21 class GbmSurfaceBuffer : public GbmBufferBase { 19 class GbmSurfaceBuffer : public GbmBufferBase {
22 public: 20 public:
23 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer(DriWrapper* dri, 21 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer(DriWrapper* dri,
24 gbm_bo* buffer); 22 gbm_bo* buffer);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 66 }
69 67
70 // static 68 // static
71 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) { 69 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) {
72 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data); 70 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data);
73 scoped_buffer->self_ = NULL; 71 scoped_buffer->self_ = NULL;
74 } 72 }
75 73
76 } // namespace 74 } // namespace
77 75
78 GbmSurface::GbmSurface(gbm_device* device, 76 GbmSurface::GbmSurface(
79 DriWrapper* dri, 77 const base::WeakPtr<HardwareDisplayController>& controller,
80 const gfx::Size& size) 78 gbm_device* device,
81 : gbm_device_(device), 79 DriWrapper* dri)
80 : GbmSurfaceless(controller),
81 gbm_device_(device),
82 dri_(dri), 82 dri_(dri),
83 size_(size),
84 native_surface_(NULL), 83 native_surface_(NULL),
85 buffers_(), 84 current_buffer_(NULL) {}
86 front_buffer_(0) {
87 for (size_t i = 0; i < arraysize(buffers_); ++i)
88 buffers_[i] = NULL;
89 }
90 85
91 GbmSurface::~GbmSurface() { 86 GbmSurface::~GbmSurface() {
92 for (size_t i = 0; i < arraysize(buffers_); ++i) { 87 if (current_buffer_)
93 if (buffers_[i]) { 88 gbm_surface_release_buffer(native_surface_, current_buffer_);
94 gbm_surface_release_buffer(native_surface_, buffers_[i]->bo());
95 }
96 }
97 89
98 if (native_surface_) 90 if (native_surface_)
99 gbm_surface_destroy(native_surface_); 91 gbm_surface_destroy(native_surface_);
100 } 92 }
101 93
102 bool GbmSurface::Initialize() { 94 bool GbmSurface::Initialize() {
103 // TODO(dnicoara) Check underlying system support for pixel format. 95 // TODO(dnicoara) Check underlying system support for pixel format.
104 native_surface_ = gbm_surface_create( 96 native_surface_ = gbm_surface_create(
105 gbm_device_, 97 gbm_device_,
106 size_.width(), 98 controller_->get_mode().hdisplay,
107 size_.height(), 99 controller_->get_mode().vdisplay,
108 GBM_BO_FORMAT_XRGB8888, 100 GBM_BO_FORMAT_XRGB8888,
109 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); 101 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
110 102
111 if (!native_surface_) 103 if (!native_surface_)
112 return false; 104 return false;
113 105
114 dumb_buffer_ = new DriBuffer(dri_);
115 if (!dumb_buffer_->Initialize(SkImageInfo::MakeN32Premul(size_.width(),
116 size_.height())))
117 return false;
118
119 return true; 106 return true;
120 } 107 }
121 108
122 uint32_t GbmSurface::GetFramebufferId() const { 109 intptr_t GbmSurface::GetNativeWindow() {
123 if (!buffers_[front_buffer_ ^ 1]) 110 CHECK(native_surface_);
124 return dumb_buffer_->GetFramebufferId(); 111 return reinterpret_cast<intptr_t>(native_surface_);
125
126 return buffers_[front_buffer_ ^ 1]->GetFramebufferId();
127 } 112 }
128 113
129 uint32_t GbmSurface::GetHandle() const { 114 bool GbmSurface::OnSwapBuffers() {
130 if (!buffers_[front_buffer_ ^ 1]) 115 CHECK(native_surface_);
131 return dumb_buffer_->GetHandle();
132 116
133 return buffers_[front_buffer_ ^ 1]->GetHandle(); 117 if (!controller_)
134 } 118 return false;
135 119
136 gfx::Size GbmSurface::Size() const { 120 gbm_bo* pending_buffer = gbm_surface_lock_front_buffer(native_surface_);
137 return size_; 121 scoped_refptr<GbmSurfaceBuffer> primary =
138 } 122 GbmSurfaceBuffer::GetBuffer(pending_buffer);
123 if (!primary) {
124 primary = GbmSurfaceBuffer::CreateBuffer(dri_, pending_buffer);
125 if (!primary) {
126 LOG(ERROR) << "Failed to associate the buffer with the controller";
127 return false;
128 }
129 }
139 130
140 // Before scheduling the backbuffer to be scanned out we need to "lock" it. 131 // The primary buffer is a special case.
141 // When we lock it, GBM will give a pointer to a buffer representing the 132 queued_planes_.push_back(OverlayPlane(primary));
142 // backbuffer. It will also update its information on which buffers can not be
143 // used for drawing. The buffer will be released when the page flip event
144 // occurs (see SwapBuffers). This is called from HardwareDisplayController
145 // before scheduling a page flip.
146 void GbmSurface::PreSwapBuffers() {
147 CHECK(native_surface_);
148 // Lock the buffer we want to display.
149 gbm_bo* bo = gbm_surface_lock_front_buffer(native_surface_);
150 133
151 buffers_[front_buffer_ ^ 1] = GbmSurfaceBuffer::GetBuffer(bo); 134 if (!GbmSurfaceless::OnSwapBuffers())
152 // If it is a new buffer, it won't have any data associated with it. So we 135 return false;
153 // create it. On creation it will associate itself with the buffer and
154 // register the buffer.
155 if (!buffers_[front_buffer_ ^ 1]) {
156 buffers_[front_buffer_ ^ 1] = GbmSurfaceBuffer::CreateBuffer(dri_, bo);
157 DCHECK(buffers_[front_buffer_ ^ 1])
158 << "Failed to associate the buffer with the controller";
159 }
160 }
161 136
162 void GbmSurface::SwapBuffers() { 137 // If there was a frontbuffer, it is no longer active. Release it back to GBM.
163 // If there was a frontbuffer, is no longer active. Release it back to GBM. 138 if (current_buffer_)
164 if (buffers_[front_buffer_]) 139 gbm_surface_release_buffer(native_surface_, current_buffer_);
165 gbm_surface_release_buffer(native_surface_, buffers_[front_buffer_]->bo());
166 140
167 // Update the index to the frontbuffer. 141 current_buffer_ = pending_buffer;
168 front_buffer_ ^= 1; 142 return true;
169 // We've just released it. Since GBM doesn't guarantee we'll get the same
170 // buffer back, we set it to NULL so we don't keep track of objects that may
171 // have been destroyed.
172 buffers_[front_buffer_ ^ 1] = NULL;
173 } 143 }
174 144
175 } // namespace ui 145 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/gbm_surface.h ('k') | ui/ozone/platform/dri/gbm_surface_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698