summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/backing_store_gtk.h
blob: cede1760168f0e8287f622fa1a14d838188d1f92 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2011 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_RENDERER_HOST_BACKING_STORE_GTK_H_
#define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_
#pragma once

#include <vector>

#include "base/basictypes.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/backing_store.h"
#include "content/common/content_export.h"
#include "ui/base/x/x11_util.h"

namespace gfx {
class Point;
class Rect;
}  // namespace gfx


typedef struct _GdkDrawable GdkDrawable;

class CONTENT_EXPORT BackingStoreGtk : public BackingStore {
 public:
  // Create a backing store on the X server. The visual is an Xlib Visual
  // describing the format of the target window and the depth is the color
  // depth of the X window which will be drawn into.
  BackingStoreGtk(RenderWidgetHost* widget,
                  const gfx::Size& size,
                  void* visual,
                  int depth);

  // This is for unittesting only. An object constructed using this constructor
  // will silently ignore all paints
  BackingStoreGtk(RenderWidgetHost* widget, const gfx::Size& size);

  virtual ~BackingStoreGtk();

  Display* display() const { return display_; }
  XID root_window() const { return root_window_; }

  // Copy from the server-side backing store to the target window
  //   origin: the destination rectangle origin
  //   damage: the area to copy
  //   target: the X id of the target window
  void XShowRect(const gfx::Point &origin, const gfx::Rect& damage,
                 XID target);

  // As above, but use Cairo instead of Xlib.
  void CairoShowRect(const gfx::Rect& damage, GdkDrawable* drawable);

#if defined(TOOLKIT_GTK)
  // Paint the backing store into the target's |dest_rect|.
  void PaintToRect(const gfx::Rect& dest_rect, GdkDrawable* target);
#endif

  // BackingStore implementation.
  virtual size_t MemorySize() OVERRIDE;
  virtual void PaintToBackingStore(
      content::RenderProcessHost* process,
      TransportDIB::Id bitmap,
      const gfx::Rect& bitmap_rect,
      const std::vector<gfx::Rect>& copy_rects,
      const base::Closure& completion_callback,
      bool* scheduled_completion_callback) OVERRIDE;
  virtual bool CopyFromBackingStore(const gfx::Rect& rect,
                                    skia::PlatformCanvas* output) OVERRIDE;
  virtual void ScrollBackingStore(int dx, int dy,
                                  const gfx::Rect& clip_rect,
                                  const gfx::Size& view_size) OVERRIDE;

 private:
  // Paints the bitmap from the renderer onto the backing store without
  // using Xrender to composite the pixmaps.
  void PaintRectWithoutXrender(TransportDIB* bitmap,
                               const gfx::Rect& bitmap_rect,
                               const std::vector<gfx::Rect>& copy_rects);

  // This is the connection to the X server where this backing store will be
  // displayed.
  Display* const display_;
  // What flavor, if any, MIT-SHM (X shared memory) support we have.
  const ui::SharedMemorySupport shared_memory_support_;
  // If this is true, then we can use Xrender to composite our pixmaps.
  const bool use_render_;
  // If |use_render_| is false, this is the number of bits-per-pixel for |depth|
  int pixmap_bpp_;
  // if |use_render_| is false, we need the Visual to get the RGB masks.
  void* const visual_;
  // This is the depth of the target window.
  const int visual_depth_;
  // The parent window (probably a GtkDrawingArea) for this backing store.
  const XID root_window_;
  // This is a handle to the server side pixmap which is our backing store.
  XID pixmap_;
  // This is the RENDER picture pointing at |pixmap_|.
  XID picture_;
  // This is a default graphic context, used in XCopyArea
  void* pixmap_gc_;

  DISALLOW_COPY_AND_ASSIGN(BackingStoreGtk);
};

#endif  // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_