1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ 7 8 #include <vector> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "build/build_config.h" 13 #include "content/browser/renderer_host/backing_store.h" 14 #include "content/common/content_export.h" 15 #include "ui/gfx/x/x11_types.h" 16 17 namespace gfx { 18 class Point; 19 class Rect; 20 } 21 22 typedef struct _GdkDrawable GdkDrawable; 23 24 namespace content { 25 26 class CONTENT_EXPORT BackingStoreGtk : public BackingStore { 27 public: 28 // Create a backing store on the X server. The visual is an Xlib Visual 29 // describing the format of the target window and the depth is the color 30 // depth of the X window which will be drawn into. 31 BackingStoreGtk(RenderWidgetHost* widget, 32 const gfx::Size& size, 33 void* visual, 34 int depth); 35 36 // This is for unittesting only. An object constructed using this constructor 37 // will silently ignore all paints 38 BackingStoreGtk(RenderWidgetHost* widget, const gfx::Size& size); 39 40 virtual ~BackingStoreGtk(); 41 42 XDisplay* display() const { return display_; } 43 XID root_window() const { return root_window_; } 44 45 // Copy from the server-side backing store to the target window 46 // origin: the destination rectangle origin 47 // damage: the area to copy 48 // target: the X id of the target window 49 void XShowRect(const gfx::Point &origin, const gfx::Rect& damage, 50 XID target); 51 52 #if defined(TOOLKIT_GTK) 53 // Paint the backing store into the target's |dest_rect|. 54 void PaintToRect(const gfx::Rect& dest_rect, GdkDrawable* target); 55 #endif 56 57 // BackingStore implementation. 58 virtual size_t MemorySize() OVERRIDE; 59 virtual void PaintToBackingStore( 60 RenderProcessHost* process, 61 TransportDIB::Id bitmap, 62 const gfx::Rect& bitmap_rect, 63 const std::vector<gfx::Rect>& copy_rects, 64 float scale_factor, 65 const base::Closure& completion_callback, 66 bool* scheduled_completion_callback) OVERRIDE; 67 virtual bool CopyFromBackingStore(const gfx::Rect& rect, 68 skia::PlatformBitmap* output) OVERRIDE; 69 virtual void ScrollBackingStore(const gfx::Vector2d& delta, 70 const gfx::Rect& clip_rect, 71 const gfx::Size& view_size) OVERRIDE; 72 73 private: 74 // Paints the bitmap from the renderer onto the backing store without 75 // using Xrender to composite the pixmaps. 76 void PaintRectWithoutXrender(TransportDIB* bitmap, 77 const gfx::Rect& bitmap_rect, 78 const std::vector<gfx::Rect>& copy_rects); 79 80 // This is the connection to the X server where this backing store will be 81 // displayed. 82 XDisplay* const display_; 83 // What flavor, if any, MIT-SHM (X shared memory) support we have. 84 const ui::SharedMemorySupport shared_memory_support_; 85 // If this is true, then we can use Xrender to composite our pixmaps. 86 const bool use_render_; 87 // If |use_render_| is false, this is the number of bits-per-pixel for |depth| 88 int pixmap_bpp_; 89 // if |use_render_| is false, we need the Visual to get the RGB masks. 90 void* const visual_; 91 // This is the depth of the target window. 92 const int visual_depth_; 93 // The parent window (probably a GtkDrawingArea) for this backing store. 94 const XID root_window_; 95 // This is a handle to the server side pixmap which is our backing store. 96 XID pixmap_; 97 // This is the RENDER picture pointing at |pixmap_|. 98 XID picture_; 99 // This is a default graphic context, used in XCopyArea 100 void* pixmap_gc_; 101 102 DISALLOW_COPY_AND_ASSIGN(BackingStoreGtk); 103 }; 104 105 } // namespace content 106 107 #endif // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_GTK_H_ 108