| OLD | NEW |
| 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 #include "skia/ext/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 | 140 |
| 141 // We use this static factory function instead of the regular constructor so | 141 // We use this static factory function instead of the regular constructor so |
| 142 // that we can create the pixel data before calling the constructor. This is | 142 // that we can create the pixel data before calling the constructor. This is |
| 143 // required so that we can call the base class' constructor with the pixel | 143 // required so that we can call the base class' constructor with the pixel |
| 144 // data. | 144 // data. |
| 145 BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, | 145 BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context, |
| 146 int width, | 146 int width, |
| 147 int height, | 147 int height, |
| 148 bool is_opaque) { | 148 bool is_opaque) { |
| 149 void* data = malloc(height * width * 4); | |
| 150 if (!data) return NULL; | |
| 151 | |
| 152 SkBitmap bitmap; | 149 SkBitmap bitmap; |
| 153 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 150 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 154 bitmap.setPixels(data); | 151 if (bitmap.allocPixels() != true) |
| 152 return NULL; |
| 153 void* data = bitmap.getPixels(); |
| 155 | 154 |
| 156 // Note: The Windows implementation clears the Bitmap later on. | 155 // Note: The Windows implementation clears the Bitmap later on. |
| 157 // This bears mentioning since removal of this line makes the | 156 // This bears mentioning since removal of this line makes the |
| 158 // unit tests only fail periodically (or when MallocPreScribble is set). | 157 // unit tests only fail periodically (or when MallocPreScribble is set). |
| 159 bitmap.eraseARGB(0, 0, 0, 0); | 158 bitmap.eraseARGB(0, 0, 0, 0); |
| 160 | 159 |
| 161 bitmap.setIsOpaque(is_opaque); | 160 bitmap.setIsOpaque(is_opaque); |
| 162 | 161 |
| 163 if (is_opaque) { | 162 if (is_opaque) { |
| 164 #ifndef NDEBUG | 163 #ifndef NDEBUG |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 const BitmapPlatformDeviceMac& other) { | 216 const BitmapPlatformDeviceMac& other) { |
| 218 data_ = other.data_; | 217 data_ = other.data_; |
| 219 data_->ref(); | 218 data_->ref(); |
| 220 return *this; | 219 return *this; |
| 221 } | 220 } |
| 222 | 221 |
| 223 CGContextRef BitmapPlatformDeviceMac::GetBitmapContext() { | 222 CGContextRef BitmapPlatformDeviceMac::GetBitmapContext() { |
| 224 return data_->GetBitmapContext(); | 223 return data_->GetBitmapContext(); |
| 225 } | 224 } |
| 226 | 225 |
| 227 void BitmapPlatformDeviceMac::setMatrixClip(const SkMatrix& transform, | 226 void BitmapPlatformDeviceMac::setMatrixClip(const SkMatrix& transform, |
| 228 const SkRegion& region) { | 227 const SkRegion& region) { |
| 229 data_->SetMatrixClip(transform, region); | 228 data_->SetMatrixClip(transform, region); |
| 230 } | 229 } |
| 231 | 230 |
| 232 void BitmapPlatformDeviceMac::DrawToContext(CGContextRef context, int x, int y, | 231 void BitmapPlatformDeviceMac::DrawToContext(CGContextRef context, int x, int y, |
| 233 const CGRect* src_rect) { | 232 const CGRect* src_rect) { |
| 234 bool created_dc = false; | 233 bool created_dc = false; |
| 235 if (!data_->bitmap_context_) { | 234 if (!data_->bitmap_context_) { |
| 236 created_dc = true; | 235 created_dc = true; |
| 237 GetBitmapContext(); | 236 GetBitmapContext(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; | 289 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; |
| 291 for (int j = 0; j < width; j++) { | 290 for (int j = 0; j < width; j++) { |
| 292 adjustor(data + offset + j); | 291 adjustor(data + offset + j); |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 } | 294 } |
| 296 } | 295 } |
| 297 | 296 |
| 298 } // namespace skia | 297 } // namespace skia |
| 299 | 298 |
| OLD | NEW |