OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "skia/ext/bitmap_platform_device_linux.h" | 5 #include "skia/ext/bitmap_platform_device_linux.h" |
6 | 6 |
7 #include "skia/ext/bitmap_platform_device_data.h" | 7 #include "skia/ext/bitmap_platform_device_data.h" |
8 | 8 |
9 #include <cairo/cairo.h> | 9 #include <cairo/cairo.h> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 cairo_set_matrix(bitmap_context_, &cairo_matrix); | 68 cairo_set_matrix(bitmap_context_, &cairo_matrix); |
69 | 69 |
70 LoadClipToContext(bitmap_context_, clip_region_); | 70 LoadClipToContext(bitmap_context_, clip_region_); |
71 LoadMatrixToContext(bitmap_context_, transform_); | 71 LoadMatrixToContext(bitmap_context_, transform_); |
72 } | 72 } |
73 | 73 |
74 // We use this static factory function instead of the regular constructor so | 74 // We use this static factory function instead of the regular constructor so |
75 // that we can create the pixel data before calling the constructor. This is | 75 // that we can create the pixel data before calling the constructor. This is |
76 // required so that we can call the base class' constructor with the pixel | 76 // required so that we can call the base class' constructor with the pixel |
77 // data. | 77 // data. |
78 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 78 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, bool i s_opaque, |
vandebo (ex-Chrome)
2011/08/19 21:54:22
Formatting was correct before.
Jeff Timanus
2011/08/20 02:31:04
Done.
| |
79 bool is_opaque, | 79 cairo_surface_t* surface) { |
80 cairo_surface_t* surface) { | |
81 SkBitmap bitmap; | 80 SkBitmap bitmap; |
82 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, | 81 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, |
83 cairo_image_surface_get_stride(surface)); | 82 cairo_image_surface_get_stride(surface)); |
84 bitmap.setPixels(cairo_image_surface_get_data(surface)); | 83 bitmap.setPixels(cairo_image_surface_get_data(surface)); |
85 bitmap.setIsOpaque(is_opaque); | 84 bitmap.setIsOpaque(is_opaque); |
86 | 85 |
87 // The device object will take ownership of the graphics context. | 86 // The device object will take ownership of the graphics context. |
88 return new BitmapPlatformDevice | 87 return new BitmapPlatformDevice |
89 (bitmap, new BitmapPlatformDeviceData(surface)); | 88 (bitmap, new BitmapPlatformDeviceData(surface)); |
90 } | 89 } |
91 | 90 |
92 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 91 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, bool i s_opaque) { |
vandebo (ex-Chrome)
2011/08/19 21:54:22
Formatting was correct before.
Jeff Timanus
2011/08/20 02:31:04
Done.
| |
93 bool is_opaque) { | |
94 cairo_surface_t* surface = | 92 cairo_surface_t* surface = |
95 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | 93 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
96 width, height); | 94 width, height); |
97 | 95 |
98 BitmapPlatformDevice* device = Create(width, height, is_opaque, surface); | 96 BitmapPlatformDevice* device = Create(width, height, is_opaque, surface); |
99 | 97 |
100 #ifndef NDEBUG | 98 #ifndef NDEBUG |
101 if (is_opaque) // Fill with bright bluish green | 99 if (is_opaque) // Fill with bright bluish green |
102 device->eraseColor(SkColorSetARGB(255, 0, 255, 128)); | 100 device->eraseColor(SkColorSetARGB(255, 0, 255, 128)); |
103 #endif | 101 #endif |
104 | 102 |
105 return device; | 103 return device; |
106 } | 104 } |
107 | 105 |
108 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 106 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, bool i s_opaque, |
vandebo (ex-Chrome)
2011/08/19 21:54:22
Formatting was correct before.
Jeff Timanus
2011/08/20 02:31:04
Done.
| |
109 bool is_opaque, | |
110 uint8_t* data) { | 107 uint8_t* data) { |
111 cairo_surface_t* surface = cairo_image_surface_create_for_data( | 108 cairo_surface_t* surface = cairo_image_surface_create_for_data( |
112 data, CAIRO_FORMAT_ARGB32, width, height, | 109 data, CAIRO_FORMAT_ARGB32, width, height, |
113 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width)); | 110 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width)); |
114 | 111 |
115 return Create(width, height, is_opaque, surface); | 112 return Create(width, height, is_opaque, surface); |
116 } | 113 } |
117 | 114 |
118 // The device will own the bitmap, which corresponds to also owning the pixel | 115 // The device will own the bitmap, which corresponds to also owning the pixel |
119 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 116 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
120 BitmapPlatformDevice::BitmapPlatformDevice( | 117 BitmapPlatformDevice::BitmapPlatformDevice( |
121 const SkBitmap& bitmap, | 118 const SkBitmap& bitmap, |
122 BitmapPlatformDeviceData* data) | 119 BitmapPlatformDeviceData* data) |
123 : PlatformDevice(bitmap), | 120 : PlatformDevice(this), |
121 SkDevice(bitmap), | |
124 data_(data) { | 122 data_(data) { |
123 | |
124 // Pass false, because BitmapPlatformDevice inherits both SkDevice, and | |
125 // PlatformDevice, so there is no need to explicitly bind the lifetime of the | |
126 // two classes. | |
127 SetPlatformDevice(this, this, false); | |
125 } | 128 } |
126 | 129 |
127 BitmapPlatformDevice::~BitmapPlatformDevice() { | 130 BitmapPlatformDevice::~BitmapPlatformDevice() { |
128 } | 131 } |
129 | 132 |
130 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 133 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
131 SkBitmap::Config config, int width, int height, bool isOpaque, | 134 SkBitmap::Config config, int width, int height, bool isOpaque, |
132 Usage /*usage*/) { | 135 Usage /*usage*/) { |
133 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 136 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
134 return BitmapPlatformDevice::Create(width, height, isOpaque); | 137 return BitmapPlatformDevice::Create(width, height, isOpaque); |
(...skipping 11 matching lines...) Expand all Loading... | |
146 return cairo; | 149 return cairo; |
147 } | 150 } |
148 | 151 |
149 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, | 152 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, |
150 const SkRegion& region, | 153 const SkRegion& region, |
151 const SkClipStack&) { | 154 const SkClipStack&) { |
152 data_->SetMatrixClip(transform, region); | 155 data_->SetMatrixClip(transform, region); |
153 } | 156 } |
154 | 157 |
155 } // namespace skia | 158 } // namespace skia |
OLD | NEW |