| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/backing_store.h" | 5 #include "chrome/browser/renderer_host/backing_store.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "chrome/common/transport_dib.h" | 12 #include "chrome/common/transport_dib.h" |
| 13 #include "chrome/common/x11_util.h" | 13 #include "chrome/common/x11_util.h" |
| 14 #include "chrome/common/x11_util_internal.h" | 14 #include "chrome/common/x11_util_internal.h" |
| 15 | 15 |
| 16 // X Backing Stores: | 16 // X Backing Stores: |
| 17 // | 17 // |
| 18 // Unlike Windows, where the backing store is kept in heap memory, we keep our | 18 // Unlike Windows, where the backing store is kept in heap memory, we keep our |
| 19 // backing store in the X server, as a pixmap. Thus expose events just require | 19 // backing store in the X server, as a pixmap. Thus expose events just require |
| 20 // instructing the X server to copy from the backing store to the window. | 20 // instructing the X server to copy from the backing store to the window. |
| 21 // | 21 // |
| 22 // The backing store is in the same format as the visual which our main window | 22 // The backing store is in the same format as the visual which our main window |
| 23 // is using. Bitmaps from the renderer are uploaded to the X server, either via | 23 // is using. Bitmaps from the renderer are uploaded to the X server, either via |
| 24 // shared memory or over the wire, and XRENDER is used to convert them to the | 24 // shared memory or over the wire, and XRENDER is used to convert them to the |
| 25 // correct format for the backing store. | 25 // correct format for the backing store. |
| 26 | 26 |
| 27 BackingStore::BackingStore(const gfx::Size& size, | 27 BackingStore::BackingStore(RenderWidgetHost* widget, |
| 28 Display* display, | 28 const gfx::Size& size, |
| 29 int depth, | |
| 30 void* visual, | 29 void* visual, |
| 31 Drawable root_window, | 30 int depth) |
| 32 bool use_render, | 31 : render_widget_host_(widget), |
| 33 bool use_shared_memory) | 32 size_(size), |
| 34 : size_(size), | 33 display_(x11_util::GetXDisplay()), |
| 35 display_(display), | 34 use_shared_memory_(x11_util::QuerySharedMemorySupport(display_)), |
| 36 use_shared_memory_(use_shared_memory), | 35 use_render_(x11_util::QueryRenderSupport(display_)), |
| 37 use_render_(use_render), | |
| 38 visual_depth_(depth), | 36 visual_depth_(depth), |
| 39 root_window_(root_window) { | 37 root_window_(x11_util::GetX11RootWindow()) { |
| 40 const int width = size.width(); | |
| 41 const int height = size.height(); | |
| 42 | |
| 43 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, assumes_little_endian); | 38 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, assumes_little_endian); |
| 44 | 39 |
| 45 pixmap_ = XCreatePixmap(display_, root_window, width, height, depth); | 40 pixmap_ = XCreatePixmap(display_, root_window_, |
| 41 size.width(), size.height(), depth); |
| 46 | 42 |
| 47 if (use_render_) { | 43 if (use_render_) { |
| 48 picture_ = XRenderCreatePicture( | 44 picture_ = XRenderCreatePicture( |
| 49 display_, pixmap_, | 45 display_, pixmap_, |
| 50 x11_util::GetRenderVisualFormat(display_, static_cast<Visual*>(visual)), | 46 x11_util::GetRenderVisualFormat(display_, |
| 51 0, NULL); | 47 static_cast<Visual*>(visual)), |
| 48 0, NULL); |
| 52 } else { | 49 } else { |
| 53 picture_ = 0; | 50 picture_ = 0; |
| 54 pixmap_bpp_ = x11_util::BitsPerPixelForPixmapDepth(display, depth); | 51 pixmap_bpp_ = x11_util::BitsPerPixelForPixmapDepth(display_, depth); |
| 55 } | 52 } |
| 56 | 53 |
| 57 pixmap_gc_ = XCreateGC(display_, pixmap_, 0, NULL); | 54 pixmap_gc_ = XCreateGC(display_, pixmap_, 0, NULL); |
| 58 } | 55 } |
| 59 | 56 |
| 60 BackingStore::BackingStore(const gfx::Size& size) | 57 BackingStore::BackingStore(RenderWidgetHost* widget, const gfx::Size& size) |
| 61 : size_(size), | 58 : render_widget_host_(widget), |
| 59 size_(size), |
| 62 display_(NULL), | 60 display_(NULL), |
| 63 use_shared_memory_(false), | 61 use_shared_memory_(false), |
| 64 use_render_(false), | 62 use_render_(false), |
| 65 visual_depth_(-1), | 63 visual_depth_(-1), |
| 66 root_window_(0) { | 64 root_window_(0) { |
| 67 } | 65 } |
| 68 | 66 |
| 69 BackingStore::~BackingStore() { | 67 BackingStore::~BackingStore() { |
| 70 // In unit tests, display_ may be NULL. | 68 // In unit tests, display_ may be NULL. |
| 71 if (!display_) | 69 if (!display_) |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 304 } |
| 307 | 305 |
| 308 PaintRect(process, bitmap, bitmap_rect); | 306 PaintRect(process, bitmap, bitmap_rect); |
| 309 } | 307 } |
| 310 | 308 |
| 311 void BackingStore::ShowRect(const gfx::Rect& rect, XID target) { | 309 void BackingStore::ShowRect(const gfx::Rect& rect, XID target) { |
| 312 XCopyArea(display_, pixmap_, target, static_cast<GC>(pixmap_gc_), | 310 XCopyArea(display_, pixmap_, target, static_cast<GC>(pixmap_gc_), |
| 313 rect.x(), rect.y(), rect.width(), rect.height(), | 311 rect.x(), rect.y(), rect.width(), rect.height(), |
| 314 rect.x(), rect.y()); | 312 rect.x(), rect.y()); |
| 315 } | 313 } |
| OLD | NEW |