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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 const int height = bitmap_rect.height(); | 53 const int height = bitmap_rect.height(); |
54 | 54 |
55 if (width <= 0 || width > kMaxVideoLayerSize || | 55 if (width <= 0 || width > kMaxVideoLayerSize || |
56 height <= 0 || height > kMaxVideoLayerSize) | 56 height <= 0 || height > kMaxVideoLayerSize) |
57 return; | 57 return; |
58 | 58 |
59 TransportDIB* dib = process->GetTransportDIB(bitmap); | 59 TransportDIB* dib = process->GetTransportDIB(bitmap); |
60 if (!dib) | 60 if (!dib) |
61 return; | 61 return; |
62 | 62 |
| 63 SkPaint copy_paint; |
| 64 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 65 |
63 SkBitmap sk_bitmap; | 66 SkBitmap sk_bitmap; |
64 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 67 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
65 sk_bitmap.setPixels(dib->memory()); | 68 sk_bitmap.setPixels(dib->memory()); |
66 for (size_t i = 0; i < copy_rects.size(); i++) { | 69 for (size_t i = 0; i < copy_rects.size(); i++) { |
67 const gfx::Rect& copy_rect = copy_rects[i]; | 70 const gfx::Rect& copy_rect = copy_rects[i]; |
68 int x = copy_rect.x() - bitmap_rect.x(); | 71 int x = copy_rect.x() - bitmap_rect.x(); |
69 int y = copy_rect.y() - bitmap_rect.y(); | 72 int y = copy_rect.y() - bitmap_rect.y(); |
70 int w = copy_rect.width(); | 73 int w = copy_rect.width(); |
71 int h = copy_rect.height(); | 74 int h = copy_rect.height(); |
72 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); | 75 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); |
73 SkRect dstrect = SkRect::MakeXYWH( | 76 SkRect dstrect = SkRect::MakeXYWH( |
74 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), | 77 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), |
75 SkIntToScalar(w), SkIntToScalar(h)); | 78 SkIntToScalar(w), SkIntToScalar(h)); |
76 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect); | 79 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
80 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, | 83 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, |
81 const gfx::Rect& clip_rect, | 84 const gfx::Rect& clip_rect, |
82 const gfx::Size& view_size) { | 85 const gfx::Size& view_size) { |
83 int x = std::min(clip_rect.x(), clip_rect.x() - dx); | 86 int x = std::min(clip_rect.x(), clip_rect.x() - dx); |
84 int y = std::min(clip_rect.y(), clip_rect.y() - dy); | 87 int y = std::min(clip_rect.y(), clip_rect.y() - dy); |
85 int w = clip_rect.width() + abs(dx); | 88 int w = clip_rect.width() + abs(dx); |
86 int h = clip_rect.height() + abs(dy); | 89 int h = clip_rect.height() + abs(dy); |
87 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); | 90 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
88 bitmap_.scrollRect(&rect, dx, dy); | 91 bitmap_.scrollRect(&rect, dx, dy); |
89 } | 92 } |
90 | 93 |
91 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, | 94 bool BackingStoreSkia::CopyFromBackingStore(const gfx::Rect& rect, |
92 skia::PlatformCanvas* output) { | 95 skia::PlatformCanvas* output) { |
93 const int width = std::min(size().width(), rect.width()); | 96 const int width = std::min(size().width(), rect.width()); |
94 const int height = std::min(size().height(), rect.height()); | 97 const int height = std::min(size().height(), rect.height()); |
95 if (!output->initialize(width, height, true)) | 98 if (!output->initialize(width, height, true)) |
96 return false; | 99 return false; |
97 | 100 |
98 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); | 101 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); |
99 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 102 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
100 SkBitmap b; | 103 SkBitmap b; |
101 if (!canvas_->readPixels(skrect, &b)) | 104 if (!canvas_->readPixels(skrect, &b)) |
102 return false; | 105 return false; |
103 output->writePixels(b, rect.x(), rect.y()); | 106 output->writePixels(b, rect.x(), rect.y()); |
104 return true; | 107 return true; |
105 } | 108 } |
OLD | NEW |