| 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 "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
| 9 #include "skia/include/SkBitmap.h" | 10 #include "skia/include/SkBitmap.h" |
| 10 #include "skia/include/SkCanvas.h" | 11 #include "skia/include/SkCanvas.h" |
| 11 | 12 |
| 12 BackingStore::BackingStore(const gfx::Size& size) | 13 BackingStore::BackingStore(const gfx::Size& size) |
| 13 : size_(size) { | 14 : size_(size) { |
| 14 if (!canvas_.initialize(size.width(), size.height(), true)) | 15 if (!canvas_.initialize(size.width(), size.height(), true)) |
| 15 SK_CRASH(); | 16 SK_CRASH(); |
| 16 } | 17 } |
| 17 | 18 |
| 18 BackingStore::~BackingStore() { | 19 BackingStore::~BackingStore() { |
| 19 } | 20 } |
| 20 | 21 |
| 21 bool BackingStore::PaintRect(base::ProcessHandle process, | 22 bool BackingStore::PaintRect(base::ProcessHandle process, |
| 22 BitmapWireData bitmap, | 23 TransportDIB* bitmap, |
| 23 const gfx::Rect& bitmap_rect) { | 24 const gfx::Rect& bitmap_rect) { |
| 24 if (bitmap.width() != bitmap_rect.width() || | 25 SkBitmap skbitmap; |
| 25 bitmap.height() != bitmap_rect.height() || | 26 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, bitmap_rect.width(), |
| 26 bitmap.config() != SkBitmap::kARGB_8888_Config) { | 27 bitmap_rect.height(), 4 * bitmap_rect.width()); |
| 27 return false; | |
| 28 } | |
| 29 | 28 |
| 30 canvas_.drawBitmap(bitmap, bitmap_rect.x(), bitmap_rect.y()); | 29 skbitmap.setPixels(bitmap->memory()); |
| 30 |
| 31 canvas_.drawBitmap(skbitmap, bitmap_rect.x(), bitmap_rect.y()); |
| 31 return true; | 32 return true; |
| 32 } | 33 } |
| 33 | 34 |
| 34 void BackingStore::ScrollRect(base::ProcessHandle process, | 35 void BackingStore::ScrollRect(base::ProcessHandle process, |
| 35 BitmapWireData bitmap, | 36 TransportDIB* bitmap, |
| 36 const gfx::Rect& bitmap_rect, | 37 const gfx::Rect& bitmap_rect, |
| 37 int dx, int dy, | 38 int dx, int dy, |
| 38 const gfx::Rect& clip_rect, | 39 const gfx::Rect& clip_rect, |
| 39 const gfx::Size& view_size) { | 40 const gfx::Size& view_size) { |
| 40 // WARNING: this is temporary code until a real solution is found for Mac and | 41 // WARNING: this is temporary code until a real solution is found for Mac and |
| 41 // Linux. | 42 // Linux. |
| 42 // | 43 // |
| 43 // On Windows, there's a ScrollDC call which performs horiz and vertical | 44 // On Windows, there's a ScrollDC call which performs horiz and vertical |
| 44 // scrolling | 45 // scrolling |
| 45 // | 46 // |
| 46 // clip_rect: MSDN says "The only bits that will be painted are the | 47 // clip_rect: MSDN says "The only bits that will be painted are the |
| 47 // bits that remain inside this rectangle after the scroll operation has been | 48 // bits that remain inside this rectangle after the scroll operation has been |
| 48 // completed." | 49 // completed." |
| 49 // | 50 // |
| 50 // The Windows code always sets the whole backing store as the source of the | 51 // The Windows code always sets the whole backing store as the source of the |
| 51 // scroll. Thus, we only have to worry about pixels which will end up inside | 52 // scroll. Thus, we only have to worry about pixels which will end up inside |
| 52 // the clipping rectangle. (Note that the clipping rectangle is not | 53 // the clipping rectangle. (Note that the clipping rectangle is not |
| 53 // translated by the scroll.) | 54 // translated by the scroll.) |
| 54 | 55 |
| 55 // We only support scrolling in one direction at a time. | 56 // We only support scrolling in one direction at a time. |
| 56 DCHECK(dx == 0 || dy == 0); | 57 DCHECK(dx == 0 || dy == 0); |
| 57 | 58 |
| 58 // We assume |clip_rect| is contained within the backing store. | 59 // We assume |clip_rect| is contained within the backing store. |
| 59 DCHECK(clip_rect.bottom() <= canvas_.getDevice()->height()); | 60 DCHECK(clip_rect.bottom() <= canvas_.getDevice()->height()); |
| 60 DCHECK(clip_rect.right() <= canvas_.getDevice()->width()); | 61 DCHECK(clip_rect.right() <= canvas_.getDevice()->width()); |
| 61 | 62 |
| 62 if (bitmap.width() != bitmap_rect.width() || | |
| 63 bitmap.height() != bitmap_rect.height() || | |
| 64 bitmap.config() != SkBitmap::kARGB_8888_Config) { | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 const SkBitmap &backing_bitmap = canvas_.getDevice()->accessBitmap(true); | 63 const SkBitmap &backing_bitmap = canvas_.getDevice()->accessBitmap(true); |
| 69 const int stride = backing_bitmap.rowBytes(); | 64 const int stride = backing_bitmap.rowBytes(); |
| 70 uint8_t* x = static_cast<uint8_t*>(backing_bitmap.getPixels()); | 65 uint8_t* x = static_cast<uint8_t*>(backing_bitmap.getPixels()); |
| 71 | 66 |
| 72 if (dx) { | 67 if (dx) { |
| 73 // Horizontal scroll. According to msdn, positive values of |dx| scroll | 68 // Horizontal scroll. According to msdn, positive values of |dx| scroll |
| 74 // left, but in practice this seems reversed. TODO(port): figure this | 69 // left, but in practice this seems reversed. TODO(port): figure this |
| 75 // out. For now just reverse the sign. | 70 // out. For now just reverse the sign. |
| 76 dx *= -1; | 71 dx *= -1; |
| 77 | 72 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 x += (clip_rect.bottom() - 1) * stride; | 111 x += (clip_rect.bottom() - 1) * stride; |
| 117 | 112 |
| 118 for (int i = clip_rect.y(); i < clip_rect.height() + dy; ++i) { | 113 for (int i = clip_rect.y(); i < clip_rect.height() + dy; ++i) { |
| 119 memcpy(x, x + stride * dy, len); | 114 memcpy(x, x + stride * dy, len); |
| 120 x -= stride; | 115 x -= stride; |
| 121 } | 116 } |
| 122 } | 117 } |
| 123 } | 118 } |
| 124 | 119 |
| 125 // Now paint the new bitmap data. | 120 // Now paint the new bitmap data. |
| 126 canvas_.drawBitmap(bitmap, bitmap_rect.x(), bitmap_rect.y()); | 121 PaintRect(process, bitmap, bitmap_rect); |
| 127 return; | 122 return; |
| 128 } | 123 } |
| OLD | NEW |