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 // This file provides the embedder's side of random webkit glue functions. | 5 // This file provides the embedder's side of random webkit glue functions. |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 cur_capacity_ = stack_capacity; | 77 cur_capacity_ = stack_capacity; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 T stack_buffer_[stack_capacity]; | 81 T stack_buffer_[stack_capacity]; |
82 T* cur_buffer_; | 82 T* cur_buffer_; |
83 size_t cur_capacity_; | 83 size_t cur_capacity_; |
84 }; | 84 }; |
85 | 85 |
86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
87 // This definition of WriteBitmap uses shared memory to communicate across | 87 // This definition of WriteBitmapFromPixels uses shared memory to communicate |
88 // processes. | 88 // across processes. |
89 void ScopedClipboardWriterGlue::WriteBitmap(const SkBitmap& bitmap) { | 89 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels, |
90 // do not try to write a bitmap more than once | 90 const gfx::Size& size) { |
| 91 // Do not try to write a bitmap more than once |
91 if (shared_buf_) | 92 if (shared_buf_) |
92 return; | 93 return; |
93 | 94 |
94 size_t buf_size = bitmap.getSize(); | 95 size_t buf_size = 4 * size.width() * size.height(); |
95 gfx::Size size(bitmap.width(), bitmap.height()); | |
96 | 96 |
97 // Allocate a shared memory buffer to hold the bitmap bits | 97 // Allocate a shared memory buffer to hold the bitmap bits |
98 shared_buf_ = new base::SharedMemory; | 98 shared_buf_ = new base::SharedMemory; |
99 shared_buf_->Create(L"", false /* read write */, true /* open existing */, | 99 shared_buf_->Create(L"", false /* read write */, true /* open existing */, |
100 buf_size); | 100 buf_size); |
101 if (!shared_buf_ || !shared_buf_->Map(buf_size)) { | 101 if (!shared_buf_ || !shared_buf_->Map(buf_size)) { |
102 NOTREACHED(); | 102 NOTREACHED(); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 // Copy the bits into shared memory | 106 // Copy the bits into shared memory |
107 SkAutoLockPixels bitmap_lock(bitmap); | 107 memcpy(shared_buf_->memory(), pixels, buf_size); |
108 memcpy(shared_buf_->memory(), bitmap.getPixels(), buf_size); | |
109 shared_buf_->Unmap(); | 108 shared_buf_->Unmap(); |
110 | 109 |
111 Clipboard::ObjectMapParam param1, param2; | 110 Clipboard::ObjectMapParam param1, param2; |
112 base::SharedMemoryHandle smh = shared_buf_->handle(); | 111 base::SharedMemoryHandle smh = shared_buf_->handle(); |
113 | 112 |
114 const char* shared_handle = reinterpret_cast<const char*>(&smh); | 113 const char* shared_handle = reinterpret_cast<const char*>(&smh); |
115 for (size_t i = 0; i < sizeof base::SharedMemoryHandle; i++) | 114 for (size_t i = 0; i < sizeof base::SharedMemoryHandle; i++) |
116 param1.push_back(shared_handle[i]); | 115 param1.push_back(shared_handle[i]); |
117 | 116 |
118 const char* size_data = reinterpret_cast<const char*>(&size); | 117 const char* size_data = reinterpret_cast<const char*>(&size); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // Update the browser about our cache | 356 // Update the browser about our cache |
358 // NOTE: Since this can be called from the plugin process, we might not have | 357 // NOTE: Since this can be called from the plugin process, we might not have |
359 // a RenderThread. Do nothing in that case. | 358 // a RenderThread. Do nothing in that case. |
360 if (!IsPluginProcess()) | 359 if (!IsPluginProcess()) |
361 RenderThread::current()->InformHostOfCacheStatsLater(); | 360 RenderThread::current()->InformHostOfCacheStatsLater(); |
362 } | 361 } |
363 | 362 |
364 #endif // !USING_SIMPLE_RESOURCE_LOADER_BRIDGE | 363 #endif // !USING_SIMPLE_RESOURCE_LOADER_BRIDGE |
365 | 364 |
366 } // namespace webkit_glue | 365 } // namespace webkit_glue |
OLD | NEW |