diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 18:15:52 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 18:15:52 +0000 |
commit | 0bd753681a82634f322d4867b19148474c25566b (patch) | |
tree | 2f96cb4494c075ddee5a3e42e6b41c096a5357a9 /webkit/plugins/ppapi/ppb_buffer_impl.cc | |
parent | d1d0afe664ff43825a4585f88ee8ce412eab0194 (diff) | |
download | chromium_src-0bd753681a82634f322d4867b19148474c25566b.zip chromium_src-0bd753681a82634f322d4867b19148474c25566b.tar.gz chromium_src-0bd753681a82634f322d4867b19148474c25566b.tar.bz2 |
Move the Pepper implementation from webkit/glue/plugins/pepper_* to
webkit/plugins/ppapi/*. This renamed the files and interface implementation
classes from foo.cc/Foo to ppb_foo_impl/PPB_Foo_Impl to match the proxy
ppb_foo_proxy/PPB_Foo_Proxy.
This moves plugin_switches.* from webkit/glue/plugins to webkit/plugins.
Review URL: http://codereview.chromium.org/5828003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/ppb_buffer_impl.cc')
-rw-r--r-- | webkit/plugins/ppapi/ppb_buffer_impl.cc | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.cc b/webkit/plugins/ppapi/ppb_buffer_impl.cc new file mode 100644 index 0000000..1c67ec3 --- /dev/null +++ b/webkit/plugins/ppapi/ppb_buffer_impl.cc @@ -0,0 +1,121 @@ +// 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 "webkit/plugins/ppapi/ppb_buffer_impl.h" + +#include <algorithm> + +#include "base/logging.h" +#include "base/scoped_ptr.h" +#include "ppapi/c/dev/ppb_buffer_dev.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/plugin_module.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" + +namespace webkit { +namespace ppapi { + +namespace { + +PP_Resource Create(PP_Module module_id, uint32_t size) { + PluginModule* module = ResourceTracker::Get()->GetModule(module_id); + if (!module) + return 0; + + scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(module)); + if (!buffer->Init(size)) + return 0; + + return buffer->GetReference(); +} + +PP_Bool IsPPB_Buffer_Impl(PP_Resource resource) { + return BoolToPPBool(!!Resource::GetAs<PPB_Buffer_Impl>(resource)); +} + +PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { + scoped_refptr<PPB_Buffer_Impl> buffer( + Resource::GetAs<PPB_Buffer_Impl>(resource)); + if (!buffer) + return PP_FALSE; + buffer->Describe(size_in_bytes); + return PP_TRUE; +} + +void* Map(PP_Resource resource) { + scoped_refptr<PPB_Buffer_Impl> buffer( + Resource::GetAs<PPB_Buffer_Impl>(resource)); + if (!buffer) + return NULL; + return buffer->Map(); +} + +void Unmap(PP_Resource resource) { + scoped_refptr<PPB_Buffer_Impl> buffer( + Resource::GetAs<PPB_Buffer_Impl>(resource)); + if (!buffer) + return; + return buffer->Unmap(); +} + +const PPB_Buffer_Dev ppb_buffer = { + &Create, + &IsPPB_Buffer_Impl, + &Describe, + &Map, + &Unmap, +}; + +} // namespace + +PPB_Buffer_Impl::PPB_Buffer_Impl(PluginModule* module) + : Resource(module), + size_(0) { +} + +PPB_Buffer_Impl::~PPB_Buffer_Impl() { +} + +// static +const PPB_Buffer_Dev* PPB_Buffer_Impl::GetInterface() { + return &ppb_buffer; +} + +PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { + return this; +} + +bool PPB_Buffer_Impl::Init(uint32_t size) { + if (size == 0) + return false; + Unmap(); + size_ = size; + return true; +} + +void PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) const { + *size_in_bytes = size_; +} + +void* PPB_Buffer_Impl::Map() { + if (size_ == 0) + return NULL; + + if (!is_mapped()) { + mem_buffer_.reset(new unsigned char[size_]); + memset(mem_buffer_.get(), 0, size_); + } + return mem_buffer_.get(); +} + +void PPB_Buffer_Impl::Unmap() { + mem_buffer_.reset(); +} + +} // namespace ppapi +} // namespace webkit + |