summaryrefslogtreecommitdiff
path: root/chromium/content/browser/compositor/software_output_device_win.h
blob: 5c80340808c2437442cee1d35b4359b2ab9a1d31 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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 CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_WIN_H_
#define CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_WIN_H_

#include <windows.h>
#include <stddef.h>

#include <vector>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "cc/output/software_output_device.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkRefCnt.h"

namespace base {
class SharedMemory;
}

namespace ui {
class Compositor;
}

namespace content {
class SoftwareOutputDeviceWin;

class OutputDeviceBacking {
 public:
  OutputDeviceBacking();
  ~OutputDeviceBacking();

  void Resized();
  void RegisterOutputDevice(SoftwareOutputDeviceWin* device);
  void UnregisterOutputDevice(SoftwareOutputDeviceWin* device);
  base::SharedMemory* GetSharedMemory(const gfx::Size& size);

 private:
  size_t GetMaxByteSize();

  std::vector<SoftwareOutputDeviceWin*> devices_;
  scoped_ptr<base::SharedMemory> backing_;
  size_t created_byte_size_;

  DISALLOW_COPY_AND_ASSIGN(OutputDeviceBacking);
};

class SoftwareOutputDeviceWin : public cc::SoftwareOutputDevice {
 public:
  SoftwareOutputDeviceWin(OutputDeviceBacking* backing,
                          ui::Compositor* compositor);
  ~SoftwareOutputDeviceWin() override;

  void Resize(const gfx::Size& viewport_pixel_size,
              float scale_factor) override;
  SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override;
  void EndPaint() override;

  gfx::Size viewport_pixel_size() const { return viewport_pixel_size_; }
  void ReleaseContents();

 private:
  HWND hwnd_;
  sk_sp<SkCanvas> contents_;
  bool is_hwnd_composited_;
  OutputDeviceBacking* backing_;
  bool in_paint_;

  DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceWin);
};

}  // namespace content

#endif  // CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_WIN_H_