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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
// Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_
#define CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_
#include "base/basictypes.h"
#include "base/gfx/rect.h"
#include "base/gfx/size.h"
#include "base/process.h"
#include "build/build_config.h"
#include "chrome/common/mru_cache.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
#include "skia/ext/platform_canvas.h"
#elif defined(OS_LINUX)
#include "chrome/common/x11_util.h"
#endif
class RenderWidgetHost;
class TransportDIB;
// BackingStore ----------------------------------------------------------------
// Represents a backing store for the pixels in a RenderWidgetHost.
class BackingStore {
public:
#if defined(OS_WIN) || defined(OS_MACOSX)
explicit BackingStore(const gfx::Size& size);
#elif defined(OS_LINUX)
// Create a backing store on the X server.
// size: the size of the server-side pixmap
// x_connection: the display to target
// depth: the depth of the X window which will be drawn into
// visual: An Xlib Visual describing the format of the target window
// root_window: The X id of the root window
// use_render: if true, the X server supports Xrender
// use_shared_memory: if true, the X server is local
BackingStore(const gfx::Size& size, Display* x_connection, int depth,
void* visual, XID root_window, bool use_render,
bool use_shared_memory);
// This is for unittesting only. An object constructed using this constructor
// will silently ignore all paints
explicit BackingStore(const gfx::Size& size);
#endif
~BackingStore();
const gfx::Size& size() { return size_; }
#if defined(OS_WIN)
HDC hdc() { return hdc_; }
#elif defined(OS_MACOSX)
skia::PlatformCanvas* canvas() { return &canvas_; }
#elif defined(OS_LINUX)
// Copy from the server-side backing store to the target window
// display: the display of the backing store and target window
// damage: the area to copy
// target: the X id of the target window
void ShowRect(const gfx::Rect& damage, XID target);
#endif
// Paints the bitmap from the renderer onto the backing store.
void PaintRect(base::ProcessHandle process,
TransportDIB* bitmap,
const gfx::Rect& bitmap_rect);
// Scrolls the given rect in the backing store, replacing the given region
// identified by |bitmap_rect| by the bitmap in the file identified by the
// given file handle.
void ScrollRect(base::ProcessHandle process,
TransportDIB* bitmap, const gfx::Rect& bitmap_rect,
int dx, int dy,
const gfx::Rect& clip_rect,
const gfx::Size& view_size);
private:
// The size of the backing store.
gfx::Size size_;
#if defined(OS_WIN)
// The backing store dc.
HDC hdc_;
// Handle to the backing store dib.
HANDLE backing_store_dib_;
// Handle to the original bitmap in the dc.
HANDLE original_bitmap_;
// Number of bits per pixel of the screen.
int color_depth_;
#elif defined(OS_MACOSX)
skia::PlatformCanvas canvas_;
#elif defined(OS_LINUX)
// 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);
// This is the connection to the X server where this backing store will be
// displayed.
Display *const display_;
// If this is true, then |connection_| is good for MIT-SHM (X shared memory).
const bool use_shared_memory_;
// 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_;
// 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_;
#endif
DISALLOW_COPY_AND_ASSIGN(BackingStore);
};
// BackingStoreManager ---------------------------------------------------------
// This class manages backing stores in the browsr. Every RenderWidgetHost is
// associated with a backing store which it requests from this class. The
// hosts don't maintain any references to the backing stores. These backing
// stores are maintained in a cache which can be trimmed as needed.
class BackingStoreManager {
public:
// Returns a backing store which matches the desired dimensions.
//
// backing_store_rect
// The desired backing store dimensions.
// Returns a pointer to the backing store on success, NULL on failure.
static BackingStore* GetBackingStore(RenderWidgetHost* host,
const gfx::Size& desired_size);
// Returns a backing store which is fully ready for consumption, i.e. the
// bitmap from the renderer has been copied into the backing store dc, or the
// bitmap in the backing store dc references the renderer bitmap.
//
// backing_store_size
// The desired backing store dimensions.
// process_handle
// The renderer process handle.
// bitmap_section
// The bitmap section from the renderer.
// bitmap_rect
// The rect to be painted into the backing store
// needs_full_paint
// Set if we need to send out a request to paint the view
// to the renderer.
static BackingStore* PrepareBackingStore(RenderWidgetHost* host,
const gfx::Size& backing_store_size,
base::ProcessHandle process_handle,
TransportDIB* bitmap,
const gfx::Rect& bitmap_rect,
bool* needs_full_paint);
// Returns a matching backing store for the host.
// Returns NULL if we fail to find one.
static BackingStore* Lookup(RenderWidgetHost* host);
// Removes the backing store for the host.
static void RemoveBackingStore(RenderWidgetHost* host);
private:
// Not intended for instantiation.
BackingStoreManager() {}
DISALLOW_COPY_AND_ASSIGN(BackingStoreManager);
};
#endif // CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_
|