| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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/ozone/platform/drm/gpu/vgem_pixmap.h" |
| 6 |
| 7 #include <i915_drm.h> |
| 8 #include "base/logging.h" |
| 9 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| 10 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 namespace { |
| 15 void EmptyPageFlipCallback(gfx::SwapResult result) {} |
| 16 } // namespace |
| 17 |
| 18 VgemPixmap::VgemPixmap(const scoped_refptr<DrmDevice>& drm) : drm_(drm) {} |
| 19 |
| 20 VgemPixmap::~VgemPixmap() { |
| 21 // TODO: finish |
| 22 if (framebuffer_ && !drm_->RemoveFramebuffer(framebuffer_)) |
| 23 PLOG(ERROR) << "SharedBuffer: RemoveFramebuffer: fb " << framebuffer_; |
| 24 } |
| 25 |
| 26 bool VgemPixmap::Initialize(base::ScopedFD dma_buf, |
| 27 int width, |
| 28 int height, |
| 29 uint32_t pitch) { |
| 30 int fd = dma_buf.get(); |
| 31 if (!drm_->BufferFdToHandle(fd, &handle_)) { |
| 32 PLOG(ERROR) << "SharedBuffer: Initialize: couldn't get handle from fd " |
| 33 << fd; |
| 34 return false; |
| 35 } |
| 36 |
| 37 // For scanout |
| 38 if (!drm_->BufferHandleSetTiling(handle_, pitch, I915_TILING_X)) |
| 39 return false; |
| 40 |
| 41 dma_buf_ = dma_buf.Pass(); |
| 42 dma_buf_pitch_ = pitch; |
| 43 |
| 44 width_ = width; |
| 45 height_ = height; |
| 46 |
| 47 if (!drm_->AddFramebuffer(width_, height_, 24, 32, dma_buf_pitch_, handle_, |
| 48 &framebuffer_)) { |
| 49 PLOG(ERROR) << "SharedBuffer: AddFramebuffer: handle " << handle_; |
| 50 return false; |
| 51 } |
| 52 |
| 53 return true; |
| 54 } |
| 55 |
| 56 uint32_t VgemPixmap::GetHandle() const { |
| 57 return handle_; |
| 58 } |
| 59 |
| 60 gfx::Size VgemPixmap::GetSize() const { |
| 61 return gfx::Size(width_, height_); |
| 62 } |
| 63 |
| 64 uint32_t VgemPixmap::GetFramebufferId() const { |
| 65 return framebuffer_; |
| 66 } |
| 67 |
| 68 int VgemPixmap::GetDmaBufFd() const { |
| 69 return dma_buf_.get(); |
| 70 } |
| 71 |
| 72 int VgemPixmap::GetDmaBufPitch() const { |
| 73 return dma_buf_pitch_; |
| 74 } |
| 75 |
| 76 VgemPixmapWrapper::VgemPixmapWrapper(ScreenManager* screen_manager, |
| 77 const scoped_refptr<VgemPixmap>& pixmap) |
| 78 : pixmap_(pixmap), screen_manager_(screen_manager) {} |
| 79 |
| 80 VgemPixmapWrapper::~VgemPixmapWrapper() {} |
| 81 |
| 82 bool VgemPixmapWrapper::ScheduleOverlayPlane( |
| 83 gfx::AcceleratedWidget widget, |
| 84 int plane_z_order, |
| 85 gfx::OverlayTransform plane_transform, |
| 86 const gfx::Rect& display_bounds, |
| 87 const gfx::RectF& crop_rect) { |
| 88 screen_manager_->GetWindow(widget)->QueueOverlayPlane(OverlayPlane(pixmap_)); |
| 89 // TODO(cstout): for the multi-overlay case, SchedulePageFlip should be called |
| 90 // once after all overlay planes are scheduled. Tracking issue mojo #540. |
| 91 screen_manager_->GetWindow(widget)->SchedulePageFlip( |
| 92 true /* is_sync */, base::Bind(&EmptyPageFlipCallback)); |
| 93 return true; |
| 94 } |
| 95 |
| 96 int VgemPixmapWrapper::GetDmaBufFd() { |
| 97 return pixmap_->GetDmaBufFd(); |
| 98 } |
| 99 |
| 100 int VgemPixmapWrapper::GetDmaBufPitch() { |
| 101 return pixmap_->GetDmaBufPitch(); |
| 102 } |
| 103 |
| 104 void* VgemPixmapWrapper::GetEGLClientBuffer() { |
| 105 return nullptr; |
| 106 } |
| 107 |
| 108 } // namespace ui |
| OLD | NEW |