Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: skia/ext/platform_canvas.h

Issue 125109: Refactor the PlatformContext layer to have only one class. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/ext/canvas_paint_win.h ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Declare a platform-neutral name for this platform's canvas class 5 #ifndef SKIA_EXT_PLATFORM_CANVAS_H_
6 // that can be used by upper-level classes that just need to pass a reference 6 #define SKIA_EXT_PLATFORM_CANVAS_H_
7 // around.
8 7
9 #if defined(WIN32) 8 // The platform-specific device will include the necessary platform headers
10 #include "skia/ext/platform_canvas_win.h" 9 // to get the surface type.
11 #elif defined(__APPLE__) 10 #include "skia/ext/platform_device.h"
12 #include "skia/ext/platform_canvas_mac.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
13 #elif defined(__linux__)
14 #include "skia/ext/platform_canvas_linux.h"
15 #endif
16 12
17 namespace skia { 13 namespace skia {
18 14
15 // This class is a specialization of the regular SkCanvas that is designed to
16 // work with a PlatformDevice to manage platform-specific drawing. It allows
17 // using both Skia operations and platform-specific operations.
18 class PlatformCanvas : public SkCanvas {
19 public:
20 // Set is_opaque if you are going to erase the bitmap and not use
21 // transparency: this will enable some optimizations.
22 // If you use the version with no arguments, you MUST call initialize()
23 PlatformCanvas();
24 PlatformCanvas(int width, int height, bool is_opaque);
25 virtual ~PlatformCanvas();
26
19 #if defined(WIN32) 27 #if defined(WIN32)
20 typedef PlatformCanvasWin PlatformCanvas; 28 // Windows ------------------------------------------------------------------
29
30 // The shared_section parameter is passed to gfx::PlatformDevice::create.
31 // See it for details.
32 PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section);
33
34 // For two-part init, call if you use the no-argument constructor above. Note
35 // that we want this to optionally match the Linux initialize if you only
36 // pass 3 arguments, hence the evil default argument.
37 bool initialize(int width, int height, bool is_opaque,
38 HANDLE shared_section = NULL);
39
21 #elif defined(__APPLE__) 40 #elif defined(__APPLE__)
22 typedef PlatformCanvasMac PlatformCanvas; 41 // Mac -----------------------------------------------------------------------
42
43 PlatformCanvas(int width, int height, bool is_opaque,
44 CGContextRef context);
45 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context);
46
47 // For two-part init, call if you use the no-argument constructor above
48 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL);
49
23 #elif defined(__linux__) 50 #elif defined(__linux__)
24 typedef PlatformCanvasLinux PlatformCanvas; 51 // Linux ---------------------------------------------------------------------
52
53 // Construct a canvas from the given memory region. The memory is not cleared
54 // first. @data must be, at least, @height * StrideForWidth(@width) bytes.
55 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data);
56
57 // For two-part init, call if you use the no-argument constructor above
58 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL);
59
25 #endif 60 #endif
61 // Shared --------------------------------------------------------------------
62
63 // These calls should surround calls to platform drawing routines, the
64 // surface returned here can be used with the native platform routines
65 //
66 // Call endPlatformPaint when you are done and want to use Skia operations
67 // after calling the platform-specific beginPlatformPaint; this will
68 // synchronize the bitmap to OS if necessary.
69 PlatformDevice::PlatformSurface beginPlatformPaint();
70 void endPlatformPaint();
71
72 // Returns the platform device pointer of the topmost rect with a non-empty
73 // clip. In practice, this is usually either the top layer or nothing, since
74 // we usually set the clip to new layers when we make them.
75 //
76 // If there is no layer that is not all clipped out, this will return a
77 // dummy device so callers do not have to check. If you are concerned about
78 // performance, check the clip before doing any painting.
79 //
80 // This is different than SkCanvas' getDevice, because that returns the
81 // bottommost device.
82 //
83 // Danger: the resulting device should not be saved. It will be invalidated
84 // by the next call to save() or restore().
85 PlatformDevice& getTopPlatformDevice() const;
86
87 // Return the stride (length of a line in bytes) for the given width. Because
88 // we use 32-bits per pixel, this will be roughly 4*width. However, for
89 // alignment reasons we may wish to increase that.
90 static size_t StrideForWidth(unsigned width);
91
92 // Allow callers to see the non-virtual function even though we have an
93 // override of a virtual one.
94 // FIXME(brettw) is this necessary?
95 using SkCanvas::clipRect;
96
97 protected:
98 // Creates a device store for use by the canvas. We override this so that
99 // the device is always our own so we know that we can use platform
100 // operations on it.
101 virtual SkDevice* createDevice(SkBitmap::Config,
102 int width,
103 int height,
104 bool is_opaque,
105 bool isForLayer);
106
107 private:
108 // Unimplemented. This is to try to prevent people from calling this function
109 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this
110 // 100%, but hopefully this will make people notice and not use the function.
111 // Calling SkCanvas' version will create a new device which is not compatible
112 // with us and we will crash if somebody tries to draw into it with
113 // CoreGraphics.
114 virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
115
116 // Disallow copy and assign.
117 PlatformCanvas(const PlatformCanvas&);
118 PlatformCanvas& operator=(const PlatformCanvas&);
119 };
26 120
27 } // namespace skia 121 } // namespace skia
122
123 #endif // SKIA_EXT_PLATFORM_CANVAS_H_
OLDNEW
« no previous file with comments | « skia/ext/canvas_paint_win.h ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698