1 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef UI_GFX_CANVAS_PAINT_LINUX_H_ 7 #define UI_GFX_CANVAS_PAINT_LINUX_H_ 8 9 #include "base/logging.h" 10 #include "skia/ext/platform_canvas.h" 11 #include "ui/gfx/canvas.h" 12 #include <gdk/gdk.h> 13 14 namespace gfx { 15 16 // A class designed to translate skia painting into a region in a GdkWindow. 17 // On construction, it will set up a context for painting into, and on 18 // destruction, it will commit it to the GdkWindow. 19 // Note: The created context is always inialized to (0, 0, 0, 0). 20 class UI_EXPORT CanvasSkiaPaint : public Canvas { 21 public: 22 // This constructor assumes the result is opaque. 23 explicit CanvasSkiaPaint(GdkEventExpose* event); 24 CanvasSkiaPaint(GdkEventExpose* event, bool opaque); 25 virtual ~CanvasSkiaPaint(); 26 27 // Sets whether the bitmap is composited in such a way that the alpha channel 28 // is honored. This is only useful if you've enabled an RGBA colormap on the 29 // widget. The default is false. 30 void set_composite_alpha(bool composite_alpha) { 31 composite_alpha_ = composite_alpha; 32 } 33 34 // Returns true if the invalid region is empty. The caller should call this 35 // function to determine if anything needs painting. 36 bool is_empty() const { 37 return gdk_region_empty(region_); 38 } 39 40 GdkRectangle rectangle() const { 41 GdkRectangle bounds; 42 gdk_region_get_clipbox(region_, &bounds); 43 return bounds; 44 } 45 46 private: 47 void Init(bool opaque); 48 49 cairo_t* context_; 50 GdkWindow* window_; 51 GdkRegion* region_; 52 // See description above setter. 53 bool composite_alpha_; 54 55 // Disallow copy and assign. 56 CanvasSkiaPaint(const CanvasSkiaPaint&); 57 CanvasSkiaPaint& operator=(const CanvasSkiaPaint&); 58 }; 59 60 } // namespace gfx 61 62 #endif // UI_GFX_CANVAS_PAINT_LINUX_H_ 63