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_font_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_font_impl.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_font_dev.h" | 7 #include "ppapi/c/dev/ppb_font_dev.h" |
8 #include "ppapi/shared_impl/ppapi_preferences.h" | 8 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 9 #include "ppapi/thunk/enter.h" |
9 #include "ppapi/thunk/thunk.h" | 10 #include "ppapi/thunk/thunk.h" |
10 #include "webkit/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
11 #include "webkit/plugins/ppapi/plugin_module.h" | 12 #include "webkit/plugins/ppapi/plugin_module.h" |
12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
13 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 14 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
14 #include "webkit/plugins/ppapi/string.h" | 15 #include "webkit/plugins/ppapi/string.h" |
15 #include "webkit/plugins/ppapi/var.h" | 16 #include "webkit/plugins/ppapi/var.h" |
16 | 17 |
17 using ::ppapi::WebKitForwarding; | 18 using ppapi::thunk::EnterResource; |
| 19 using ppapi::thunk::PPB_ImageData_API; |
| 20 using ppapi::WebKitForwarding; |
18 | 21 |
19 namespace webkit { | 22 namespace webkit { |
20 namespace ppapi { | 23 namespace ppapi { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 // Converts the given PP_TextRun to a TextRun, returning true on success. | 27 // Converts the given PP_TextRun to a TextRun, returning true on success. |
25 // False means the input was invalid. | 28 // False means the input was invalid. |
26 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 29 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
27 WebKitForwarding::Font::TextRun* output) { | 30 WebKitForwarding::Font::TextRun* output) { |
(...skipping 21 matching lines...) Expand all Loading... |
49 font_forwarding_.reset(result); | 52 font_forwarding_.reset(result); |
50 } | 53 } |
51 | 54 |
52 PPB_Font_Impl::~PPB_Font_Impl() { | 55 PPB_Font_Impl::~PPB_Font_Impl() { |
53 } | 56 } |
54 | 57 |
55 ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { | 58 ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { |
56 return this; | 59 return this; |
57 } | 60 } |
58 | 61 |
59 PPB_Font_Impl* PPB_Font_Impl::AsPPB_Font_Impl() { | |
60 return this; | |
61 } | |
62 | |
63 PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, | 62 PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, |
64 PP_FontMetrics_Dev* metrics) { | 63 PP_FontMetrics_Dev* metrics) { |
65 std::string face; | 64 std::string face; |
66 PP_Bool result = PP_FALSE; | 65 PP_Bool result = PP_FALSE; |
67 font_forwarding_->Describe(NULL, description, &face, metrics, &result); | 66 font_forwarding_->Describe(NULL, description, &face, metrics, &result); |
68 if (!result) | 67 if (!result) |
69 return PP_FALSE; | 68 return PP_FALSE; |
70 | 69 |
71 // Convert the string. | 70 // Convert the string. |
72 description->face = StringVar::StringToPPVar(instance()->module(), face); | 71 description->face = StringVar::StringToPPVar(instance()->module(), face); |
73 return PP_TRUE; | 72 return PP_TRUE; |
74 } | 73 } |
75 | 74 |
76 PP_Bool PPB_Font_Impl::DrawTextAt(PP_Resource image_data, | 75 PP_Bool PPB_Font_Impl::DrawTextAt(PP_Resource image_data, |
77 const PP_TextRun_Dev* text, | 76 const PP_TextRun_Dev* text, |
78 const PP_Point* position, | 77 const PP_Point* position, |
79 uint32_t color, | 78 uint32_t color, |
80 const PP_Rect* clip, | 79 const PP_Rect* clip, |
81 PP_Bool image_data_is_opaque) { | 80 PP_Bool image_data_is_opaque) { |
82 // Get and map the image data we're painting to. | 81 // Get and map the image data we're painting to. |
83 scoped_refptr<PPB_ImageData_Impl> image_resource( | 82 EnterResource<PPB_ImageData_API> enter(image_data, true); |
84 Resource::GetAs<PPB_ImageData_Impl>(image_data)); | 83 if (enter.failed()) |
85 if (!image_resource.get()) | |
86 return PP_FALSE; | 84 return PP_FALSE; |
| 85 PPB_ImageData_Impl* image_resource = |
| 86 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 87 |
87 ImageDataAutoMapper mapper(image_resource); | 88 ImageDataAutoMapper mapper(image_resource); |
88 if (!mapper.is_valid()) | 89 if (!mapper.is_valid()) |
89 return PP_FALSE; | 90 return PP_FALSE; |
90 | 91 |
91 WebKitForwarding::Font::TextRun run; | 92 WebKitForwarding::Font::TextRun run; |
92 if (!PPTextRunToTextRun(text, &run)) | 93 if (!PPTextRunToTextRun(text, &run)) |
93 return PP_FALSE; | 94 return PP_FALSE; |
94 | 95 |
95 font_forwarding_->DrawTextAt(NULL, WebKitForwarding::Font::DrawTextParams( | 96 font_forwarding_->DrawTextAt(NULL, WebKitForwarding::Font::DrawTextParams( |
96 image_resource->mapped_canvas(), run, position, | 97 image_resource->mapped_canvas(), run, position, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return this; | 140 return this; |
140 } | 141 } |
141 | 142 |
142 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { | 143 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { |
143 return PP_MakeUndefined(); | 144 return PP_MakeUndefined(); |
144 } | 145 } |
145 | 146 |
146 } // namespace ppapi | 147 } // namespace ppapi |
147 } // namespace webkit | 148 } // namespace webkit |
148 | 149 |
OLD | NEW |