1
2// Copyright (c) 2012 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_MAC_H_
7#define UI_GFX_CANVAS_PAINT_MAC_H_
8
9#include "skia/ext/platform_canvas.h"
10#include "ui/gfx/canvas.h"
11
12#import <Cocoa/Cocoa.h>
13
14namespace gfx {
15
16// A class designed to translate skia painting into a region to the current
17// graphics context.  On construction, it will set up a context for painting
18// into, and on destruction, it will commit it to the current context.
19// Note: The created context is always inialized to (0, 0, 0, 0).
20class GFX_EXPORT CanvasSkiaPaint : public Canvas {
21 public:
22  // This constructor assumes the result is opaque.
23  explicit CanvasSkiaPaint(NSRect dirtyRect);
24  CanvasSkiaPaint(NSRect dirtyRect, bool opaque);
25  virtual ~CanvasSkiaPaint();
26
27  // If true, the data painted into the CanvasSkiaPaint is blended onto the
28  // current context, else it is copied.
29  void set_composite_alpha(bool composite_alpha) {
30    composite_alpha_ = composite_alpha;
31  }
32
33  // Returns true if the invalid region is empty. The caller should call this
34  // function to determine if anything needs painting.
35  bool is_empty() const {
36    return NSIsEmptyRect(rectangle_);
37  }
38
39  const NSRect& rectangle() const {
40    return rectangle_;
41  }
42
43 private:
44  void Init(bool opaque);
45
46  CGContext* context_;
47  NSRect rectangle_;
48  // See description above setter.
49  bool composite_alpha_;
50
51  // Disallow copy and assign.
52  CanvasSkiaPaint(const CanvasSkiaPaint&);
53  CanvasSkiaPaint& operator=(const CanvasSkiaPaint&);
54};
55
56}  // namespace gfx
57
58
59#endif  // UI_GFX_CANVAS_PAINT_MAC_H_
60