summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-14 17:08:00 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-14 17:08:00 +0000
commitfb35dcfafd929772b185516173a92c619aa97421 (patch)
treecc7260344ab7f028274c312d646685adcebd95b5 /ppapi
parentda441db001417a34e7378a95481d237a637488a7 (diff)
downloadchromium_src-fb35dcfafd929772b185516173a92c619aa97421.zip
chromium_src-fb35dcfafd929772b185516173a92c619aa97421.tar.gz
chromium_src-fb35dcfafd929772b185516173a92c619aa97421.tar.bz2
Implement DrawGlyphs and refactor the FontDescription serialization such
that it can be reused for this code. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi.gyp2
-rw-r--r--ppapi/proxy/ppapi_messages.h52
-rw-r--r--ppapi/proxy/ppb_flash_proxy.cc42
-rw-r--r--ppapi/proxy/ppb_font_proxy.cc95
-rw-r--r--ppapi/proxy/ppb_pdf_proxy.cc13
-rw-r--r--ppapi/proxy/serialized_structs.cc53
-rw-r--r--ppapi/proxy/serialized_structs.h98
7 files changed, 223 insertions, 132 deletions
diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp
index 5d6f78e..bf8d032 100644
--- a/ppapi/ppapi.gyp
+++ b/ppapi/ppapi.gyp
@@ -554,6 +554,8 @@
'proxy/ppp_class_proxy.h',
'proxy/ppp_instance_proxy.cc',
'proxy/ppp_instance_proxy.h',
+ 'proxy/serialized_structs.cc',
+ 'proxy/serialized_structs.h',
'proxy/serialized_var.cc',
'proxy/serialized_var.h',
'proxy/var_serialization_rules.h',
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 5b5caf2..d0f5bed 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -17,57 +17,7 @@
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/ppapi_param_traits.h"
-
-namespace pp {
-namespace proxy {
-
-// PP_FontDescript_Dev has to be redefined with a SerializedVar in place of
-// the PP_Var used for the face name.
-struct SerializedFontDescription {
- pp::proxy::SerializedVar face;
- int32_t family;
- uint32_t size;
- int32_t weight;
- PP_Bool italic;
- PP_Bool small_caps;
- int32_t letter_spacing;
- int32_t word_spacing;
-};
-
-struct SerializedDirEntry {
- std::string name;
- bool is_dir;
-};
-
-// Since there are so many parameters, DrawTextAt requires this separate
-// structure. This includes everything but the font name. Because the font name
-// is a var, it's much more convenient to use the normal way of passing a
-// PP_Var.
-struct PPBFont_DrawTextAt_Params {
- PP_Resource font;
- PP_Resource image_data;
- PP_Bool text_is_rtl;
- PP_Bool override_direction;
- PP_Point position;
- uint32_t color;
- PP_Rect clip;
- bool clip_is_null;
- PP_Bool image_data_is_opaque;
-};
-
-struct PPBFlash_DrawGlyphs_Params {
- PP_Resource pp_image_data;
- SerializedFontDescription font_desc;
- uint32_t color;
- PP_Point position;
- PP_Rect clip;
- float transformation[3][3];
- std::vector<uint16_t> glyph_indices;
- std::vector<PP_Point> glyph_advances;
-};
-
-} // namespace proxy
-} // namespace pp
+#include "ppapi/proxy/serialized_structs.h"
#define MESSAGES_INTERNAL_FILE "ppapi/proxy/ppapi_messages_internal.h"
#include "ipc/ipc_message_macros.h"
diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc
index 2a6e237..1f9b297 100644
--- a/ppapi/proxy/ppb_flash_proxy.cc
+++ b/ppapi/proxy/ppb_flash_proxy.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "build/build_config.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
+#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_resource.h"
@@ -62,13 +63,35 @@ bool DrawGlyphs(PP_Resource pp_image_data,
uint32_t glyph_count,
uint16_t glyph_indices[],
PP_Point glyph_advances[]) {
- return false; // TODO(brettw): implement this.
+ Dispatcher* dispatcher = PluginDispatcher::Get();
+
+ PPBFlash_DrawGlyphs_Params params;
+ params.pp_image_data = pp_image_data;
+ params.font_desc.SetFromPPFontDescription(dispatcher, *font_desc, true);
+ params.color = color;
+ params.position = position;
+ params.clip = clip;
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++)
+ params.transformation[i][j] = transformation[i][j];
+ }
+
+ params.glyph_indices.insert(params.glyph_indices.begin(),
+ &glyph_indices[0],
+ &glyph_indices[glyph_count]);
+ params.glyph_advances.insert(params.glyph_advances.begin(),
+ &glyph_advances[0],
+ &glyph_advances[glyph_count]);
+
+ dispatcher->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs(
+ INTERFACE_ID_PPB_FLASH, params));
+ return true;
}
PP_Var GetProxyForURL(PP_Module pp_module, const char* url) {
ReceiveSerializedVarReturnValue result;
PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL(
- INTERFACE_ID_PPB_FLASH, pp_module, url, &result));
+ INTERFACE_ID_PPB_FLASH, pp_module, url, &result));
return result.Return(PluginDispatcher::Get());
}
@@ -214,7 +237,20 @@ void PPB_Flash_Proxy::OnMsgSetInstanceAlwaysOnTop(
void PPB_Flash_Proxy::OnMsgDrawGlyphs(
const pp::proxy::PPBFlash_DrawGlyphs_Params& params) {
- // TODO(brettw) implement this.
+ PP_FontDescription_Dev font_desc;
+ params.font_desc.SetToPPFontDescription(dispatcher(), &font_desc, false);
+
+ if (params.glyph_indices.size() != params.glyph_advances.size() ||
+ params.glyph_indices.empty())
+ return;
+
+ ppb_flash_target()->DrawGlyphs(
+ params.pp_image_data, &font_desc, params.color,
+ params.position, params.clip,
+ const_cast<float(*)[3]>(params.transformation),
+ static_cast<uint32_t>(params.glyph_indices.size()),
+ const_cast<uint16_t*>(&params.glyph_indices[0]),
+ const_cast<PP_Point*>(&params.glyph_advances[0]));
}
void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Module module,
diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc
index 4f10956..9a4dbf5 100644
--- a/ppapi/proxy/ppb_font_proxy.cc
+++ b/ppapi/proxy/ppb_font_proxy.cc
@@ -21,6 +21,7 @@ class Font : public PluginResource {
virtual Font* AsFont() { return this; }
PP_FontDescription_Dev& desc() { return desc_; }
+ PP_FontDescription_Dev* desc_ptr() { return &desc_; }
PP_FontMetrics_Dev& metrics() { return metrics_; }
private:
@@ -46,16 +47,8 @@ PP_Resource Create(PP_Module module_id,
const PP_FontDescription_Dev* description) {
PluginDispatcher* dispatcher = PluginDispatcher::Get();
- // Convert the input font description to a SerializedFontDescription.
SerializedFontDescription in_description;
- in_description.face = SerializedVarSendInput(dispatcher, description->face);
- in_description.family = description->family;
- in_description.size = description->size;
- in_description.weight = description->weight;
- in_description.italic = description->italic;
- in_description.small_caps = description->small_caps;
- in_description.letter_spacing = description->letter_spacing;
- in_description.word_spacing = description->word_spacing;
+ in_description.SetFromPPFontDescription(dispatcher, *description, true);
PP_Resource result;
SerializedFontDescription out_description;
@@ -68,31 +61,14 @@ PP_Resource Create(PP_Module module_id,
return 0; // Failure creating font.
linked_ptr<Font> object(new Font);
-
- // Jump through some hoops to get a PP_Var with a single ref to it in our
- // resource object.
- ReceiveSerializedVarReturnValue face_return_value;
- *static_cast<SerializedVar*>(&face_return_value) = out_description.face;
- object->desc().face = face_return_value.Return(dispatcher);
-
- // Convert the rest of the font description.
- object->desc().family =
- static_cast<PP_FontFamily_Dev>(out_description.family);
- object->desc().size = out_description.size;
- object->desc().weight =
- static_cast<PP_FontWeight_Dev>(out_description.weight);
- object->desc().italic = out_description.italic;
- object->desc().small_caps = out_description.small_caps;
- object->desc().letter_spacing = out_description.letter_spacing;
- object->desc().word_spacing = out_description.word_spacing;
+ out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true);
// Convert the metrics, this is just serialized as a string of bytes.
if (out_metrics.size() != sizeof(PP_FontMetrics_Dev))
return 0;
memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ dispatcher->plugin_resource_tracker()->AddResource(result, object);
return result;
}
@@ -233,51 +209,28 @@ void PPB_Font_Proxy::OnMsgCreate(
SerializedFontDescription* out_description,
std::string* out_metrics) {
// Convert the face name in the input description.
- PP_FontDescription_Dev in_desc;
- SerializedVarReceiveInput in_face_name(in_description.face);
- in_desc.face = in_face_name.Get(dispatcher());
-
- // The rest of the font description is easy.
- in_desc.family = static_cast<PP_FontFamily_Dev>(in_description.family);
- in_desc.size = in_description.size;
- in_desc.weight = static_cast<PP_FontWeight_Dev>(in_description.weight);
- in_desc.italic = in_description.italic;
- in_desc.small_caps = in_description.small_caps;
- in_desc.letter_spacing = in_description.letter_spacing;
- in_desc.word_spacing = in_description.word_spacing;
-
- PP_FontDescription_Dev out_desc;
- SerializedVarOutParam out_face_name(&out_description->face);
-
- *result = ppb_font_target()->Create(pp_module, &in_desc);
- if (!*result) {
- // Even in the failure case we need to set the var for the name or it
- // will have no dispatcher set, and the serialization layer will assert
- // when we're sending it to the browser.
- *out_face_name.OutParam(dispatcher()) = PP_MakeUndefined();
- return;
+ PP_FontDescription_Dev in_pp_desc;
+ in_description.SetToPPFontDescription(dispatcher(), &in_pp_desc, false);
+
+ // Make sure the output is always defined so we can still serialize it back
+ // to the plugin below.
+ PP_FontDescription_Dev out_pp_desc;
+ memset(&out_pp_desc, 0, sizeof(PP_FontDescription_Dev));
+ out_pp_desc.face = PP_MakeUndefined();
+
+ *result = ppb_font_target()->Create(pp_module, &in_pp_desc);
+ if (*result) {
+ // Get the metrics and resulting description to return to the browser.
+ PP_FontMetrics_Dev metrics;
+ if (ppb_font_target()->Describe(*result, &out_pp_desc, &metrics)) {
+ out_metrics->assign(reinterpret_cast<const char*>(&metrics),
+ sizeof(PP_FontMetrics_Dev));
+ }
}
- // Get the metrics and resulting description to return to the browser.
- PP_FontMetrics_Dev metrics;
- ppb_font_target()->Describe(*result, &out_desc, &metrics);
-
- // Convert the PP_Var in the resulting description to an out param. This
- // should clean up the ref |Describe| assigned to our font name.
- *out_face_name.OutParam(dispatcher()) = out_desc.face;
-
- // The rest of the font description is easy.
- out_description->family = out_desc.family;
- out_description->size = out_desc.size;
- out_description->weight = out_desc.weight;
- out_description->italic = out_desc.italic;
- out_description->small_caps = out_desc.small_caps;
- out_description->letter_spacing = out_desc.letter_spacing;
- out_description->word_spacing = out_desc.word_spacing;
-
- // Metrics are just serialized as a string.
- out_metrics->assign(reinterpret_cast<const char*>(&metrics),
- sizeof(PP_FontMetrics_Dev));
+ // This must always get called or it will assert when trying to serialize
+ // the un-filled-in SerializedFontDescription as the return value.
+ out_description->SetFromPPFontDescription(dispatcher(), out_pp_desc, false);
}
void PPB_Font_Proxy::OnMsgDrawTextAt(SerializedVarReceiveInput text,
diff --git a/ppapi/proxy/ppb_pdf_proxy.cc b/ppapi/proxy/ppb_pdf_proxy.cc
index c706804..580c6b0 100644
--- a/ppapi/proxy/ppb_pdf_proxy.cc
+++ b/ppapi/proxy/ppb_pdf_proxy.cc
@@ -60,19 +60,18 @@ PP_Resource GetFontFileWithFallback(
PP_Module module_id,
const PP_FontDescription_Dev* description,
PP_PrivateFontCharset charset) {
+ PluginDispatcher* dispatcher = PluginDispatcher::Get();
SerializedFontDescription desc;
- // TODO(brettw): serialize the description!
+ desc.SetFromPPFontDescription(dispatcher, *description, true);
PP_Resource result = 0;
- PluginDispatcher::Get()->Send(
- new PpapiHostMsg_PPBPdf_GetFontFileWithFallback(
- INTERFACE_ID_PPB_PDF, module_id, desc, charset, &result));
+ dispatcher->Send(new PpapiHostMsg_PPBPdf_GetFontFileWithFallback(
+ INTERFACE_ID_PPB_PDF, module_id, desc, charset, &result));
if (!result)
return 0;
linked_ptr<PrivateFontFile> object(new PrivateFontFile);
- PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
- result, object);
+ dispatcher->plugin_resource_tracker()->AddResource(result, object);
return result;
}
@@ -142,7 +141,7 @@ void PPB_Pdf_Proxy::OnMsgGetFontFileWithFallback(
int32_t charset,
PP_Resource* result) {
PP_FontDescription_Dev desc;
- // TODO(brettw) deserialize this value!
+ in_desc.SetToPPFontDescription(dispatcher(), &desc, false);
*result = ppb_pdf_target()->GetFontFileWithFallback(module, &desc,
static_cast<PP_PrivateFontCharset>(charset));
}
diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc
new file mode 100644
index 0000000..fa71f71
--- /dev/null
+++ b/ppapi/proxy/serialized_structs.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/serialized_structs.h"
+
+#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/c/pp_rect.h"
+
+namespace pp {
+namespace proxy {
+
+void SerializedFontDescription::SetFromPPFontDescription(
+ Dispatcher* dispatcher,
+ const PP_FontDescription_Dev& desc,
+ bool source_owns_ref) {
+ if (source_owns_ref)
+ face = SerializedVarSendInput(dispatcher, desc.face);
+ else
+ SerializedVarReturnValue(&face).Return(dispatcher, desc.face);
+
+ family = desc.family;
+ size = desc.size;
+ weight = desc.weight;
+ italic = desc.italic;
+ small_caps = desc.small_caps;
+ letter_spacing = desc.letter_spacing;
+ word_spacing = desc.word_spacing;
+}
+
+void SerializedFontDescription::SetToPPFontDescription(
+ Dispatcher* dispatcher,
+ PP_FontDescription_Dev* desc,
+ bool dest_owns_ref) const {
+ if (dest_owns_ref) {
+ ReceiveSerializedVarReturnValue face_return_value;
+ *static_cast<SerializedVar*>(&face_return_value) = face;
+ desc->face = face_return_value.Return(dispatcher);
+ } else {
+ desc->face = SerializedVarReceiveInput(face).Get(dispatcher);
+ }
+
+ desc->family = static_cast<PP_FontFamily_Dev>(family);
+ desc->size = size;
+ desc->weight = static_cast<PP_FontWeight_Dev>(weight);
+ desc->italic = italic;
+ desc->small_caps = small_caps;
+ desc->letter_spacing = letter_spacing;
+ desc->word_spacing = word_spacing;
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h
new file mode 100644
index 0000000..49fc222
--- /dev/null
+++ b/ppapi/proxy/serialized_structs.h
@@ -0,0 +1,98 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_SERIALIZED_STRUCTS_H_
+#define PPAPI_PROXY_SERIALIZED_STRUCTS_H_
+
+#include <string>
+#include <vector>
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_rect.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/serialized_var.h"
+
+struct PP_FontDescription_Dev;
+
+namespace pp {
+namespace proxy {
+
+class Dispatcher;
+
+// PP_FontDescript_Dev has to be redefined with a SerializedVar in place of
+// the PP_Var used for the face name.
+struct SerializedFontDescription {
+ // Converts a PP_FontDescription_Dev to a SerializedFontDescription.
+ //
+ // If source_owns_ref is true, the reference owned by the
+ // PP_FontDescription_Dev will be unchanged and the caller is responsible for
+ // freeing it. When false, the SerializedFontDescription will take ownership
+ // of the ref. This is the difference between serializing as an input value
+ // (owns_ref = true) and an output value (owns_ref = true).
+ void SetFromPPFontDescription(Dispatcher* dispatcher,
+ const PP_FontDescription_Dev& desc,
+ bool source_owns_ref);
+
+ // Converts to a PP_FontDescription_Dev. The face name will have one ref
+ // assigned to it on behalf of the caller.
+ //
+ // If dest_owns_ref is set, the resulting PP_FontDescription_Dev will keep a
+ // reference to any strings we made on its behalf even when the
+ // SerializedFontDescription goes away. When false, ownership of the ref will
+ // stay with the SerializedFontDescription and the PP_FontDescription_Dev
+ // will just refer to that one. This is the difference between deserializing
+ // as an input value (owns_ref = false) and an output value (owns_ref = true).
+ void SetToPPFontDescription(Dispatcher* dispatcher,
+ PP_FontDescription_Dev* desc,
+ bool dest_owns_ref) const;
+
+ pp::proxy::SerializedVar face;
+ int32_t family;
+ uint32_t size;
+ int32_t weight;
+ PP_Bool italic;
+ PP_Bool small_caps;
+ int32_t letter_spacing;
+ int32_t word_spacing;
+};
+
+struct SerializedDirEntry {
+ std::string name;
+ bool is_dir;
+};
+
+// Since there are so many parameters, DrawTextAt requires this separate
+// structure. This includes everything but the font name. Because the font name
+// is a var, it's much more convenient to use the normal way of passing a
+// PP_Var.
+struct PPBFont_DrawTextAt_Params {
+ PP_Resource font;
+ PP_Resource image_data;
+ PP_Bool text_is_rtl;
+ PP_Bool override_direction;
+ PP_Point position;
+ uint32_t color;
+ PP_Rect clip;
+ bool clip_is_null;
+ PP_Bool image_data_is_opaque;
+};
+
+struct PPBFlash_DrawGlyphs_Params {
+ PP_Resource pp_image_data;
+ SerializedFontDescription font_desc;
+ uint32_t color;
+ PP_Point position;
+ PP_Rect clip;
+ float transformation[3][3];
+ std::vector<uint16_t> glyph_indices;
+ std::vector<PP_Point> glyph_advances;
+};
+
+} // namespace proxy
+} // namespace pp
+
+
+
+#endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_