summaryrefslogtreecommitdiffstats
path: root/skia/ext/vector_canvas.h
blob: d4f76f854af87b4eab0741867bd080dc41f26f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKIA_EXT_VECTOR_CANVAS_H_
#define SKIA_EXT_VECTOR_CANVAS_H_

#include "skia/ext/platform_canvas.h"
#include "skia/ext/vector_platform_device.h"

#if defined(__linux__)
typedef struct _cairo cairo_t;
#endif

namespace skia {

// This class is a specialization of the regular PlatformCanvas. It is designed
// to work with a VectorDevice to manage platform-specific drawing. It allows
// using both Skia operations and platform-specific operations. It *doesn't*
// support reading back from the bitmap backstore since it is not used.
class VectorCanvas : public PlatformCanvas {
 public:
  VectorCanvas();
#if defined(WIN32)
  VectorCanvas(HDC dc, int width, int height);
#elif defined(__linux__)
  // Caller owns |context|. Ownership is not transferred.
  VectorCanvas(cairo_t* context, int width, int height);
#endif
  virtual ~VectorCanvas();

  // For two-part init, call if you use the no-argument constructor above
#if defined(WIN32)
  bool initialize(HDC context, int width, int height);
#elif defined(__linux__)
  // Ownership of |context| is not transferred.
  bool initialize(cairo_t* context, int width, int height);
#endif

  virtual SkBounder* setBounder(SkBounder* bounder);
#if defined(WIN32) || defined(__linux__)
  virtual SkDevice* createDevice(SkBitmap::Config config,
                                 int width, int height,
                                 bool is_opaque, bool isForLayer);
#endif
  virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);

 private:
#if defined(WIN32)
  // |shared_section| is in fact the HDC used for output. |is_opaque| is unused.
  virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
                                         HANDLE shared_section);
#elif defined(__linux__)
  // Ownership of |context| is not transferred. |is_opaque| is unused.
  virtual SkDevice* createPlatformDevice(cairo_t* context,
                                         int width, int height,
                                         bool is_opaque);
#endif

  // Returns true if the top device is vector based and not bitmap based.
  bool IsTopDeviceVectorial() const;

  // Copy & assign are not supported.
  VectorCanvas(const VectorCanvas&);
  const VectorCanvas& operator=(const VectorCanvas&);
};

}  // namespace skia

#endif  // SKIA_EXT_VECTOR_CANVAS_H_