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

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

Issue 400283002: [Ozone-GBM] Migrate GBM buffers to use the ScanoutBuffer interface (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" 10 #include "third_party/skia/include/core/SkImageInfo.h"
11 #include "ui/ozone/platform/dri/buffer_data.h"
12 #include "ui/ozone/platform/dri/dri_buffer.h" 11 #include "ui/ozone/platform/dri/dri_buffer.h"
13 #include "ui/ozone/platform/dri/dri_wrapper.h" 12 #include "ui/ozone/platform/dri/dri_wrapper.h"
13 #include "ui/ozone/platform/dri/gbm_buffer_base.h"
14 #include "ui/ozone/platform/dri/hardware_display_controller.h" 14 #include "ui/ozone/platform/dri/hardware_display_controller.h"
15 #include "ui/ozone/platform/dri/scanout_buffer.h"
15 16
16 namespace ui { 17 namespace ui {
17 18
19 namespace {
20
21 class GbmSurfaceBuffer : public GbmBufferBase {
22 public:
23 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer(DriWrapper* dri,
24 gbm_bo* buffer);
25 static scoped_refptr<GbmSurfaceBuffer> GetBuffer(gbm_bo* buffer);
26
27 private:
28 GbmSurfaceBuffer(DriWrapper* dri, gbm_bo* bo);
29 virtual ~GbmSurfaceBuffer();
30
31 static void Destroy(gbm_bo* buffer, void* data);
32
33 // This buffer is special and is released by GBM at any point in time (as
34 // long as it isn't being used). Since GBM should be the only one to
35 // release this buffer, keep a self-reference in order to keep this alive.
36 // When GBM calls Destroy(..) the self-reference will dissapear and this will
37 // be destroyed.
38 scoped_refptr<GbmSurfaceBuffer> self_;
39
40 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceBuffer);
41 };
42
43 GbmSurfaceBuffer::GbmSurfaceBuffer(DriWrapper* dri, gbm_bo* bo)
44 : GbmBufferBase(dri, bo, true) {
45 if (GetFramebufferId()) {
46 self_ = this;
47 gbm_bo_set_user_data(bo, this, GbmSurfaceBuffer::Destroy);
48 }
49 }
50
51 GbmSurfaceBuffer::~GbmSurfaceBuffer() {}
52
53 // static
54 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::CreateBuffer(
55 DriWrapper* dri, gbm_bo* buffer) {
56 scoped_refptr<GbmSurfaceBuffer> scoped_buffer(new GbmSurfaceBuffer(dri,
57 buffer));
58 if (!scoped_buffer->GetFramebufferId())
59 return NULL;
60
61 return scoped_buffer;
62 }
63
64 // static
65 scoped_refptr<GbmSurfaceBuffer> GbmSurfaceBuffer::GetBuffer(gbm_bo* buffer) {
66 return scoped_refptr<GbmSurfaceBuffer>(
67 static_cast<GbmSurfaceBuffer*>(gbm_bo_get_user_data(buffer)));
68 }
69
70 // static
71 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) {
72 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data);
73 scoped_buffer->self_ = NULL;
74 }
75
76 } // namespace
77
18 GbmSurface::GbmSurface(gbm_device* device, 78 GbmSurface::GbmSurface(gbm_device* device,
19 DriWrapper* dri, 79 DriWrapper* dri,
20 const gfx::Size& size) 80 const gfx::Size& size)
21 : gbm_device_(device), 81 : gbm_device_(device),
22 dri_(dri), 82 dri_(dri),
23 size_(size), 83 size_(size),
24 native_surface_(NULL), 84 native_surface_(NULL),
25 buffers_(), 85 buffers_(),
26 front_buffer_(0) { 86 front_buffer_(0) {
27 for (size_t i = 0; i < arraysize(buffers_); ++i) 87 for (size_t i = 0; i < arraysize(buffers_); ++i)
28 buffers_[i] = NULL; 88 buffers_[i] = NULL;
29 } 89 }
30 90
31 GbmSurface::~GbmSurface() { 91 GbmSurface::~GbmSurface() {
32 for (size_t i = 0; i < arraysize(buffers_); ++i) { 92 for (size_t i = 0; i < arraysize(buffers_); ++i) {
33 if (buffers_[i]) { 93 if (buffers_[i]) {
34 gbm_surface_release_buffer(native_surface_, buffers_[i]); 94 gbm_surface_release_buffer(native_surface_, buffers_[i]->bo());
35 } 95 }
36 } 96 }
37 97
38 if (native_surface_) 98 if (native_surface_)
39 gbm_surface_destroy(native_surface_); 99 gbm_surface_destroy(native_surface_);
40 } 100 }
41 101
42 bool GbmSurface::Initialize() { 102 bool GbmSurface::Initialize() {
43 // TODO(dnicoara) Check underlying system support for pixel format. 103 // TODO(dnicoara) Check underlying system support for pixel format.
44 native_surface_ = gbm_surface_create( 104 native_surface_ = gbm_surface_create(
(...skipping 11 matching lines...) Expand all
56 size_.height()))) 116 size_.height())))
57 return false; 117 return false;
58 118
59 return true; 119 return true;
60 } 120 }
61 121
62 uint32_t GbmSurface::GetFramebufferId() const { 122 uint32_t GbmSurface::GetFramebufferId() const {
63 if (!buffers_[front_buffer_ ^ 1]) 123 if (!buffers_[front_buffer_ ^ 1])
64 return dumb_buffer_->GetFramebufferId(); 124 return dumb_buffer_->GetFramebufferId();
65 125
66 BufferData* data = BufferData::GetData(buffers_[front_buffer_ ^ 1]); 126 return buffers_[front_buffer_ ^ 1]->GetFramebufferId();
67 CHECK(data);
68 return data->framebuffer();
69 } 127 }
70 128
71 uint32_t GbmSurface::GetHandle() const { 129 uint32_t GbmSurface::GetHandle() const {
72 if (!buffers_[front_buffer_ ^ 1]) 130 if (!buffers_[front_buffer_ ^ 1])
73 return dumb_buffer_->GetHandle(); 131 return dumb_buffer_->GetHandle();
74 132
75 BufferData* data = BufferData::GetData(buffers_[front_buffer_ ^ 1]); 133 return buffers_[front_buffer_ ^ 1]->GetHandle();
76 CHECK(data);
77 return data->handle();
78 } 134 }
79 135
80 gfx::Size GbmSurface::Size() const { 136 gfx::Size GbmSurface::Size() const {
81 return size_; 137 return size_;
82 } 138 }
83 139
84 // Before scheduling the backbuffer to be scanned out we need to "lock" it. 140 // Before scheduling the backbuffer to be scanned out we need to "lock" it.
85 // When we lock it, GBM will give a pointer to a buffer representing the 141 // When we lock it, GBM will give a pointer to a buffer representing the
86 // backbuffer. It will also update its information on which buffers can not be 142 // backbuffer. It will also update its information on which buffers can not be
87 // used for drawing. The buffer will be released when the page flip event 143 // used for drawing. The buffer will be released when the page flip event
88 // occurs (see SwapBuffers). This is called from HardwareDisplayController 144 // occurs (see SwapBuffers). This is called from HardwareDisplayController
89 // before scheduling a page flip. 145 // before scheduling a page flip.
90 void GbmSurface::PreSwapBuffers() { 146 void GbmSurface::PreSwapBuffers() {
91 CHECK(native_surface_); 147 CHECK(native_surface_);
92 // Lock the buffer we want to display. 148 // Lock the buffer we want to display.
93 buffers_[front_buffer_ ^ 1] = gbm_surface_lock_front_buffer(native_surface_); 149 gbm_bo* bo = gbm_surface_lock_front_buffer(native_surface_);
94 150
95 BufferData* data = BufferData::GetData(buffers_[front_buffer_ ^ 1]); 151 buffers_[front_buffer_ ^ 1] = GbmSurfaceBuffer::GetBuffer(bo);
96 // If it is a new buffer, it won't have any data associated with it. So we 152 // If it is a new buffer, it won't have any data associated with it. So we
97 // create it. On creation it will associate itself with the buffer and 153 // create it. On creation it will associate itself with the buffer and
98 // register the buffer. 154 // register the buffer.
99 if (!data) { 155 if (!buffers_[front_buffer_ ^ 1]) {
100 data = BufferData::CreateData(dri_, buffers_[front_buffer_ ^ 1]); 156 buffers_[front_buffer_ ^ 1] = GbmSurfaceBuffer::CreateBuffer(dri_, bo);
101 DCHECK(data) << "Failed to associate the buffer with the controller"; 157 DCHECK(buffers_[front_buffer_ ^ 1])
158 << "Failed to associate the buffer with the controller";
102 } 159 }
103 } 160 }
104 161
105 void GbmSurface::SwapBuffers() { 162 void GbmSurface::SwapBuffers() {
106 // If there was a frontbuffer, is no longer active. Release it back to GBM. 163 // If there was a frontbuffer, is no longer active. Release it back to GBM.
107 if (buffers_[front_buffer_]) 164 if (buffers_[front_buffer_])
108 gbm_surface_release_buffer(native_surface_, buffers_[front_buffer_]); 165 gbm_surface_release_buffer(native_surface_, buffers_[front_buffer_]->bo());
109 166
110 // Update the index to the frontbuffer. 167 // Update the index to the frontbuffer.
111 front_buffer_ ^= 1; 168 front_buffer_ ^= 1;
112 // We've just released it. Since GBM doesn't guarantee we'll get the same 169 // We've just released it. Since GBM doesn't guarantee we'll get the same
113 // buffer back, we set it to NULL so we don't keep track of objects that may 170 // buffer back, we set it to NULL so we don't keep track of objects that may
114 // have been destroyed. 171 // have been destroyed.
115 buffers_[front_buffer_ ^ 1] = NULL; 172 buffers_[front_buffer_ ^ 1] = NULL;
116 } 173 }
117 174
118 } // namespace ui 175 } // 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