summaryrefslogtreecommitdiffstats
path: root/ui/ozone/platform/drm/gpu/drm_buffer.cc
diff options
context:
space:
mode:
authordnicoara <dnicoara@chromium.org>2015-03-05 12:46:18 -0800
committerCommit bot <commit-bot@chromium.org>2015-03-05 20:47:08 +0000
commit171d8c892da1b2e38f90c17b62896ba82f0719e3 (patch)
tree9fe2810948b2d8dfd73cd7a5afa002dcf79c0547 /ui/ozone/platform/drm/gpu/drm_buffer.cc
parentf36607f2398cb4aa9b50449b1221bbc72e3f3453 (diff)
downloadchromium_src-171d8c892da1b2e38f90c17b62896ba82f0719e3.zip
chromium_src-171d8c892da1b2e38f90c17b62896ba82f0719e3.tar.gz
chromium_src-171d8c892da1b2e38f90c17b62896ba82f0719e3.tar.bz2
[Ozone] Rename and split the DRI platform for clarity
This CL does the following: - Moves the files in ui/ozone/platform/dri to ui/ozone/platform/drm since the platform name should really be DRM rather than DRI. Note, that the platform is still refered to as "dri" in GYP/GN since CrOS builds are still using the 'dri' name. - Rename all files with a "_dri*" suffix to a "drm_" prefix. Also rename all files with a "dri_" prefix to a "drm_" prefix. - Rename NativeDisplayDelegateDri to DrmDisplayDelegateManager since it is no longer dependent on the NativeDisplayDelegate interface and the new name better describes its intent. - Split the files in the platform into 2 sub-folders ("host" and "gpu"). Depending on the intended use place of the objects (Browser (host) process or GPU process) the files in the platform are split accordingly in the 2 sub-folders. BUG=none TBR=jam@chromium.org Review URL: https://codereview.chromium.org/975063002 Cr-Commit-Position: refs/heads/master@{#319320}
Diffstat (limited to 'ui/ozone/platform/drm/gpu/drm_buffer.cc')
-rw-r--r--ui/ozone/platform/drm/gpu/drm_buffer.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/ui/ozone/platform/drm/gpu/drm_buffer.cc b/ui/ozone/platform/drm/gpu/drm_buffer.cc
new file mode 100644
index 0000000..12e0a8e
--- /dev/null
+++ b/ui/ozone/platform/drm/gpu/drm_buffer.cc
@@ -0,0 +1,114 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/ozone/platform/drm/gpu/drm_buffer.h"
+
+#include "base/logging.h"
+#include "ui/ozone/platform/drm/gpu/drm_device.h"
+
+namespace ui {
+
+namespace {
+
+// Modesetting cannot happen from a buffer with transparencies. Return the size
+// of a pixel without alpha.
+uint8_t GetColorDepth(SkColorType type) {
+ switch (type) {
+ case kUnknown_SkColorType:
+ case kAlpha_8_SkColorType:
+ return 0;
+ case kIndex_8_SkColorType:
+ return 8;
+ case kRGB_565_SkColorType:
+ return 16;
+ case kARGB_4444_SkColorType:
+ return 12;
+ case kN32_SkColorType:
+ return 24;
+ default:
+ NOTREACHED();
+ return 0;
+ }
+}
+
+} // namespace
+
+DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm)
+ : drm_(drm), handle_(0), framebuffer_(0) {
+}
+
+DrmBuffer::~DrmBuffer() {
+ if (!surface_)
+ return;
+
+ if (framebuffer_)
+ drm_->RemoveFramebuffer(framebuffer_);
+
+ SkImageInfo info;
+ void* pixels = const_cast<void*>(surface_->peekPixels(&info, NULL));
+ if (!pixels)
+ return;
+
+ drm_->DestroyDumbBuffer(info, handle_, stride_, pixels);
+}
+
+bool DrmBuffer::Initialize(const SkImageInfo& info,
+ bool should_register_framebuffer) {
+ void* pixels = NULL;
+ if (!drm_->CreateDumbBuffer(info, &handle_, &stride_, &pixels)) {
+ VLOG(2) << "Cannot create drm dumb buffer";
+ return false;
+ }
+
+ if (should_register_framebuffer &&
+ !drm_->AddFramebuffer(
+ info.width(), info.height(), GetColorDepth(info.colorType()),
+ info.bytesPerPixel() << 3, stride_, handle_, &framebuffer_)) {
+ VLOG(2) << "Failed to register framebuffer: " << strerror(errno);
+ return false;
+ }
+
+ surface_ = skia::AdoptRef(SkSurface::NewRasterDirect(info, pixels, stride_));
+ if (!surface_) {
+ VLOG(2) << "Cannot install Skia pixels for drm buffer";
+ return false;
+ }
+
+ return true;
+}
+
+SkCanvas* DrmBuffer::GetCanvas() const {
+ return surface_->getCanvas();
+}
+
+uint32_t DrmBuffer::GetFramebufferId() const {
+ return framebuffer_;
+}
+
+uint32_t DrmBuffer::GetHandle() const {
+ return handle_;
+}
+
+gfx::Size DrmBuffer::GetSize() const {
+ return gfx::Size(surface_->width(), surface_->height());
+}
+
+DrmBufferGenerator::DrmBufferGenerator() {
+}
+
+DrmBufferGenerator::~DrmBufferGenerator() {
+}
+
+scoped_refptr<ScanoutBuffer> DrmBufferGenerator::Create(
+ const scoped_refptr<DrmDevice>& drm,
+ const gfx::Size& size) {
+ scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm));
+ SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
+ if (!buffer->Initialize(info, true /* should_register_framebuffer */))
+ return NULL;
+
+ return buffer;
+}
+
+} // namespace ui