Separate TransferableResource into own header
This is so that we can write the picklers without having to include webcore/wtf. This also changes the resource transfer functions to avoid copies. BUG=146080 Review URL: https://chromiumcodereview.appspot.com/11358080 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165847 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
3
cc/DEPS
3
cc/DEPS
@ -29,4 +29,7 @@ include_rules = [
|
||||
# http://crbug.com/154451
|
||||
"+third_party/WebKit/Source/WTF/config.h",
|
||||
"+Source/WTF/config.h",
|
||||
# TODO(piman): Remove as soon as ui/compositor uses cc directly.
|
||||
# http://crbug.com/159278
|
||||
"+third_party/WebKit/Source/Platform/chromium/public/WebCompositorTransferableResourceList.h"
|
||||
]
|
||||
|
@ -218,6 +218,8 @@
|
||||
'time_source.h',
|
||||
'timing_function.cc',
|
||||
'timing_function.h',
|
||||
'transferable_resource.cc',
|
||||
'transferable_resource.h',
|
||||
'tree_synchronizer.cc',
|
||||
'tree_synchronizer.h',
|
||||
'video_layer.cc',
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "cc/gl_renderer.h" // For the GLC() macro.
|
||||
#include "cc/proxy.h"
|
||||
#include "cc/texture_uploader.h"
|
||||
#include "cc/transferable_resource.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
#include "third_party/khronos/GLES2/gl2ext.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
@ -58,14 +59,6 @@ static bool isTextureFormatSupportedForStorage(GLenum format)
|
||||
return (format == GL_RGBA || format == GL_BGRA_EXT);
|
||||
}
|
||||
|
||||
ResourceProvider::TransferableResourceList::TransferableResourceList()
|
||||
{
|
||||
}
|
||||
|
||||
ResourceProvider::TransferableResourceList::~TransferableResourceList()
|
||||
{
|
||||
}
|
||||
|
||||
ResourceProvider::Resource::Resource()
|
||||
: glId(0)
|
||||
, pixels(0)
|
||||
@ -548,37 +541,36 @@ const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
|
||||
return it->second.childToParentMap;
|
||||
}
|
||||
|
||||
ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent(const ResourceIdArray& resources)
|
||||
void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, TransferableResourceList* list)
|
||||
{
|
||||
DCHECK(Proxy::isImplThread());
|
||||
TransferableResourceList list;
|
||||
list.syncPoint = 0;
|
||||
list->sync_point = 0;
|
||||
list->resources.clear();
|
||||
WebGraphicsContext3D* context3d = m_context->context3D();
|
||||
if (!context3d || !context3d->makeContextCurrent()) {
|
||||
// FIXME: Implement this path for software compositing.
|
||||
return list;
|
||||
return;
|
||||
}
|
||||
for (ResourceIdArray::const_iterator it = resources.begin(); it != resources.end(); ++it) {
|
||||
TransferableResource resource;
|
||||
if (transferResource(context3d, *it, &resource)) {
|
||||
m_resources.find(*it)->second.exported = true;
|
||||
list.resources.push_back(resource);
|
||||
list->resources.push_back(resource);
|
||||
}
|
||||
}
|
||||
if (list.resources.size())
|
||||
list.syncPoint = context3d->insertSyncPoint();
|
||||
return list;
|
||||
if (list->resources.size())
|
||||
list->sync_point = context3d->insertSyncPoint();
|
||||
}
|
||||
|
||||
ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& resources)
|
||||
void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& resources, TransferableResourceList* list)
|
||||
{
|
||||
DCHECK(Proxy::isImplThread());
|
||||
TransferableResourceList list;
|
||||
list.syncPoint = 0;
|
||||
list->sync_point = 0;
|
||||
list->resources.clear();
|
||||
WebGraphicsContext3D* context3d = m_context->context3D();
|
||||
if (!context3d || !context3d->makeContextCurrent()) {
|
||||
// FIXME: Implement this path for software compositing.
|
||||
return list;
|
||||
return;
|
||||
}
|
||||
Child& childInfo = m_children.find(child)->second;
|
||||
for (ResourceIdArray::const_iterator it = resources.begin(); it != resources.end(); ++it) {
|
||||
@ -589,12 +581,11 @@ ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
|
||||
resource.id = childInfo.parentToChildMap[*it];
|
||||
childInfo.parentToChildMap.erase(*it);
|
||||
childInfo.childToParentMap.erase(resource.id);
|
||||
list.resources.push_back(resource);
|
||||
list->resources.push_back(resource);
|
||||
deleteResource(*it);
|
||||
}
|
||||
if (list.resources.size())
|
||||
list.syncPoint = context3d->insertSyncPoint();
|
||||
return list;
|
||||
if (list->resources.size())
|
||||
list->sync_point = context3d->insertSyncPoint();
|
||||
}
|
||||
|
||||
void ResourceProvider::receiveFromChild(int child, const TransferableResourceList& resources)
|
||||
@ -605,14 +596,14 @@ void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
|
||||
// FIXME: Implement this path for software compositing.
|
||||
return;
|
||||
}
|
||||
if (resources.syncPoint) {
|
||||
if (resources.sync_point) {
|
||||
// NOTE: If the parent is a browser and the child a renderer, the parent
|
||||
// is not supposed to have its context wait, because that could induce
|
||||
// deadlocks and/or security issues. The caller is responsible for
|
||||
// waiting asynchronously, and resetting syncPoint before calling this.
|
||||
// waiting asynchronously, and resetting sync_point before calling this.
|
||||
// However if the parent is a renderer (e.g. browser tag), it may be ok
|
||||
// (and is simpler) to wait.
|
||||
GLC(context3d, context3d->waitSyncPoint(resources.syncPoint));
|
||||
GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
|
||||
}
|
||||
Child& childInfo = m_children.find(child)->second;
|
||||
for (TransferableResourceArray::const_iterator it = resources.resources.begin(); it != resources.resources.end(); ++it) {
|
||||
@ -637,8 +628,8 @@ void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
|
||||
// FIXME: Implement this path for software compositing.
|
||||
return;
|
||||
}
|
||||
if (resources.syncPoint)
|
||||
GLC(context3d, context3d->waitSyncPoint(resources.syncPoint));
|
||||
if (resources.sync_point)
|
||||
GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
|
||||
for (TransferableResourceArray::const_iterator it = resources.resources.begin(); it != resources.resources.end(); ++it) {
|
||||
ResourceMap::iterator mapIterator = m_resources.find(it->id);
|
||||
DCHECK(mapIterator != m_resources.end());
|
||||
@ -667,7 +658,7 @@ bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
|
||||
resource->id = id;
|
||||
resource->format = source->format;
|
||||
resource->size = source->size;
|
||||
if (m_mailboxes.size()) {
|
||||
if (!m_mailboxes.empty()) {
|
||||
resource->mailbox = m_mailboxes.front();
|
||||
m_mailboxes.pop_front();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "cc/cc_export.h"
|
||||
#include "cc/graphics_context.h"
|
||||
#include "cc/texture_copier.h"
|
||||
#include "cc/transferable_resource.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
@ -43,23 +44,6 @@ public:
|
||||
GLTexture = 1,
|
||||
Bitmap,
|
||||
};
|
||||
struct Mailbox {
|
||||
GLbyte name[64];
|
||||
};
|
||||
struct TransferableResource {
|
||||
unsigned id;
|
||||
GLenum format;
|
||||
gfx::Size size;
|
||||
Mailbox mailbox;
|
||||
};
|
||||
typedef std::vector<TransferableResource> TransferableResourceArray;
|
||||
struct CC_EXPORT TransferableResourceList {
|
||||
TransferableResourceList();
|
||||
~TransferableResourceList();
|
||||
|
||||
TransferableResourceArray resources;
|
||||
unsigned syncPoint;
|
||||
};
|
||||
|
||||
static scoped_ptr<ResourceProvider> create(GraphicsContext*);
|
||||
|
||||
@ -122,16 +106,16 @@ public:
|
||||
|
||||
// Prepares resources to be transfered to the parent, moving them to
|
||||
// mailboxes and serializing meta-data into TransferableResources.
|
||||
// Resources are not removed from the ResourceProvider, but are markes as
|
||||
// Resources are not removed from the ResourceProvider, but are marked as
|
||||
// "in use".
|
||||
TransferableResourceList prepareSendToParent(const ResourceIdArray&);
|
||||
void prepareSendToParent(const ResourceIdArray&, TransferableResourceList*);
|
||||
|
||||
// Prepares resources to be transfered back to the child, moving them to
|
||||
// mailboxes and serializing meta-data into TransferableResources.
|
||||
// Resources are removed from the ResourceProvider. Note: the resource IDs
|
||||
// passed are in the parent namespace and will be translated to the child
|
||||
// namespace when returned.
|
||||
TransferableResourceList prepareSendToChild(int child, const ResourceIdArray&);
|
||||
void prepareSendToChild(int child, const ResourceIdArray&, TransferableResourceList*);
|
||||
|
||||
// Receives resources from a child, moving them from mailboxes. Resource IDs
|
||||
// passed are in the child namespace, and will be translated to the parent
|
||||
|
@ -443,8 +443,9 @@ TEST_P(ResourceProviderTest, TransferResources)
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(id1);
|
||||
resourceIdsToTransfer.push_back(id2);
|
||||
ResourceProvider::TransferableResourceList list = childResourceProvider->prepareSendToParent(resourceIdsToTransfer);
|
||||
EXPECT_NE(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
|
||||
EXPECT_NE(0u, list.sync_point);
|
||||
EXPECT_EQ(2u, list.resources.size());
|
||||
EXPECT_TRUE(childResourceProvider->inUseByConsumer(id1));
|
||||
EXPECT_TRUE(childResourceProvider->inUseByConsumer(id2));
|
||||
@ -473,8 +474,9 @@ TEST_P(ResourceProviderTest, TransferResources)
|
||||
// parent is a noop.
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(id1);
|
||||
ResourceProvider::TransferableResourceList list = childResourceProvider->prepareSendToParent(resourceIdsToTransfer);
|
||||
EXPECT_EQ(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
|
||||
EXPECT_EQ(0u, list.sync_point);
|
||||
EXPECT_EQ(0u, list.resources.size());
|
||||
}
|
||||
|
||||
@ -483,8 +485,9 @@ TEST_P(ResourceProviderTest, TransferResources)
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(mappedId1);
|
||||
resourceIdsToTransfer.push_back(mappedId2);
|
||||
ResourceProvider::TransferableResourceList list = m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer);
|
||||
EXPECT_NE(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &list);
|
||||
EXPECT_NE(0u, list.sync_point);
|
||||
EXPECT_EQ(2u, list.resources.size());
|
||||
childResourceProvider->receiveFromParent(list);
|
||||
}
|
||||
@ -514,8 +517,9 @@ TEST_P(ResourceProviderTest, TransferResources)
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(id1);
|
||||
resourceIdsToTransfer.push_back(id2);
|
||||
ResourceProvider::TransferableResourceList list = childResourceProvider->prepareSendToParent(resourceIdsToTransfer);
|
||||
EXPECT_NE(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
|
||||
EXPECT_NE(0u, list.sync_point);
|
||||
EXPECT_EQ(2u, list.resources.size());
|
||||
EXPECT_TRUE(childResourceProvider->inUseByConsumer(id1));
|
||||
EXPECT_TRUE(childResourceProvider->inUseByConsumer(id2));
|
||||
@ -555,8 +559,9 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources)
|
||||
// Transfer some resource to the parent.
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(id);
|
||||
ResourceProvider::TransferableResourceList list = childResourceProvider->prepareSendToParent(resourceIdsToTransfer);
|
||||
EXPECT_NE(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list);
|
||||
EXPECT_NE(0u, list.sync_point);
|
||||
EXPECT_EQ(1u, list.resources.size());
|
||||
EXPECT_TRUE(childResourceProvider->inUseByConsumer(id));
|
||||
m_resourceProvider->receiveFromChild(childId, list);
|
||||
@ -573,8 +578,9 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources)
|
||||
EXPECT_NE(0u, mappedId);
|
||||
ResourceProvider::ResourceIdArray resourceIdsToTransfer;
|
||||
resourceIdsToTransfer.push_back(mappedId);
|
||||
ResourceProvider::TransferableResourceList list = m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer);
|
||||
EXPECT_NE(0u, list.syncPoint);
|
||||
TransferableResourceList list;
|
||||
m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &list);
|
||||
EXPECT_NE(0u, list.sync_point);
|
||||
EXPECT_EQ(1u, list.resources.size());
|
||||
childResourceProvider->receiveFromParent(list);
|
||||
}
|
||||
|
24
cc/transferable_resource.cc
Normal file
24
cc/transferable_resource.cc
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2012 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 "cc/transferable_resource.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
TransferableResource::TransferableResource()
|
||||
: id(0),
|
||||
format(0) {
|
||||
}
|
||||
|
||||
TransferableResource::~TransferableResource() {
|
||||
}
|
||||
|
||||
TransferableResourceList::TransferableResourceList()
|
||||
: sync_point(0) {
|
||||
}
|
||||
|
||||
TransferableResourceList::~TransferableResourceList() {
|
||||
}
|
||||
|
||||
} // namespace cc
|
44
cc/transferable_resource.h
Normal file
44
cc/transferable_resource.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2012 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 CC_TRANSERABLE_RESOURCE_H_
|
||||
#define CC_TRANSERABLE_RESOURCE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "cc/cc_export.h"
|
||||
#include "ui/gfx/size.h"
|
||||
#include "third_party/khronos/GLES2/gl2.h"
|
||||
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorTransferableResourceList.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
struct Mailbox {
|
||||
GLbyte name[64];
|
||||
};
|
||||
|
||||
struct CC_EXPORT TransferableResource {
|
||||
TransferableResource();
|
||||
~TransferableResource();
|
||||
|
||||
unsigned id;
|
||||
GLenum format;
|
||||
gfx::Size size;
|
||||
Mailbox mailbox;
|
||||
};
|
||||
|
||||
typedef std::vector<TransferableResource> TransferableResourceArray;
|
||||
|
||||
struct CC_EXPORT TransferableResourceList :
|
||||
public NON_EXPORTED_BASE(WebKit::WebCompositorTransferableResourceList) {
|
||||
TransferableResourceList();
|
||||
~TransferableResourceList();
|
||||
|
||||
TransferableResourceArray resources;
|
||||
unsigned sync_point;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_TRANSERABLE_RESOURCE_H_
|
Reference in New Issue
Block a user