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 SkBitmap b; | |
64 #if defined(OS_WIN) | |
65 // Creating a platform canvas on windows results in attempting to map the | |
brettw
2011/07/01 22:26:22
Actually your new code is better on all platforms.
| |
66 // memory again (by CreateDIBSection). We want to avoid that, so we directly | |
67 // create the bitmap. | |
68 b.setConfig(SkBitmap::kARGB_8888_Config, width, height); | |
69 b.setPixels(dib->memory()); | |
70 #else | |
63 scoped_ptr<skia::PlatformCanvas> p_canvas( | 71 scoped_ptr<skia::PlatformCanvas> p_canvas( |
64 dib->GetPlatformCanvas(width, height)); | 72 dib->GetPlatformCanvas(width, height)); |
73 b = skia::GetTopDevice(*p_canvas)->accessBitmap(false); | |
74 #endif | |
65 for (size_t i = 0; i < copy_rects.size(); i++) { | 75 for (size_t i = 0; i < copy_rects.size(); i++) { |
66 const gfx::Rect& copy_rect = copy_rects[i]; | 76 const gfx::Rect& copy_rect = copy_rects[i]; |
67 int x = copy_rect.x() - bitmap_rect.x(); | 77 int x = copy_rect.x() - bitmap_rect.x(); |
68 int y = copy_rect.y() - bitmap_rect.y(); | 78 int y = copy_rect.y() - bitmap_rect.y(); |
69 int w = copy_rect.width(); | 79 int w = copy_rect.width(); |
70 int h = copy_rect.height(); | 80 int h = copy_rect.height(); |
71 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); | 81 SkIRect srcrect = SkIRect::MakeXYWH(x, y, w, h); |
72 SkRect dstrect = SkRect::MakeXYWH( | 82 SkRect dstrect = SkRect::MakeXYWH( |
73 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), | 83 SkIntToScalar(copy_rect.x()), SkIntToScalar(copy_rect.y()), |
74 SkIntToScalar(w), SkIntToScalar(h)); | 84 SkIntToScalar(w), SkIntToScalar(h)); |
75 SkBitmap b = skia::GetTopDevice(*p_canvas)->accessBitmap(false); | |
76 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect); | 85 canvas_.get()->drawBitmapRect(b, &srcrect, dstrect); |
77 } | 86 } |
78 } | 87 } |
79 | 88 |
80 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, | 89 void BackingStoreSkia::ScrollBackingStore(int dx, int dy, |
81 const gfx::Rect& clip_rect, | 90 const gfx::Rect& clip_rect, |
82 const gfx::Size& view_size) { | 91 const gfx::Size& view_size) { |
83 int x = std::min(clip_rect.x(), clip_rect.x() - dx); | 92 int x = std::min(clip_rect.x(), clip_rect.x() - dx); |
84 int y = std::min(clip_rect.y(), clip_rect.y() - dy); | 93 int y = std::min(clip_rect.y(), clip_rect.y() - dy); |
85 int w = clip_rect.width() + abs(dx); | 94 int w = clip_rect.width() + abs(dx); |
(...skipping 10 matching lines...) Expand all Loading... | |
96 return false; | 105 return false; |
97 | 106 |
98 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); | 107 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); |
99 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 108 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
100 SkBitmap b; | 109 SkBitmap b; |
101 if (!canvas_->readPixels(skrect, &b)) | 110 if (!canvas_->readPixels(skrect, &b)) |
102 return false; | 111 return false; |
103 output->writePixels(b, rect.x(), rect.y()); | 112 output->writePixels(b, rect.x(), rect.y()); |
104 return true; | 113 return true; |
105 } | 114 } |
OLD | NEW |