OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "skia/ext/bitmap_platform_device.h" |
| 6 |
| 7 #include "skia/ext/bitmap_platform_device_data.h" |
| 8 #include "third_party/skia/include/core/SkUtils.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 // Constrains position and size to fit within available_size. If |size| is -1, |
| 13 // all the available_size is used. Returns false if the position is out of |
| 14 // available_size. |
| 15 bool Constrain(int available_size, int* position, int *size) { |
| 16 if (*size < -2) |
| 17 return false; |
| 18 |
| 19 if (*position < 0) { |
| 20 if (*size != -1) |
| 21 *size += *position; |
| 22 *position = 0; |
| 23 } |
| 24 if (*size == 0 || *position >= available_size) |
| 25 return false; |
| 26 |
| 27 if (*size > 0) { |
| 28 int overflow = (*position + *size) - available_size; |
| 29 if (overflow > 0) { |
| 30 *size -= overflow; |
| 31 } |
| 32 } else { |
| 33 // Fill up available size. |
| 34 *size = available_size - *position; |
| 35 } |
| 36 return true; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 namespace skia { |
| 42 |
| 43 void BitmapPlatformDevice::makeOpaque(int x, int y, int width, int height) { |
| 44 const SkBitmap& bitmap = accessBitmap(true); |
| 45 SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); |
| 46 |
| 47 // FIXME(brettw): This is kind of lame, we shouldn't be dealing with |
| 48 // transforms at this level. Probably there should be a PlatformCanvas |
| 49 // function that does the transform (using the actual transform not just the |
| 50 // translation) and calls us with the transformed rect. |
| 51 const SkMatrix& matrix = data_->transform(); |
| 52 int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x; |
| 53 int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y; |
| 54 |
| 55 if (Constrain(bitmap.width(), &bitmap_start_x, &width) && |
| 56 Constrain(bitmap.height(), &bitmap_start_y, &height)) { |
| 57 SkAutoLockPixels lock(bitmap); |
| 58 SkASSERT(bitmap.rowBytes() % sizeof(uint32_t) == 0u); |
| 59 size_t row_words = bitmap.rowBytes() / sizeof(uint32_t); |
| 60 // Set data to the first pixel to be modified. |
| 61 uint32_t* data = bitmap.getAddr32(0, 0) + (bitmap_start_y * row_words) + |
| 62 bitmap_start_x; |
| 63 for (int i = 0; i < height; i++) { |
| 64 for (int j = 0; j < width; j++) |
| 65 data[j] |= (0xFF << SK_A32_SHIFT); |
| 66 data += row_words; |
| 67 } |
| 68 } |
| 69 } |
| 70 |
| 71 } |
OLD | NEW |