summaryrefslogtreecommitdiffstats
path: root/ui/ozone/platform/drm/gpu/drm_console_buffer.h
blob: 5e92f74aa56f9619344906e66d5c1fc303cf57d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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_DRM_GPU_DRM_CONSOLE_BUFFER_H_
#define UI_OZONE_PLATFORM_DRM_GPU_DRM_CONSOLE_BUFFER_H_

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkSurface.h"

class SkCanvas;

namespace ui {

class DrmDevice;

// Wrapper for the console buffer. This is the buffer that is allocated by
// default by the system and is used when no application is controlling the
// CRTC. 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 DrmConsoleBuffer {
 public:
  DrmConsoleBuffer(const scoped_refptr<DrmDevice>& drm, uint32_t framebuffer);
  ~DrmConsoleBuffer();

  SkCanvas* canvas() { return surface_->getCanvas(); }
  skia::RefPtr<SkImage> image() {
    return skia::AdoptRef(surface_->newImageSnapshot());
  }

  // Memory map the backing pixels and wrap them in |surface_|.
  bool Initialize();

 protected:
  scoped_refptr<DrmDevice> drm_;

  // Wrapper around the native pixel memory.
  skia::RefPtr<SkSurface> surface_;

  // Length of a row of pixels.
  uint32_t stride_;

  // Buffer handle used by the DRM allocator.
  uint32_t handle_;

  // Buffer ID used by the DRM modesettings API.
  uint32_t framebuffer_;

  // Memory map base address.
  void* mmap_base_;

  // Memory map size.
  size_t mmap_size_;

  DISALLOW_COPY_AND_ASSIGN(DrmConsoleBuffer);
};

}  // namespace ui

#endif  // UI_OZONE_PLATFORM_DRM_GPU_DRM_CONSOLE_BUFFER_H_