Commit 3986ac00 authored by dnicoara@chromium.org's avatar dnicoara@chromium.org

[Ozone-DRI] Adding ScanoutBuffer interface

First step in transitioning HardwareDisplayController to take in buffers rather
than surfaces. ScanoutBuffer defines the minimal interface required by HDC for
modesetting and page-flipping.

BUG=none
NOTRY=true

Review URL: https://codereview.chromium.org/399213005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284115 0039d316-1c4b-4281-b951-d872f2087c98
parent 781849a0
......@@ -65,6 +65,7 @@
'scoped_drm_types.h',
'screen_manager.cc',
'screen_manager.h',
'scanout_buffer.h',
'scanout_surface.h',
'virtual_terminal_manager.cc',
'virtual_terminal_manager.h',
......
......@@ -79,4 +79,33 @@ bool DriBuffer::Initialize(const SkImageInfo& info) {
return true;
}
SkCanvas* DriBuffer::GetCanvas() const {
return surface_->getCanvas();
}
uint32_t DriBuffer::GetFramebufferId() const {
return framebuffer_;
}
uint32_t DriBuffer::GetHandle() const {
return handle_;
}
gfx::Size DriBuffer::GetSize() const {
return gfx::Size(surface_->width(), surface_->height());
}
DriBufferGenerator::DriBufferGenerator(DriWrapper* dri) : dri_(dri) {}
DriBufferGenerator::~DriBufferGenerator() {}
scoped_refptr<ScanoutBuffer> DriBufferGenerator::Create(const gfx::Size& size) {
scoped_refptr<DriBuffer> buffer(new DriBuffer(dri_));
SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
if (!buffer->Initialize(info))
return NULL;
return buffer;
}
} // namespace ui
......@@ -8,8 +8,7 @@
#include "base/macros.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkSurface.h"
class SkCanvas;
#include "ui/ozone/platform/dri/scanout_buffer.h"
namespace ui {
......@@ -18,21 +17,24 @@ class DriWrapper;
// Wrapper for a DRM allocated buffer. Keeps track of the native properties of
// the buffer and wraps the pixel memory into a SkSurface which can be used to
// draw into using Skia.
class DriBuffer {
class DriBuffer : public ScanoutBuffer {
public:
DriBuffer(DriWrapper* dri);
~DriBuffer();
uint32_t stride() const { return stride_; }
uint32_t handle() const { return handle_; }
uint32_t framebuffer() const { return framebuffer_; }
SkCanvas* canvas() { return surface_->getCanvas(); }
// Allocates the backing pixels and wraps them in |surface_|. |info| is used
// to describe the buffer characteristics (size, color format).
bool Initialize(const SkImageInfo& info);
private:
SkCanvas* GetCanvas() const;
// ScanoutBuffer:
virtual uint32_t GetFramebufferId() const OVERRIDE;
virtual uint32_t GetHandle() const OVERRIDE;
virtual gfx::Size GetSize() const OVERRIDE;
protected:
virtual ~DriBuffer();
DriWrapper* dri_; // Not owned.
// Wrapper around the native pixel memory.
......@@ -51,6 +53,20 @@ class DriBuffer {
DISALLOW_COPY_AND_ASSIGN(DriBuffer);
};
class DriBufferGenerator : public ScanoutBufferGenerator {
public:
DriBufferGenerator(DriWrapper* dri);
virtual ~DriBufferGenerator();
// ScanoutBufferGenerator:
virtual scoped_refptr<ScanoutBuffer> Create(const gfx::Size& size) OVERRIDE;
private:
DriWrapper* dri_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(DriBufferGenerator);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_DRI_DRI_BUFFER_H_
......@@ -31,7 +31,7 @@ DriSurface::~DriSurface() {
bool DriSurface::Initialize() {
for (size_t i = 0; i < arraysize(bitmaps_); ++i) {
bitmaps_[i].reset(new DriBuffer(dri_));
bitmaps_[i] = new DriBuffer(dri_);
// TODO(dnicoara) Should select the configuration based on what the
// underlying system supports.
SkImageInfo info = SkImageInfo::MakeN32Premul(size_.width(),
......@@ -46,12 +46,12 @@ bool DriSurface::Initialize() {
uint32_t DriSurface::GetFramebufferId() const {
CHECK(backbuffer());
return backbuffer()->framebuffer();
return backbuffer()->GetFramebufferId();
}
uint32_t DriSurface::GetHandle() const {
CHECK(backbuffer());
return backbuffer()->handle();
return backbuffer()->GetHandle();
}
void DriSurface::PreSwapBuffers() {
......@@ -73,7 +73,7 @@ gfx::Size DriSurface::Size() const {
SkCanvas* DriSurface::GetDrawableForWidget() {
CHECK(backbuffer());
return backbuffer()->canvas();
return backbuffer()->GetCanvas();
}
} // namespace ui
......@@ -6,7 +6,7 @@
#define UI_OZONE_PLATFORM_DRI_DRI_SURFACE_H_
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/skia_util.h"
#include "ui/ozone/platform/dri/scanout_surface.h"
......@@ -45,7 +45,7 @@ class DriSurface : public ScanoutSurface {
DriWrapper* dri_;
// The actual buffers used for painting.
scoped_ptr<DriBuffer> bitmaps_[2];
scoped_refptr<DriBuffer> bitmaps_[2];
// Keeps track of which bitmap is |buffers_| is the frontbuffer.
int front_buffer_;
......
......@@ -51,7 +51,7 @@ bool GbmSurface::Initialize() {
if (!native_surface_)
return false;
dumb_buffer_.reset(new DriBuffer(dri_));
dumb_buffer_ = new DriBuffer(dri_);
if (!dumb_buffer_->Initialize(SkImageInfo::MakeN32Premul(size_.width(),
size_.height())))
return false;
......@@ -61,7 +61,7 @@ bool GbmSurface::Initialize() {
uint32_t GbmSurface::GetFramebufferId() const {
if (!buffers_[front_buffer_ ^ 1])
return dumb_buffer_->framebuffer();
return dumb_buffer_->GetFramebufferId();
BufferData* data = BufferData::GetData(buffers_[front_buffer_ ^ 1]);
CHECK(data);
......@@ -70,7 +70,7 @@ uint32_t GbmSurface::GetFramebufferId() const {
uint32_t GbmSurface::GetHandle() const {
if (!buffers_[front_buffer_ ^ 1])
return dumb_buffer_->handle();
return dumb_buffer_->GetHandle();
BufferData* data = BufferData::GetData(buffers_[front_buffer_ ^ 1]);
CHECK(data);
......
......@@ -6,7 +6,7 @@
#define UI_OZONE_PLATFORM_DRI_GBM_SURFACE_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/size.h"
#include "ui/ozone/platform/dri/scanout_surface.h"
......@@ -58,7 +58,7 @@ class GbmSurface : public ScanoutSurface {
// after something draws into it. But modesetting needs to happen earlier,
// before an actual window is created and draws. So, we create a dumb buffer
// for this purpose.
scoped_ptr<DriBuffer> dumb_buffer_;
scoped_refptr<DriBuffer> dumb_buffer_;
DISALLOW_COPY_AND_ASSIGN(GbmSurface);
};
......
// 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.
#ifndef UI_OZONE_PLATFORM_DRI_SCANOUT_BUFFER_H_
#define UI_OZONE_PLATFORM_DRI_SCANOUT_BUFFER_H_
#include <stdint.h>
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/size.h"
namespace ui {
// Abstraction for a DRM buffer that can be scanned-out of.
class ScanoutBuffer : public base::RefCounted<ScanoutBuffer> {
public:
// ID allocated by the KMS API when the buffer is registered (via the handle).
virtual uint32_t GetFramebufferId() const = 0;
// Handle for the buffer. This is received when allocating the buffer.
virtual uint32_t GetHandle() const = 0;
// Size of the buffer.
virtual gfx::Size GetSize() const = 0;
protected:
virtual ~ScanoutBuffer() {}
friend class base::RefCounted<ScanoutBuffer>;
};
class ScanoutBufferGenerator {
public:
virtual ~ScanoutBufferGenerator() {}
virtual scoped_refptr<ScanoutBuffer> Create(const gfx::Size& size) = 0;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_DRI_SCANOUT_BUFFER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment