diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 00:26:43 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 00:26:43 +0000 |
commit | 4614f1974881ecfd0a0118683bac628c6128c2a9 (patch) | |
tree | c69836459560dd8003f7e18ca554f2e1d7f79b4d /webkit | |
parent | b8e6654fb91108033580f510e2d411093936fc2f (diff) | |
download | chromium_src-4614f1974881ecfd0a0118683bac628c6128c2a9.zip chromium_src-4614f1974881ecfd0a0118683bac628c6128c2a9.tar.gz chromium_src-4614f1974881ecfd0a0118683bac628c6128c2a9.tar.bz2 |
First pass at making the proxy handle multiple renderers. This associates the
instance with resources and has most callers retrieve the dispatcher
according to the appropriate instance. This isn't hooked up to anything yet.
This changes some PPB_Flash interface methods to use PP_Bool.
The most challenging part of the change is in the plugin_var_tracker which
now needs to track which dispatcher each var object came from, and remap var
IDs since each renderer will be generating var IDs in its own space, which
will likely overlap. A similar system will need to be done for resources
which is not implemented yet.
I added some null checks in audio_impl because audio_ can be NULL in some
cases when using the trusted API. I discovered this when testing NaCl for
this patch.
Review URL: http://codereview.chromium.org/6282007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72053 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 9 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_audio_impl.cc | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_impl.cc | 21 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_impl.h | 22 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_impl_linux.cc | 30 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_font_impl.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_image_data_impl.cc | 17 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_image_data_impl.h | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_tracker.cc | 19 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_tracker.h | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_tracker_unittest.cc | 14 |
11 files changed, 71 insertions, 91 deletions
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index ea0188d..fdd9448 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -191,18 +191,15 @@ void QuitMessageLoop() { MessageLoop::current()->QuitNow(); } -uint32_t GetLiveObjectCount(PP_Module module_id) { - PluginModule* module = ResourceTracker::Get()->GetModule(module_id); - if (!module) - return static_cast<uint32_t>(-1); - return ResourceTracker::Get()->GetLiveObjectsForModule(module); +uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { + return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id); } const PPB_Testing_Dev testing_interface = { &ReadImageData, &RunMessageLoop, &QuitMessageLoop, - &GetLiveObjectCount + &GetLiveObjectsForInstance }; // GetInterface ---------------------------------------------------------------- diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc index 93561f8..1a36e70 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.cc +++ b/webkit/plugins/ppapi/ppb_audio_impl.cc @@ -49,6 +49,8 @@ uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count) { // TODO(brettw) Currently we don't actually query to get a value from the // hardware, so we always return the input for in-range values. + // + // Danger: this code is duplicated in the audio config proxy. if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) return PP_AUDIOMINSAMPLEFRAMECOUNT; if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) @@ -219,8 +221,10 @@ PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) PPB_Audio_Impl::~PPB_Audio_Impl() { // Calling ShutDown() makes sure StreamCreated cannot be called anymore. - audio_->ShutDown(); - audio_ = NULL; + if (audio_) { + audio_->ShutDown(); + audio_ = NULL; + } // If the completion callback hasn't fired yet, do so here // with an error condition. @@ -263,6 +267,8 @@ PP_Resource PPB_Audio_Impl::GetCurrentConfig() { } bool PPB_Audio_Impl::StartPlayback() { + if (!audio_) + return false; if (playing()) return true; SetStartPlaybackState(); @@ -270,6 +276,8 @@ bool PPB_Audio_Impl::StartPlayback() { } bool PPB_Audio_Impl::StopPlayback() { + if (!audio_) + return false; if (!playing()) return true; if (!audio_->StopPlayback()) diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index 386b24f..33e0d11 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -28,11 +28,11 @@ namespace ppapi { namespace { -void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) { +void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return; - instance->set_always_on_top(on_top); + instance->set_always_on_top(PPBoolToBool(on_top)); } PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { @@ -114,14 +114,15 @@ int32_t RenameModuleLocalFile(PP_Instance pp_instance, int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, const char* path, - bool recursive) { + PP_Bool recursive) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; base::PlatformFileError result = instance->delegate()->DeleteModuleLocalFileOrDir( - instance->module()->name(), GetFilePathFromUTF8(path), recursive); + instance->module()->name(), GetFilePathFromUTF8(path), + PPBoolToBool(recursive)); return PlatformFileErrorToPepperError(result); } @@ -192,7 +193,7 @@ int32_t GetModuleLocalDirContents(PP_Instance pp_instance, char* name_copy = new char[size]; memcpy(name_copy, name.c_str(), size); entry.name = name_copy; - entry.is_dir = pepper_contents[i].is_dir; + entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); } return PP_OK; } @@ -207,13 +208,13 @@ void FreeModuleLocalDirContents(PP_Instance instance, delete contents; } -bool NavigateToURL(PP_Instance pp_instance, - const char* url, - const char* target) { +PP_Bool NavigateToURL(PP_Instance pp_instance, + const char* url, + const char* target) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) - return false; - return instance->NavigateToURL(url, target); + return PP_FALSE; + return BoolToPPBool(instance->NavigateToURL(url, target)); } const PPB_Flash ppb_flash = { diff --git a/webkit/plugins/ppapi/ppb_flash_impl.h b/webkit/plugins/ppapi/ppb_flash_impl.h index 7eb2e8b..8b02dee 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_impl.h @@ -23,20 +23,20 @@ class PPB_Flash_Impl { // exposed to the plugin. static const PPB_Flash* GetInterface(); - static bool DrawGlyphs(PP_Instance pp_instance, - PP_Resource pp_image_data, - const PP_FontDescription_Dev* font_desc, - uint32_t color, - PP_Point position, - PP_Rect clip, - const float transformation[3][3], - uint32_t glyph_count, - const uint16_t glyph_indices[], - const PP_Point glyph_advances[]) + static PP_Bool DrawGlyphs(PP_Instance pp_instance, + PP_Resource pp_image_data, + const PP_FontDescription_Dev* font_desc, + uint32_t color, + PP_Point position, + PP_Rect clip, + const float transformation[3][3], + uint32_t glyph_count, + const uint16_t glyph_indices[], + const PP_Point glyph_advances[]) #if defined(OS_LINUX) ; #else - { return false; } + { return PP_FALSE; } #endif private: diff --git a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc index 50346b4..bd554c7b 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl_linux.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl_linux.cc @@ -20,28 +20,28 @@ namespace webkit { namespace ppapi { -bool PPB_Flash_Impl::DrawGlyphs(PP_Instance, - PP_Resource pp_image_data, - const PP_FontDescription_Dev* font_desc, - uint32_t color, - PP_Point position, - PP_Rect clip, - const float transformation[3][3], - uint32_t glyph_count, - const uint16_t glyph_indices[], - const PP_Point glyph_advances[]) { +PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance, + PP_Resource pp_image_data, + const PP_FontDescription_Dev* font_desc, + uint32_t color, + PP_Point position, + PP_Rect clip, + const float transformation[3][3], + uint32_t glyph_count, + const uint16_t glyph_indices[], + const PP_Point glyph_advances[]) { scoped_refptr<PPB_ImageData_Impl> image_resource( Resource::GetAs<PPB_ImageData_Impl>(pp_image_data)); if (!image_resource.get()) - return false; + return PP_FALSE; ImageDataAutoMapper mapper(image_resource); if (!mapper.is_valid()) - return false; + return PP_FALSE; // Set up the typeface. scoped_refptr<StringVar> face_name(StringVar::FromPPVar(font_desc->face)); if (!face_name) - return false; + return PP_FALSE; int style = SkTypeface::kNormal; if (font_desc->weight >= PP_FONTWEIGHT_BOLD) style |= SkTypeface::kBold; @@ -51,7 +51,7 @@ bool PPB_Flash_Impl::DrawGlyphs(PP_Instance, SkTypeface::CreateFromName(face_name->value().c_str(), static_cast<SkTypeface::Style>(style)); if (!typeface) - return false; + return PP_FALSE; // Set up the canvas. SkCanvas* canvas = image_resource->mapped_canvas(); @@ -105,7 +105,7 @@ bool PPB_Flash_Impl::DrawGlyphs(PP_Instance, canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); canvas->restore(); - return true; + return PP_TRUE; } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 8f4b6fd..b0a99ada 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -161,7 +161,7 @@ uint32_t CharacterOffsetForPixel(PP_Resource font_id, int32_t pixel_position) { scoped_refptr<PPB_Font_Impl> font(Resource::GetAs<PPB_Font_Impl>(font_id)); if (!font.get()) - return false; + return -1; return font->CharacterOffsetForPixel(text, pixel_position); } diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc index 042f38b..062e613 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.cc +++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc @@ -129,23 +129,6 @@ const PPB_ImageDataTrusted* PPB_ImageData_Impl::GetTrustedInterface() { return &ppb_imagedata_trusted; } -// static -PP_ImageDataFormat PPB_ImageData_Impl::GetNativeImageDataFormat() { - if (SK_B32_SHIFT == 0) - return PP_IMAGEDATAFORMAT_BGRA_PREMUL; - else if (SK_R32_SHIFT == 0) - return PP_IMAGEDATAFORMAT_RGBA_PREMUL; - else - return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. -} - -// static -bool PPB_ImageData_Impl::IsImageDataFormatSupported( - PP_ImageDataFormat format) { - return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL || - format == PP_IMAGEDATAFORMAT_RGBA_PREMUL; -} - PPB_ImageData_Impl* PPB_ImageData_Impl::AsPPB_ImageData_Impl() { return this; } diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h index 84b2bde..9260d98 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.h +++ b/webkit/plugins/ppapi/ppb_image_data_impl.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "ppapi/c/ppb_image_data.h" +#include "ppapi/shared_impl/image_data_impl.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/resource.h" @@ -21,7 +22,8 @@ class SkBitmap; namespace webkit { namespace ppapi { -class PPB_ImageData_Impl : public Resource { +class PPB_ImageData_Impl : public Resource, + public pp::shared_impl::ImageDataImpl { public: explicit PPB_ImageData_Impl(PluginInstance* instance); virtual ~PPB_ImageData_Impl(); @@ -45,14 +47,6 @@ class PPB_ImageData_Impl : public Resource { static const PPB_ImageData* GetInterface(); static const PPB_ImageDataTrusted* GetTrustedInterface(); - // Returns the image data format used by the browser. If the plugin uses the - // same format, there is no conversion. Otherwise the browser will be in - // charge of converting from a supported format to its native format. - static PP_ImageDataFormat GetNativeImageDataFormat(); - - // Returns true if the format is supported by the browser. - static bool IsImageDataFormatSupported(PP_ImageDataFormat format); - // Resource overrides. virtual PPB_ImageData_Impl* AsPPB_ImageData_Impl(); diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 730c36a..6507e2d 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -155,18 +155,13 @@ void ResourceTracker::ForceDeletePluginResourceRefs(PP_Resource res) { live_resources_.erase(i); } -uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const { - // Since this is for testing only, we'll just go through all of them and - // count. - // - // TODO(brettw) we will eventually need to implement more efficient - // module->resource lookup to free resources when a module is unloaded. In - // this case, this function can be implemented using that system. - uint32 count = 0; - for (ResourceMap::const_iterator i = live_resources_.begin(); - i != live_resources_.end(); ++i) - count++; - return count; +uint32 ResourceTracker::GetLiveObjectsForInstance( + PP_Instance instance) const { + InstanceToResourceMap::const_iterator found = + instance_to_resources_.find(instance); + if (found == instance_to_resources_.end()) + return 0; + return static_cast<uint32>(found->second.size()); } scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const { diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index 0b49ad8..ce577c3 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -63,9 +63,7 @@ class ResourceTracker { void ForceDeletePluginResourceRefs(PP_Resource res); // Returns the number of resources associated with this module. - // - // This is slow, use only for testing. - uint32 GetLiveObjectsForModule(PluginModule* module) const; + uint32 GetLiveObjectsForInstance(PP_Instance instance) const; // PP_Vars ------------------------------------------------------------------- diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc index bbcff1f..6e7b2a4 100644 --- a/webkit/plugins/ppapi/resource_tracker_unittest.cc +++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc @@ -53,7 +53,8 @@ class ResourceTrackerTest : public PpapiUnittest { TEST_F(ResourceTrackerTest, Ref) { ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); - EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module())); + EXPECT_EQ(0u, + tracker().GetLiveObjectsForInstance(instance()->pp_instance())); { scoped_refptr<TrackedMockResource> new_resource( new TrackedMockResource(instance())); @@ -61,7 +62,8 @@ TEST_F(ResourceTrackerTest, Ref) { // Since we haven't gotten a PP_Resource, it's not associated with the // module. - EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module())); + EXPECT_EQ(0u, + tracker().GetLiveObjectsForInstance(instance()->pp_instance())); } ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive); @@ -72,7 +74,8 @@ TEST_F(ResourceTrackerTest, Ref) { new TrackedMockResource(instance())); ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive); resource_id = new_resource->GetReference(); - EXPECT_EQ(1u, tracker().GetLiveObjectsForModule(module())); + EXPECT_EQ(1u, + tracker().GetLiveObjectsForInstance(instance()->pp_instance())); // Resource IDs should be consistent. PP_Resource resource_id_2 = new_resource->GetReference(); @@ -96,6 +99,7 @@ TEST_F(ResourceTrackerTest, ForceDeleteWithInstance) { new PluginInstance(delegate(), module(), static_cast<const PPP_Instance*>( GetMockInterface(PPP_INSTANCE_INTERFACE)))); + PP_Instance pp_instance2 = instance2->pp_instance(); // Make two resources and take refs on behalf of the "plugin" for each. scoped_refptr<TrackedMockResource> resource1( @@ -110,11 +114,11 @@ TEST_F(ResourceTrackerTest, ForceDeleteWithInstance) { resource2 = NULL; ASSERT_EQ(2, TrackedMockResource::tracked_objects_alive); - EXPECT_EQ(2u, tracker().GetLiveObjectsForModule(module())); + EXPECT_EQ(2u, tracker().GetLiveObjectsForInstance(pp_instance2)); // Free the instance, this should release both plugin refs. instance2 = NULL; - EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module())); + EXPECT_EQ(0u, tracker().GetLiveObjectsForInstance(pp_instance2)); // The resource we have a scoped_refptr to should still be alive, but it // should have a NULL instance. |