| OLD | NEW |
| 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" |
| 11 #include "ui/ozone/platform/dri/dri_buffer.h" | 12 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 12 #include "ui/ozone/platform/dri/dri_wrapper.h" | 13 #include "ui/ozone/platform/dri/dri_wrapper.h" |
| 13 #include "ui/ozone/platform/dri/gbm_surface.h" | |
| 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 // Pixel configuration for the current buffer format. | |
| 21 // TODO(dnicoara) These will need to change once we'll query the hardware for | |
| 22 // supported configurations. | |
| 23 const uint8_t kColorDepth = 24; | |
| 24 const uint8_t kPixelDepth = 32; | |
| 25 | |
| 26 class BufferData { | |
| 27 public: | |
| 28 // When we create the BufferData we need to register the buffer. Once | |
| 29 // successfully registered, the |framebuffer_| field will hold the ID of the | |
| 30 // buffer. The controller will use this ID when scanning out the buffer. On | |
| 31 // creation we will also associate the BufferData with the buffer. | |
| 32 static BufferData* CreateData(DriWrapper* dri, gbm_bo* buffer); | |
| 33 | |
| 34 // Callback used by GBM to destory the BufferData associated with a buffer. | |
| 35 static void Destroy(gbm_bo* buffer, void* data); | |
| 36 | |
| 37 // Returns the BufferData associated with |buffer|. NULL if no data is | |
| 38 // associated. | |
| 39 static BufferData* GetData(gbm_bo* buffer); | |
| 40 | |
| 41 uint32_t framebuffer() const { return framebuffer_; } | |
| 42 uint32_t handle() const { return handle_; } | |
| 43 | |
| 44 private: | |
| 45 BufferData(DriWrapper* dri, gbm_bo* buffer); | |
| 46 ~BufferData(); | |
| 47 | |
| 48 DriWrapper* dri_; | |
| 49 | |
| 50 uint32_t handle_; | |
| 51 | |
| 52 // ID provided by the controller when the buffer is registered. This ID is | |
| 53 // used when scanning out the buffer. | |
| 54 uint32_t framebuffer_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(BufferData); | |
| 57 }; | |
| 58 | |
| 59 BufferData::BufferData(DriWrapper* dri, gbm_bo* buffer) | |
| 60 : dri_(dri), | |
| 61 handle_(gbm_bo_get_handle(buffer).u32), | |
| 62 framebuffer_(0) { | |
| 63 // Register the buffer with the controller. This will allow us to scan out the | |
| 64 // buffer once we're done drawing into it. If we can't register the buffer | |
| 65 // then there's no point in having BufferData associated with it. | |
| 66 if (!dri_->AddFramebuffer(gbm_bo_get_width(buffer), | |
| 67 gbm_bo_get_height(buffer), | |
| 68 kColorDepth, | |
| 69 kPixelDepth, | |
| 70 gbm_bo_get_stride(buffer), | |
| 71 handle_, | |
| 72 &framebuffer_)) { | |
| 73 LOG(ERROR) << "Failed to register buffer"; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 BufferData::~BufferData() { | |
| 78 if (framebuffer_) | |
| 79 dri_->RemoveFramebuffer(framebuffer_); | |
| 80 } | |
| 81 | |
| 82 // static | |
| 83 BufferData* BufferData::CreateData(DriWrapper* dri, | |
| 84 gbm_bo* buffer) { | |
| 85 BufferData* data = new BufferData(dri, buffer); | |
| 86 if (!data->framebuffer()) { | |
| 87 delete data; | |
| 88 return NULL; | |
| 89 } | |
| 90 | |
| 91 // GBM can destroy the buffers at any time as long as they aren't locked. This | |
| 92 // sets a callback such that we can clean up all our state when GBM destroys | |
| 93 // the buffer. | |
| 94 gbm_bo_set_user_data(buffer, data, BufferData::Destroy); | |
| 95 | |
| 96 return data; | |
| 97 } | |
| 98 | |
| 99 // static | |
| 100 void BufferData::Destroy(gbm_bo* buffer, void* data) { | |
| 101 BufferData* bd = static_cast<BufferData*>(data); | |
| 102 delete bd; | |
| 103 } | |
| 104 | |
| 105 // static | |
| 106 BufferData* BufferData::GetData(gbm_bo* buffer) { | |
| 107 return static_cast<BufferData*>(gbm_bo_get_user_data(buffer)); | |
| 108 } | |
| 109 | |
| 110 } // namespace | |
| 111 | |
| 112 GbmSurface::GbmSurface(gbm_device* device, | 18 GbmSurface::GbmSurface(gbm_device* device, |
| 113 DriWrapper* dri, | 19 DriWrapper* dri, |
| 114 const gfx::Size& size) | 20 const gfx::Size& size) |
| 115 : gbm_device_(device), | 21 : gbm_device_(device), |
| 116 dri_(dri), | 22 dri_(dri), |
| 117 size_(size), | 23 size_(size), |
| 118 native_surface_(NULL), | 24 native_surface_(NULL), |
| 119 buffers_(), | 25 buffers_(), |
| 120 front_buffer_(0) { | 26 front_buffer_(0) { |
| 121 for (size_t i = 0; i < arraysize(buffers_); ++i) | 27 for (size_t i = 0; i < arraysize(buffers_); ++i) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // If it is a new buffer, it won't have any data associated with it. So we | 103 // If it is a new buffer, it won't have any data associated with it. So we |
| 198 // create it. On creation it will associate itself with the buffer and | 104 // create it. On creation it will associate itself with the buffer and |
| 199 // register the buffer. | 105 // register the buffer. |
| 200 if (!data) { | 106 if (!data) { |
| 201 data = BufferData::CreateData(dri_, buffers_[front_buffer_ ^ 1]); | 107 data = BufferData::CreateData(dri_, buffers_[front_buffer_ ^ 1]); |
| 202 DCHECK(data) << "Failed to associate the buffer with the controller"; | 108 DCHECK(data) << "Failed to associate the buffer with the controller"; |
| 203 } | 109 } |
| 204 } | 110 } |
| 205 | 111 |
| 206 } // namespace ui | 112 } // namespace ui |
| OLD | NEW |