diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:17:48 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-10 21:17:48 +0000 |
commit | 7a1f7c6f6c982287b3f6bb2acded619f3824416c (patch) | |
tree | 82ff404c4bcf84520c21ea7f0526ad5a40661641 /ppapi/shared_impl | |
parent | bafaee12825a06890f114a282880e135a8b0b1ae (diff) | |
download | chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.zip chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.tar.gz chromium_src-7a1f7c6f6c982287b3f6bb2acded619f3824416c.tar.bz2 |
Make the Pepper proxy support in-process font rendering.
This implements a WebKit thread in the PPAPI plugin process so we can do the
font calls without IPC. The existing font support was refactored into
a virtual class (to prevent PPAPI from depending on WebKit and creating a
circular GYP dependency).
This moves the renderer sandbox support into content/common so that it can
be used by the PPAPI process.
Review URL: http://codereview.chromium.org/6981001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/DEPS | 6 | ||||
-rw-r--r-- | ppapi/shared_impl/font_impl.cc | 36 | ||||
-rw-r--r-- | ppapi/shared_impl/font_impl.h | 33 | ||||
-rw-r--r-- | ppapi/shared_impl/resource_object_base.h | 6 | ||||
-rw-r--r-- | ppapi/shared_impl/webkit_forwarding.cc | 36 | ||||
-rw-r--r-- | ppapi/shared_impl/webkit_forwarding.h | 104 |
6 files changed, 217 insertions, 4 deletions
diff --git a/ppapi/shared_impl/DEPS b/ppapi/shared_impl/DEPS index ebb73ea..512b07b 100644 --- a/ppapi/shared_impl/DEPS +++ b/ppapi/shared_impl/DEPS @@ -1,13 +1,11 @@ include_rules = [ "+base", + "+skia", + "+webkit/glue", # Since this is used by the implementation in /webkit, we don't want it to # depend on IPC. "-ipc", "-ppapi/cpp", - - # The image data implementation depends on how we're building Skia. This isn't - # a link-time dependency, so it's OK. - "+skia/config/SkUserConfig.h" ] diff --git a/ppapi/shared_impl/font_impl.cc b/ppapi/shared_impl/font_impl.cc new file mode 100644 index 0000000..3feaf9f --- /dev/null +++ b/ppapi/shared_impl/font_impl.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2011 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/shared_impl/font_impl.h" + +#include "ppapi/c/dev/ppb_font_dev.h" + +namespace pp { +namespace shared_impl { + +// static +bool FontImpl::IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc) { + // Check validity of string. We can't check the actual text since we could + // be on the wrong thread and don't know if we're in the plugin or the host. + if (desc.face.type != PP_VARTYPE_STRING && + desc.face.type != PP_VARTYPE_UNDEFINED) + return false; + + // Check enum ranges. + if (static_cast<int>(desc.family) < PP_FONTFAMILY_DEFAULT || + static_cast<int>(desc.family) > PP_FONTFAMILY_MONOSPACE) + return false; + if (static_cast<int>(desc.weight) < PP_FONTWEIGHT_100 || + static_cast<int>(desc.weight) > PP_FONTWEIGHT_900) + return false; + + // Check for excessive sizes which may cause layout to get confused. + if (desc.size > 200) + return false; + + return true; +} + +} // namespace shared_impl +} // namespace pp diff --git a/ppapi/shared_impl/font_impl.h b/ppapi/shared_impl/font_impl.h new file mode 100644 index 0000000..ebdf38a --- /dev/null +++ b/ppapi/shared_impl/font_impl.h @@ -0,0 +1,33 @@ +// Copyright (c) 2011 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_SHARED_IMPL_FONT_IMPL_H_ +#define PPAPI_SHARED_IMPL_FONT_IMPL_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_stdint.h" + +struct PP_FontDescription_Dev; + +namespace pp { +namespace shared_impl { + +class FontImpl { + public: + // Validates the parameters in thee description. Can be called on any thread. + static bool IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc); + + private: + DISALLOW_COPY_AND_ASSIGN(FontImpl); +}; + +} // namespace shared_impl +} // namespace pp + +#endif // PPAPI_SHARED_IMPL_FONT_IMPL_H_ diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h index 50ba30d..1a87360 100644 --- a/ppapi/shared_impl/resource_object_base.h +++ b/ppapi/shared_impl/resource_object_base.h @@ -8,6 +8,7 @@ namespace ppapi { namespace thunk { +class PPB_Font_API; class PPB_Graphics2D_API; class PPB_ImageData_API; } @@ -17,6 +18,7 @@ namespace shared_impl { class ResourceObjectBase { public: + virtual thunk::PPB_Font_API* AsFont_API() { return NULL; } virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; } virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; } @@ -24,6 +26,10 @@ class ResourceObjectBase { }; template<> +inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() { + return AsFont_API(); +} +template<> inline thunk::PPB_Graphics2D_API* ResourceObjectBase::GetAs() { return AsGraphics2D_API(); } diff --git a/ppapi/shared_impl/webkit_forwarding.cc b/ppapi/shared_impl/webkit_forwarding.cc new file mode 100644 index 0000000..02573f8 --- /dev/null +++ b/ppapi/shared_impl/webkit_forwarding.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2011 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/shared_impl/webkit_forwarding.h" + +namespace pp { +namespace shared_impl { + +WebKitForwarding::Font::DrawTextParams::DrawTextParams( + skia::PlatformCanvas* destination_arg, + const TextRun& text_arg, + const PP_Point* position_arg, + uint32_t color_arg, + const PP_Rect* clip_arg, + PP_Bool image_data_is_opaque_arg) + : destination(destination_arg), + text(text_arg), + position(position_arg), + color(color_arg), + clip(clip_arg), + image_data_is_opaque(image_data_is_opaque_arg) { +} + +WebKitForwarding::Font::DrawTextParams::~DrawTextParams() { +} + +WebKitForwarding::Font::~Font() { +} + +WebKitForwarding::~WebKitForwarding() { +} + +} // namespace shared_impl +} // namespace pp + diff --git a/ppapi/shared_impl/webkit_forwarding.h b/ppapi/shared_impl/webkit_forwarding.h new file mode 100644 index 0000000..aa788f8 --- /dev/null +++ b/ppapi/shared_impl/webkit_forwarding.h @@ -0,0 +1,104 @@ +// Copyright (c) 2011 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_SHARED_IMPL_WEBKIT_FORWARDING_H_ +#define PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ + +#include <string> + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_stdint.h" + +struct PP_FontDescription_Dev; +struct PP_FontMetrics_Dev; +struct PP_Point; +struct PP_Rect; + +namespace base { +class WaitableEvent; +} + +namespace skia { +class PlatformCanvas; +} + +namespace pp { +namespace shared_impl { + +class WebKitForwarding { + public: + class Font { + public: + // C++ version of PP_TextRun_Dev. Since the functions below will be called + // on an alternate thread in the proxy, and since there are different + // methods of converting PP_Var -> strings in the plugin and the proxy, we + // can't use PP_Vars in the Do* functions below. + struct TextRun { + std::string text; + bool rtl; + bool override_direction; + }; + + // DoDrawText takes too many arguments to be used with base::Bind, so we + // use this struct to hold them. + struct DrawTextParams { + DrawTextParams(skia::PlatformCanvas* destination_arg, + const TextRun& text_arg, + const PP_Point* position_arg, + uint32_t color_arg, + const PP_Rect* clip_arg, + PP_Bool image_data_is_opaque_arg); + ~DrawTextParams(); + + skia::PlatformCanvas* destination; + const TextRun& text; + const PP_Point* position; + uint32_t color; + const PP_Rect* clip; + PP_Bool image_data_is_opaque; + }; + + virtual ~Font(); + + // The face name in the description is not filled in to avoid a dependency + // on creating vars. Instead, the face name is placed into the given + // string. See class description for waitable_event documentation. If + // non-null, the given event will be set on completion. + virtual void Describe(base::WaitableEvent* event, + PP_FontDescription_Dev* description, + std::string* face, + PP_FontMetrics_Dev* metrics, + PP_Bool* result) = 0; + virtual void DrawTextAt(base::WaitableEvent* event, + const DrawTextParams& params) = 0; + virtual void MeasureText(base::WaitableEvent* event, + const TextRun& text, + int32_t* result) = 0; + virtual void CharacterOffsetForPixel(base::WaitableEvent* event, + const TextRun& text, + int32_t pixel_position, + uint32_t* result) = 0; + virtual void PixelOffsetForCharacter(base::WaitableEvent* event, + const TextRun& text, + uint32_t char_offset, + int32_t* result) = 0; + }; + + virtual ~WebKitForwarding(); + + // Creates a new font with the given description. The desc_face is the face + // name already extracted from the description. The caller owns the result + // pointer, which will never be NULL. If non-null, the given event will be + // set on completion. + virtual void CreateFontForwarding(base::WaitableEvent* event, + const PP_FontDescription_Dev& desc, + const std::string& desc_face, + Font** result) = 0; + +}; + +} // namespace shared_impl +} // namespace pp + +#endif // PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ |