| 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 "chrome/browser/renderer_host/backing_store.h" | 5 #include "chrome/browser/renderer_host/backing_store.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/transport_dib.h" | 8 #include "chrome/common/transport_dib.h" |
| 9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // We assume |clip_rect| is contained within the backing store. | 59 // We assume |clip_rect| is contained within the backing store. |
| 60 DCHECK(clip_rect.bottom() <= canvas_.getDevice()->height()); | 60 DCHECK(clip_rect.bottom() <= canvas_.getDevice()->height()); |
| 61 DCHECK(clip_rect.right() <= canvas_.getDevice()->width()); | 61 DCHECK(clip_rect.right() <= canvas_.getDevice()->width()); |
| 62 | 62 |
| 63 const SkBitmap &backing_bitmap = canvas_.getDevice()->accessBitmap(true); | 63 const SkBitmap &backing_bitmap = canvas_.getDevice()->accessBitmap(true); |
| 64 const int stride = backing_bitmap.rowBytes(); | 64 const int stride = backing_bitmap.rowBytes(); |
| 65 uint8_t* x = static_cast<uint8_t*>(backing_bitmap.getPixels()); | 65 uint8_t* x = static_cast<uint8_t*>(backing_bitmap.getPixels()); |
| 66 | 66 |
| 67 if (dx) { | 67 if (dx) { |
| 68 // Horizontal scroll. According to msdn, positive values of |dx| scroll | 68 // Do not memmove any data if the scroll distance (|dx|) is greater |
| 69 // left, but in practice this seems reversed. TODO(port): figure this | 69 // than |clip_rect.width()|. If this is true, then none of the |
| 70 // previous pixels will still be on the screen after the scroll. |
| 71 // The call to PaintRect() below will redraw the entire area. |
| 72 if (abs(dx) < clip_rect.width()) { |
| 73 // Horizontal scroll. According to msdn, positive values of |dx| scroll |
| 74 // left, but in practice this seems reversed. TODO(port): figure this |
| 75 // out. For now just reverse the sign. |
| 76 dx *= -1; |
| 77 |
| 78 // This is the number of bytes to move per line at 4 bytes per pixel. |
| 79 const int len = (clip_rect.width() - abs(dx)) * 4; |
| 80 |
| 81 // Move |x| to the first pixel of the first row. |
| 82 x += clip_rect.y() * stride; |
| 83 x += clip_rect.x() * 4; |
| 84 |
| 85 // If we are scrolling left, move |x| to the |dx|^th pixel. |
| 86 if (dx < 0) { |
| 87 x -= dx * 4; |
| 88 } |
| 89 |
| 90 for (int i = clip_rect.y(); i < clip_rect.bottom(); ++i) { |
| 91 // Note that overlapping regions requires memmove, not memcpy. |
| 92 memmove(x, x + dx * 4, len); |
| 93 x += stride; |
| 94 } |
| 95 } |
| 96 } else if (dy) { |
| 97 // Vertical scroll. The above warning about not copying data if |
| 98 // |dy| > |clip_rect.height()| technically applies here too, but |
| 99 // is implicitly taken care of by the termination condition in the |
| 100 // for loop, so we do not need to explicitly check against |dy|. |
| 101 |
| 102 // TODO(port): According to msdn, positive values of |dy| scroll |
| 103 // down, but in practice this seems reversed. Figure this |
| 70 // out. For now just reverse the sign. | 104 // out. For now just reverse the sign. |
| 71 dx *= -1; | |
| 72 | |
| 73 // This is the number of bytes to move per line at 4 bytes per pixel. | |
| 74 const int len = (clip_rect.width() - abs(dx)) * 4; | |
| 75 | |
| 76 // Move |x| to the first pixel of the first row. | |
| 77 x += clip_rect.y() * stride; | |
| 78 x += clip_rect.x() * 4; | |
| 79 | |
| 80 // If we are scrolling left, move |x| to the |dx|^th pixel. | |
| 81 if (dx < 0) { | |
| 82 x -= dx * 4; | |
| 83 } | |
| 84 | |
| 85 for (int i = clip_rect.y(); i < clip_rect.bottom(); ++i) { | |
| 86 // Note that overlapping regions requires memmove, not memcpy. | |
| 87 memmove(x, x + dx * 4, len); | |
| 88 x += stride; | |
| 89 } | |
| 90 } else { | |
| 91 // Vertical scroll. According to msdn, positive values of |dy| scroll down, | |
| 92 // but in practice this seems reversed. TODO(port): figure this out. For now | |
| 93 // just reverse the sign. | |
| 94 dy *= -1; | 105 dy *= -1; |
| 95 | 106 |
| 96 const int len = clip_rect.width() * 4; | 107 const int len = clip_rect.width() * 4; |
| 97 | 108 |
| 98 // For down scrolls, we copy bottom-up (in screen coordinates). | 109 // For down scrolls, we copy bottom-up (in screen coordinates). |
| 99 // For up scrolls, we copy top-down. | 110 // For up scrolls, we copy top-down. |
| 100 if (dy > 0) { | 111 if (dy > 0) { |
| 101 // Move |x| to the first pixel of the first row of the clip rect. | 112 // Move |x| to the first pixel of the first row of the clip rect. |
| 102 x += clip_rect.y() * stride; | 113 x += clip_rect.y() * stride; |
| 103 x += clip_rect.x() * 4; | 114 x += clip_rect.x() * 4; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 115 memcpy(x, x + stride * dy, len); | 126 memcpy(x, x + stride * dy, len); |
| 116 x -= stride; | 127 x -= stride; |
| 117 } | 128 } |
| 118 } | 129 } |
| 119 } | 130 } |
| 120 | 131 |
| 121 // Now paint the new bitmap data. | 132 // Now paint the new bitmap data. |
| 122 PaintRect(process, bitmap, bitmap_rect); | 133 PaintRect(process, bitmap, bitmap_rect); |
| 123 return; | 134 return; |
| 124 } | 135 } |
| OLD | NEW |