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

Side by Side Diff: ui/gfx/ozone/dri/hardware_display_controller.cc

Issue 106633002: GBM Ozone implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/gfx/ozone/dri/hardware_display_controller.h" 5 #include "ui/gfx/ozone/dri/hardware_display_controller.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "ui/gfx/ozone/dri/dri_skbitmap.h" 13 #include "ui/gfx/ozone/dri/dri_skbitmap.h"
14 #include "ui/gfx/ozone/dri/dri_surface.h"
15 #include "ui/gfx/ozone/dri/dri_wrapper.h" 14 #include "ui/gfx/ozone/dri/dri_wrapper.h"
15 #include "ui/gfx/ozone/dri/scanout_surface.h"
16 16
17 namespace gfx { 17 namespace gfx {
18 18
19 HardwareDisplayController::HardwareDisplayController() 19 HardwareDisplayController::HardwareDisplayController()
20 : drm_(NULL), 20 : drm_(NULL),
21 connector_id_(0), 21 connector_id_(0),
22 crtc_id_(0), 22 crtc_id_(0),
23 mode_(), 23 mode_(),
24 saved_crtc_(NULL), 24 saved_crtc_(NULL),
25 state_(UNASSOCIATED), 25 state_(UNASSOCIATED),
(...skipping 14 matching lines...) Expand all
40 saved_crtc_ = drm_->GetCrtc(crtc_id_); 40 saved_crtc_ = drm_->GetCrtc(crtc_id_);
41 state_ = UNINITIALIZED; 41 state_ = UNINITIALIZED;
42 } 42 }
43 43
44 HardwareDisplayController::~HardwareDisplayController() { 44 HardwareDisplayController::~HardwareDisplayController() {
45 if (saved_crtc_) { 45 if (saved_crtc_) {
46 if (!drm_->SetCrtc(saved_crtc_, &connector_id_)) 46 if (!drm_->SetCrtc(saved_crtc_, &connector_id_))
47 DLOG(ERROR) << "Failed to restore CRTC state: " << strerror(errno); 47 DLOG(ERROR) << "Failed to restore CRTC state: " << strerror(errno);
48 drm_->FreeCrtc(saved_crtc_); 48 drm_->FreeCrtc(saved_crtc_);
49 } 49 }
50
51 if (surface_.get()) {
52 // Unregister the buffers.
53 for (int i = 0; i < 2; ++i) {
54 if (!drm_->RemoveFramebuffer(surface_->bitmaps_[i]->get_framebuffer()))
55 DLOG(ERROR) << "Failed to remove FB: " << strerror(errno);
56 }
57 }
58 } 50 }
59 51
60 bool 52 bool
61 HardwareDisplayController::BindSurfaceToController( 53 HardwareDisplayController::BindSurfaceToController(
62 scoped_ptr<DriSurface> surface) { 54 scoped_ptr<ScanoutSurface> surface) {
63 CHECK(state_ == UNINITIALIZED); 55 CHECK(state_ == UNINITIALIZED);
64 56
65 // Register the buffers.
66 for (int i = 0; i < 2; ++i) {
67 uint32_t fb_id;
68 if (!drm_->AddFramebuffer(mode_,
69 surface->bitmaps_[i]->GetColorDepth(),
70 surface->bitmaps_[i]->bytesPerPixel() << 3,
71 surface->bitmaps_[i]->rowBytes(),
72 surface->bitmaps_[i]->get_handle(),
73 &fb_id)) {
74 DLOG(ERROR) << "Failed to register framebuffer: " << strerror(errno);
75 state_ = FAILED;
76 return false;
77 }
78 surface->bitmaps_[i]->set_framebuffer(fb_id);
79 }
80
81 surface_.reset(surface.release()); 57 surface_.reset(surface.release());
82 state_ = SURFACE_INITIALIZED; 58 state_ = SURFACE_INITIALIZED;
83 return true; 59 return true;
84 } 60 }
85 61
62 bool HardwareDisplayController::AddFramebuffer(
63 uint8_t depth,
64 uint8_t bpp,
65 uint32_t stride,
66 uint32_t handle,
67 uint32_t* framebuffer_id) {
68 CHECK(state_ != UNASSOCIATED && state_ != FAILED);
69 if (!drm_->AddFramebuffer(mode_,
70 depth,
71 bpp,
72 stride,
73 handle,
74 framebuffer_id)){
75 DLOG(ERROR) << "Failed to register framebuffer: " << strerror(errno);
76 state_ = FAILED;
77 return false;
78 }
79 return true;
80 }
81
82 bool HardwareDisplayController::RemoveFramebuffer(
83 uint32_t framebuffer_id) {
84 CHECK(state_ != UNASSOCIATED);
85 if (!drm_->RemoveFramebuffer(framebuffer_id)) {
86 DLOG(ERROR) << "Failed to remove FB: " << strerror(errno);
87 return false;
88 }
89 return true;
90 }
91
86 bool HardwareDisplayController::SchedulePageFlip() { 92 bool HardwareDisplayController::SchedulePageFlip() {
87 CHECK(state_ == SURFACE_INITIALIZED || state_ == INITIALIZED); 93 CHECK(state_ == SURFACE_INITIALIZED || state_ == INITIALIZED);
88 94
89 if (state_ == SURFACE_INITIALIZED) { 95 if (state_ == SURFACE_INITIALIZED) {
90 // Perform the initial modeset. 96 // Perform the initial modeset.
91 if (!drm_->SetCrtc(crtc_id_, 97 if (!drm_->SetCrtc(crtc_id_,
92 surface_->GetFramebufferId(), 98 surface_->GetFramebufferId(),
93 &connector_id_, 99 &connector_id_,
94 &mode_)) { 100 &mode_)) {
95 DLOG(ERROR) << "Cannot set CRTC: " << strerror(errno); 101 DLOG(ERROR) << "Cannot set CRTC: " << strerror(errno);
(...skipping 24 matching lines...) Expand all
120 unsigned int seconds, 126 unsigned int seconds,
121 unsigned int useconds) { 127 unsigned int useconds) {
122 time_of_last_flip_ = 128 time_of_last_flip_ =
123 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond + 129 static_cast<uint64_t>(seconds) * base::Time::kMicrosecondsPerSecond +
124 useconds; 130 useconds;
125 131
126 surface_->SwapBuffers(); 132 surface_->SwapBuffers();
127 } 133 }
128 134
129 } // namespace gfx 135 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698