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

Side by Side Diff: skia/ext/platform_canvas_mac.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/platform_canvas_linux.cc ('k') | skia/ext/platform_canvas_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SKIA_EXT_PLATFORM_CANVAS_MAC_H_
6 #define SKIA_EXT_PLATFORM_CANVAS_MAC_H_
7
8 #include "skia/ext/platform_device_mac.h"
9
10 #include "third_party/skia/include/core/SkCanvas.h"
11
12 namespace skia {
13
14 // This class is a specialization of the regular SkCanvas that is designed to
15 // work with a gfx::PlatformDevice to manage platform-specific drawing. It
16 // allows using both Skia operations and platform-specific operations.
17 class PlatformCanvasMac : public SkCanvas {
18 public:
19 // Set is_opaque if you are going to erase the bitmap and not use
20 // tranparency: this will enable some optimizations. The shared_section
21 // parameter is passed to gfx::PlatformDevice::create. See it for details.
22 //
23 // If you use the version with no arguments, you MUST call initialize()
24 PlatformCanvasMac();
25 PlatformCanvasMac(int width, int height, bool is_opaque);
26 PlatformCanvasMac(int width, int height, bool is_opaque,
27 CGContextRef context);
28 PlatformCanvasMac(int width, int height, bool is_opaque,
29 uint8_t* context);
30 virtual ~PlatformCanvasMac();
31
32 // For two-part init, call if you use the no-argument constructor above
33 bool initialize(int width, int height, bool is_opaque);
34 bool initialize(int width, int height, bool is_opaque, uint8_t* data);
35
36 // These calls should surround calls to platform drawing routines. The CG
37 // context returned by beginPlatformPaint is the one that can be used to
38 // draw into.
39 // Call endPlatformPaint when you are done and want to use Skia operations
40 // again; this will synchronize the bitmap.
41 virtual CGContextRef beginPlatformPaint();
42 virtual void endPlatformPaint();
43
44 // Returns the platform device pointer of the topmost rect with a non-empty
45 // clip. In practice, this is usually either the top layer or nothing, since
46 // we usually set the clip to new layers when we make them.
47 //
48 // If there is no layer that is not all clipped out, this will return a
49 // dummy device so callers do not have to check. If you are concerned about
50 // performance, check the clip before doing any painting.
51 //
52 // This is different than SkCanvas' getDevice, because that returns the
53 // bottommost device.
54 //
55 // Danger: the resulting device should not be saved. It will be invalidated
56 // by the next call to save() or restore().
57 PlatformDeviceMac& getTopPlatformDevice() const;
58
59 // Allow callers to see the non-virtual function even though we have an
60 // override of a virtual one.
61 using SkCanvas::clipRect;
62
63 // Return the stride (length of a line in bytes) for the given width. Because
64 // we use 32-bits per pixel, this will be roughly 4*width. However, for
65 // alignment reasons we may wish to increase that.
66 static size_t StrideForWidth(unsigned width);
67
68 protected:
69 // Creates a device store for use by the canvas. We override this so that
70 // the device is always our own so we know that we can use GDI operations
71 // on it. Simply calls into createPlatformDevice().
72 virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
73 bool is_opaque, bool isForLayer);
74
75 // Creates a device store for use by the canvas. By default, it creates a
76 // BitmapPlatformDevice object. Can be overridden to change the object type.
77 virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
78 CGContextRef context);
79
80 private:
81 // Unimplemented. This is to try to prevent people from calling this function
82 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this
83 // 100%, but hopefully this will make people notice and not use the function.
84 // Calling SkCanvas' version will create a new device which is not compatible
85 // with us and we will crash if somebody tries to draw into it with
86 // CoreGraphics.
87 SkDevice* setBitmapDevice(const SkBitmap& bitmap);
88
89 // Disallow copy and assign.
90 PlatformCanvasMac(const PlatformCanvasMac&);
91 PlatformCanvasMac& operator=(const PlatformCanvasMac&);
92 };
93
94 } // namespace skia
95
96 #endif // SKIA_EXT_PLATFORM_CANVAS_MAC_H_
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas_linux.cc ('k') | skia/ext/platform_canvas_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698