| 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 "content/browser/renderer_host/backing_store_skia.h" | 5 #include "content/browser/renderer_host/backing_store_skia.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/render_process_host.h" | 7 #include "content/browser/renderer_host/render_process_host.h" |
| 8 #include "skia/ext/platform_canvas.h" | 8 #include "skia/ext/platform_canvas.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 for (size_t i = 0; i < copy_rects.size(); i++) { | 65 for (size_t i = 0; i < copy_rects.size(); i++) { |
| 66 const gfx::Rect& copy_rect = copy_rects[i]; | 66 const gfx::Rect& copy_rect = copy_rects[i]; |
| 67 int x = copy_rect.x() - bitmap_rect.x(); | 67 int x = copy_rect.x() - bitmap_rect.x(); |
| 68 int y = copy_rect.y() - bitmap_rect.y(); | 68 int y = copy_rect.y() - bitmap_rect.y(); |
| 69 int w = copy_rect.width(); | 69 int w = copy_rect.width(); |
| 70 int h = copy_rect.height(); | 70 int h = copy_rect.height(); |
| 71 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); | 71 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); |
| 72 SkRect dstrect = SkRect::MakeXYWH( | 72 SkRect dstrect = SkRect::MakeXYWH( |
| 73 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), | 73 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), |
| 74 SkIntToScalar(w), SkIntToScalar(h)); | 74 SkIntToScalar(w), SkIntToScalar(h)); |
| 75 SkBitmap b = p_canvas->getTopPlatformDevice().accessBitmap(false); | 75 SkBitmap b = p_canvas->getTopDevice().accessBitmap(false); |
| 76 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect); | 76 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, | 80 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, |
| 81 const gfx::Rect& clip_rect, | 81 const gfx::Rect& clip_rect, |
| 82 const gfx::Size& view_size) { | 82 const gfx::Size& view_size) { |
| 83 int x = std::min(clip_rect.x(), clip_rect.x() - dx); | 83 int x = std::min(clip_rect.x(), clip_rect.x() - dx); |
| 84 int y = std::min(clip_rect.y(), clip_rect.y() - dy); | 84 int y = std::min(clip_rect.y(), clip_rect.y() - dy); |
| 85 int w = clip_rect.width() + abs(dx); | 85 int w = clip_rect.width() + abs(dx); |
| 86 int h = clip_rect.height() + abs(dy); | 86 int h = clip_rect.height() + abs(dy); |
| 87 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); | 87 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
| 88 bitmap_.scrollRect(&rect, dx, dy); | 88 bitmap_.scrollRect(&rect, dx, dy); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, | 91 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, |
| 92 skia::PlatformCanvas* output) { | 92 skia::PlatformCanvas* output) { |
| 93 const int width = std::min(size().width(), rect.width()); | 93 const int width = std::min(size().width(), rect.width()); |
| 94 const int height = std::min(size().height(), rect.height()); | 94 const int height = std::min(size().height(), rect.height()); |
| 95 if (!output->initialize(width, height, true)) | 95 if (!output->initialize(width, height, true)) |
| 96 return false; | 96 return false; |
| 97 | 97 |
| 98 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); | 98 SkBitmap bitmap = output->getTopDevice().accessBitmap(true); |
| 99 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 99 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
| 100 SkBitmap b; | 100 SkBitmap b; |
| 101 if (!canvas_->readPixels(skrect, &b)) | 101 if (!canvas_->readPixels(skrect, &b)) |
| 102 return false; | 102 return false; |
| 103 output->writePixels(b, rect.x(), rect.y()); | 103 output->writePixels(b, rect.x(), rect.y()); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| OLD | NEW |