OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/gfx/ozone/impl/hardware_display_controller_ozone.h" |
| 6 |
| 7 #include <errno.h> |
| 8 #include <string.h> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" |
| 12 #include "ui/gfx/ozone/impl/drm_skbitmap_ozone.h" |
| 13 #include "ui/gfx/ozone/impl/drm_wrapper_ozone.h" |
| 14 #include "ui/gfx/ozone/impl/software_surface_ozone.h" |
| 15 |
| 16 namespace gfx { |
| 17 |
| 18 HardwareDisplayControllerOzone::HardwareDisplayControllerOzone() |
| 19 : drm_(NULL), |
| 20 connector_id_(0), |
| 21 crtc_id_(0), |
| 22 mode_(), |
| 23 saved_crtc_(NULL), |
| 24 state_(UNASSOCIATED), |
| 25 surface_() { |
| 26 } |
| 27 |
| 28 void HardwareDisplayControllerOzone::SetControllerInfo( |
| 29 DrmWrapperOzone* drm, |
| 30 uint32_t connector_id, |
| 31 uint32_t crtc_id, |
| 32 drmModeModeInfo mode) { |
| 33 drm_ = drm; |
| 34 connector_id_ = connector_id; |
| 35 crtc_id_ = crtc_id; |
| 36 mode_ = mode; |
| 37 saved_crtc_ = drm_->GetCrtc(crtc_id_); |
| 38 state_ = UNINITIALIZED; |
| 39 } |
| 40 |
| 41 HardwareDisplayControllerOzone::~HardwareDisplayControllerOzone() { |
| 42 if (saved_crtc_) { |
| 43 if (!drm_->SetCrtc(saved_crtc_, &connector_id_)) |
| 44 DLOG(ERROR) << "Failed to restore CRTC state: " << strerror(errno); |
| 45 drm_->FreeCrtc(saved_crtc_); |
| 46 } |
| 47 |
| 48 if (surface_.get()) { |
| 49 // Unregister the buffers. |
| 50 for (int i = 0; i < 2; ++i) { |
| 51 if (!drm_->RemoveFramebuffer(surface_->bitmaps_[i]->get_framebuffer())) |
| 52 DLOG(ERROR) << "Failed to remove FB: " << strerror(errno); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 bool |
| 58 HardwareDisplayControllerOzone::BindSurfaceToController( |
| 59 SoftwareSurfaceOzone* surface) { |
| 60 CHECK(state_ == UNINITIALIZED); |
| 61 |
| 62 // Register the buffers. |
| 63 for (int i = 0; i < 2; ++i) { |
| 64 uint32_t fb_id; |
| 65 if (!drm_->AddFramebuffer(mode_, |
| 66 surface->bitmaps_[i]->GetColorDepth(), |
| 67 surface->bitmaps_[i]->bytesPerPixel() << 3, |
| 68 surface->bitmaps_[i]->rowBytes(), |
| 69 surface->bitmaps_[i]->get_handle(), |
| 70 &fb_id)) { |
| 71 DLOG(ERROR) << "Failed to register framebuffer: " << strerror(errno); |
| 72 state_ = FAILED; |
| 73 return false; |
| 74 } |
| 75 surface->bitmaps_[i]->set_framebuffer(fb_id); |
| 76 } |
| 77 |
| 78 surface_.reset(surface); |
| 79 state_ = SURFACE_INITIALIZED; |
| 80 return true; |
| 81 } |
| 82 |
| 83 bool HardwareDisplayControllerOzone::SchedulePageFlip() { |
| 84 CHECK(state_ == SURFACE_INITIALIZED || state_ == INITIALIZED); |
| 85 |
| 86 if (state_ == SURFACE_INITIALIZED) { |
| 87 // Perform the initial modeset. |
| 88 if (!drm_->SetCrtc(crtc_id_, |
| 89 surface_->GetFramebufferId(), |
| 90 &connector_id_, |
| 91 &mode_)) { |
| 92 DLOG(ERROR) << "Cannot set CRTC: " << strerror(errno); |
| 93 state_ = FAILED; |
| 94 return false; |
| 95 } else { |
| 96 state_ = INITIALIZED; |
| 97 } |
| 98 } |
| 99 |
| 100 if (!drm_->PageFlip(crtc_id_, |
| 101 surface_->GetFramebufferId(), |
| 102 this)) { |
| 103 state_ = FAILED; |
| 104 LOG(ERROR) << "Cannot page flip: " << strerror(errno); |
| 105 return false; |
| 106 } |
| 107 return true; |
| 108 } |
| 109 |
| 110 } // namespace gfx |
OLD | NEW |