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
3// found in the LICENSE file.
4
5#ifndef UI_OZONE_PLATFORM_DRI_DRI_BUFFER_H_
6#define UI_OZONE_PLATFORM_DRI_DRI_BUFFER_H_
7
8#include "base/macros.h"
9#include "skia/ext/refptr.h"
10#include "third_party/skia/include/core/SkSurface.h"
11#include "ui/ozone/ozone_export.h"
12
13class SkCanvas;
14
15namespace ui {
16
17class DriWrapper;
18
19// Wrapper for a DRM allocated buffer. Keeps track of the native properties of
20// the buffer and wraps the pixel memory into a SkSurface which can be used to
21// draw into using Skia.
22class OZONE_EXPORT DriBuffer {
23 public:
24  DriBuffer(DriWrapper* dri);
25  virtual ~DriBuffer();
26
27  uint32_t stride() const { return stride_; }
28  uint32_t handle() const { return handle_; }
29  uint32_t framebuffer() const { return framebuffer_; }
30  SkCanvas* canvas() { return surface_->getCanvas(); }
31
32  // Allocates the backing pixels and wraps them in |surface_|. |info| is used
33  // to describe the buffer characteristics (size, color format).
34  virtual bool Initialize(const SkImageInfo& info);
35
36 protected:
37  DriWrapper* dri_;  // Not owned.
38
39  // Wrapper around the native pixel memory.
40  skia::RefPtr<SkSurface> surface_;
41
42  // Length of a row of pixels.
43  uint32_t stride_;
44
45  // Buffer handle used by the DRM allocator.
46  uint32_t handle_;
47
48  // Buffer ID used by the DRM modesettings API. This is set when the buffer is
49  // registered with the CRTC.
50  uint32_t framebuffer_;
51
52  DISALLOW_COPY_AND_ASSIGN(DriBuffer);
53};
54
55}  // namespace ui
56
57#endif  // UI_OZONE_PLATFORM_DRI_DRI_BUFFER_H_
58