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

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

Issue 2616003003: Revert of Delete Mac & Cairo skia::BitmapPlatformDevice impls (Closed)
Patch Set: Created 3 years, 11 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/bitmap_platform_device.h ('k') | skia/ext/bitmap_platform_device_cairo.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 2013 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_BITMAP_PLATFORM_DEVICE_CAIRO_H_
6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_CAIRO_H_
7
8 #include <stdint.h>
9
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "skia/ext/platform_device.h"
14
15 typedef struct _cairo_surface cairo_surface_t;
16
17 // -----------------------------------------------------------------------------
18 // Image byte ordering on Linux:
19 //
20 // Pixels are packed into 32-bit words these days. Even for 24-bit images,
21 // often 8-bits will be left unused for alignment reasons. Thus, when you see
22 // ARGB as the byte order you have to wonder if that's in memory order or
23 // little-endian order. Here I'll write A.R.G.B to specifiy the memory order.
24 //
25 // GdkPixbuf's provide a nice backing store and defaults to R.G.B.A order.
26 // They'll do the needed byte swapping to match the X server when drawn.
27 //
28 // Skia can be controled in skia/include/corecg/SkUserConfig.h (see bits about
29 // SK_R32_SHIFT). For Linux we define it to be ARGB in registers. For little
30 // endian machines that means B.G.R.A in memory.
31 //
32 // The image loaders are controlled in
33 // webkit/port/platform/image-decoders/ImageDecoder.h (see setRGBA). These are
34 // also configured for ARGB in registers.
35 //
36 // Cairo's only 32-bit mode is ARGB in registers.
37 //
38 // X servers commonly have a 32-bit visual with xRGB in registers (since they
39 // typically don't do alpha blending of drawables at the user level. Composite
40 // extensions aside.)
41 //
42 // We don't use GdkPixbuf because its byte order differs from the rest. Most
43 // importantly, it differs from Cairo which, being a system library, is
44 // something that we can't easily change.
45 // -----------------------------------------------------------------------------
46
47 namespace skia {
48
49 // -----------------------------------------------------------------------------
50 // This is the Linux bitmap backing for Skia. We create a Cairo image surface
51 // to store the backing buffer. This buffer is BGRA in memory (on little-endian
52 // machines).
53 //
54 // For now we are also using Cairo to paint to the Drawables so we provide an
55 // accessor for getting the surface.
56 //
57 // This is all quite ok for test_shell. In the future we will want to use
58 // shared memory between the renderer and the main process at least. In this
59 // case we'll probably create the buffer from a precreated region of memory.
60 // -----------------------------------------------------------------------------
61 class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
62 public:
63 // Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
64 // you should probably be using Create(). This may become private later if
65 // we ever have to share state between some native drawing UI and Skia, like
66 // the Windows and Mac versions of this class do.
67 //
68 // This object takes ownership of @cairo.
69 BitmapPlatformDevice(const SkBitmap& other, cairo_t* cairo);
70 ~BitmapPlatformDevice() override;
71
72 // Constructs a device with size |width| * |height| with contents initialized
73 // to zero. |is_opaque| should be set if the caller knows the bitmap will be
74 // completely opaque and allows some optimizations.
75 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque);
76
77 // This doesn't take ownership of |data|. If |data| is NULL, the contents
78 // of the device are initialized to 0.
79 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
80 uint8_t* data);
81
82 protected:
83 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
84
85 private:
86 // Overridden from PlatformDevice:
87 cairo_t* BeginPlatformPaint(const SkMatrix& transform,
88 const SkIRect& clip_bounds) override;
89
90 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
91 cairo_surface_t* surface);
92
93 // Loads the current transform and clip into the context.
94 void LoadConfig(const SkMatrix& transform, const SkIRect& clip_bounds);
95
96 // Graphics context used to draw into the surface.
97 cairo_t* cairo_;
98
99 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
100 };
101
102 } // namespace skia
103
104 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_CAIRO_H_
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device.h ('k') | skia/ext/bitmap_platform_device_cairo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698