Don't crash when SimpleCache index is corrupt.
[chromium-blink-merge.git] / ui / gfx / canvas_paint_gtk.h
blob889f30895b4726bf695a5559bf9f4d0652205540
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.
6 #ifndef UI_GFX_CANVAS_PAINT_LINUX_H_
7 #define UI_GFX_CANVAS_PAINT_LINUX_H_
9 #include "base/logging.h"
10 #include "skia/ext/platform_canvas.h"
11 #include "ui/gfx/canvas.h"
12 #include <gdk/gdk.h>
14 namespace gfx {
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();
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;
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_);
40 GdkRectangle rectangle() const {
41 GdkRectangle bounds;
42 gdk_region_get_clipbox(region_, &bounds);
43 return bounds;
46 private:
47 void Init(bool opaque);
49 cairo_t* context_;
50 GdkWindow* window_;
51 GdkRegion* region_;
52 // See description above setter.
53 bool composite_alpha_;
55 // Disallow copy and assign.
56 CanvasSkiaPaint(const CanvasSkiaPaint&);
57 CanvasSkiaPaint& operator=(const CanvasSkiaPaint&);
60 } // namespace gfx
62 #endif // UI_GFX_CANVAS_PAINT_LINUX_H_