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 "webkit/plugins/ppapi/ppb_image_data_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/ppb_image_data.h" | 15 #include "ppapi/c/ppb_image_data.h" |
16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
17 #include "ppapi/thunk/thunk.h" | 17 #include "ppapi/thunk/thunk.h" |
18 #include "third_party/skia/include/core/SkColorPriv.h" | 18 #include "third_party/skia/include/core/SkColorPriv.h" |
19 #include "webkit/plugins/ppapi/common.h" | 19 #include "webkit/plugins/ppapi/common.h" |
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
21 | 21 |
| 22 using ::ppapi::thunk::PPB_ImageData_API; |
| 23 |
22 namespace webkit { | 24 namespace webkit { |
23 namespace ppapi { | 25 namespace ppapi { |
24 | 26 |
25 namespace { | |
26 | |
27 int32_t GetSharedMemory(PP_Resource resource, | |
28 int* handle, | |
29 uint32_t* byte_count) { | |
30 scoped_refptr<PPB_ImageData_Impl> image_data( | |
31 Resource::GetAs<PPB_ImageData_Impl>(resource)); | |
32 if (image_data) { | |
33 *handle = image_data->GetSharedMemoryHandle(byte_count); | |
34 return PP_OK; | |
35 } | |
36 return PP_ERROR_BADRESOURCE; | |
37 } | |
38 | |
39 const PPB_ImageDataTrusted ppb_imagedata_trusted = { | |
40 &GetSharedMemory, | |
41 }; | |
42 | |
43 } // namespace | |
44 | |
45 PPB_ImageData_Impl::PPB_ImageData_Impl(PluginInstance* instance) | 27 PPB_ImageData_Impl::PPB_ImageData_Impl(PluginInstance* instance) |
46 : Resource(instance), | 28 : Resource(instance), |
47 format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), | 29 format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), |
48 width_(0), | 30 width_(0), |
49 height_(0) { | 31 height_(0) { |
50 } | 32 } |
51 | 33 |
52 PPB_ImageData_Impl::~PPB_ImageData_Impl() { | 34 PPB_ImageData_Impl::~PPB_ImageData_Impl() { |
53 } | 35 } |
54 | 36 |
55 // static | 37 PPB_ImageData_API* PPB_ImageData_Impl::AsPPB_ImageData_API() { |
56 const PPB_ImageData* PPB_ImageData_Impl::GetInterface() { | |
57 return ::ppapi::thunk::GetPPB_ImageData_Thunk(); | |
58 } | |
59 | |
60 // static | |
61 const PPB_ImageDataTrusted* PPB_ImageData_Impl::GetTrustedInterface() { | |
62 return &ppb_imagedata_trusted; | |
63 } | |
64 | |
65 ::ppapi::thunk::PPB_ImageData_API* PPB_ImageData_Impl::AsPPB_ImageData_API() { | |
66 return this; | 38 return this; |
67 } | 39 } |
68 | 40 |
69 PPB_ImageData_Impl* PPB_ImageData_Impl::AsPPB_ImageData_Impl() { | 41 PPB_ImageData_Impl* PPB_ImageData_Impl::AsPPB_ImageData_Impl() { |
70 return this; | 42 return this; |
71 } | 43 } |
72 | 44 |
73 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, | 45 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, |
74 int width, int height, | 46 int width, int height, |
75 bool init_to_zero) { | 47 bool init_to_zero) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return bitmap.getAddr32(0, 0); | 87 return bitmap.getAddr32(0, 0); |
116 } | 88 } |
117 | 89 |
118 void PPB_ImageData_Impl::Unmap() { | 90 void PPB_ImageData_Impl::Unmap() { |
119 // This is currently unimplemented, which is OK. The data will just always | 91 // This is currently unimplemented, which is OK. The data will just always |
120 // be around once it's mapped. Chrome's TransportDIB isn't currently | 92 // be around once it's mapped. Chrome's TransportDIB isn't currently |
121 // unmappable without freeing it, but this may be something we want to support | 93 // unmappable without freeing it, but this may be something we want to support |
122 // in the future to save some memory. | 94 // in the future to save some memory. |
123 } | 95 } |
124 | 96 |
125 int PPB_ImageData_Impl::GetSharedMemoryHandle(uint32* byte_count) const { | 97 int32_t PPB_ImageData_Impl::GetSharedMemory(int* handle, |
126 return platform_image_->GetSharedMemoryHandle(byte_count); | 98 uint32_t* byte_count) { |
| 99 *handle = platform_image_->GetSharedMemoryHandle(byte_count); |
| 100 return PP_OK; |
127 } | 101 } |
128 | 102 |
129 const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const { | 103 const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const { |
130 if (!mapped_canvas_.get()) | 104 if (!mapped_canvas_.get()) |
131 return NULL; | 105 return NULL; |
132 return &skia::GetTopDevice(*mapped_canvas_)->accessBitmap(false); | 106 return &skia::GetTopDevice(*mapped_canvas_)->accessBitmap(false); |
133 } | 107 } |
134 | 108 |
135 void PPB_ImageData_Impl::Swap(PPB_ImageData_Impl* other) { | 109 void PPB_ImageData_Impl::Swap(PPB_ImageData_Impl* other) { |
136 swap(other->platform_image_, platform_image_); | 110 swap(other->platform_image_, platform_image_); |
137 swap(other->mapped_canvas_, mapped_canvas_); | 111 swap(other->mapped_canvas_, mapped_canvas_); |
138 std::swap(other->format_, format_); | 112 std::swap(other->format_, format_); |
139 std::swap(other->width_, width_); | 113 std::swap(other->width_, width_); |
140 std::swap(other->height_, height_); | 114 std::swap(other->height_, height_); |
141 } | 115 } |
142 | 116 |
143 } // namespace ppapi | 117 } // namespace ppapi |
144 } // namespace webkit | 118 } // namespace webkit |
145 | 119 |
OLD | NEW |