Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1190)

Unified Diff: cc/resources/resource_provider.cc

Issue 14409006: cc: Changes to use GL API for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/resource_provider.cc
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 7c55a3c52f3fcdca765f14714facf03ea878b535..4588339e677d842398e38d3792b1767465566a9f 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -21,6 +21,7 @@
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/vector2d.h"
+#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
using WebKit::WebGraphicsContext3D;
@@ -80,12 +81,14 @@ ResourceProvider::Resource::Resource()
size(),
format(0),
filter(0),
- type(static_cast<ResourceType>(0)) {}
+ type(static_cast<ResourceType>(0)),
+ use_gpu_memory_buffer(false) {}
ResourceProvider::Resource::~Resource() {}
ResourceProvider::Resource::Resource(
- unsigned texture_id, gfx::Size size, GLenum format, GLenum filter)
+ unsigned texture_id, gfx::Size size,
+ GLenum format, GLenum filter, bool gpu_memory_buffer)
: gl_id(texture_id),
gl_pixel_buffer_id(0),
gl_upload_query_id(0),
@@ -104,7 +107,8 @@ ResourceProvider::Resource::Resource(
size(size),
format(format),
filter(filter),
- type(GLTexture) {}
+ type(GLTexture),
+ use_gpu_memory_buffer(gpu_memory_buffer) {}
ResourceProvider::Resource::Resource(
uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter)
@@ -126,7 +130,8 @@ ResourceProvider::Resource::Resource(
size(size),
format(format),
filter(filter),
- type(Bitmap) {}
+ type(Bitmap),
+ use_gpu_memory_buffer(false) {}
ResourceProvider::Child::Child() {}
@@ -217,7 +222,8 @@ ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
}
ResourceId id = next_id_++;
- Resource resource(texture_id, size, format, GL_LINEAR);
+ Resource resource(texture_id, size, format, GL_LINEAR,
+ use_gpu_memory_buffers_);
resource.allocated = false;
resources_[id] = resource;
return id;
@@ -254,7 +260,7 @@ ResourceProvider::CreateResourceFromExternalTexture(
texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
ResourceId id = next_id_++;
- Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR);
+ Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, false);
resource.external = true;
resource.allocated = true;
resources_[id] = resource;
@@ -267,7 +273,7 @@ ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
// Just store the information. Mailbox will be consumed in LockForRead().
ResourceId id = next_id_++;
unsigned texture_id = 0;
- Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR);
+ Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, false);
resource.external = true;
resource.allocated = true;
resource.mailbox = mailbox;
@@ -361,6 +367,7 @@ void ResourceProvider::SetPixels(ResourceId id,
DCHECK(!resource->lock_for_read_count);
DCHECK(!resource->external);
DCHECK(!resource->exported);
+ DCHECK(!resource->use_gpu_memory_buffer);
DCHECK(ReadLockFenceHasPassed(resource));
LazyAllocate(resource);
@@ -614,7 +621,8 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface)
use_texture_usage_hint_(false),
use_shallow_flush_(false),
max_texture_size_(0),
- best_texture_format_(0) {}
+ best_texture_format_(0),
+ use_gpu_memory_buffers_(false) {}
bool ResourceProvider::Initialize(int highp_threshold_min) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -786,7 +794,7 @@ void ResourceProvider::ReceiveFromChild(
GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
it->mailbox.name));
ResourceId id = next_id_++;
- Resource resource(texture_id, it->size, it->format, it->filter);
+ Resource resource(texture_id, it->size, it->format, it->filter, false);
resource.mailbox.SetName(it->mailbox);
// Don't allocate a texture for a child.
resource.allocated = true;
@@ -880,15 +888,25 @@ void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
DCHECK(context3d);
if (!resource->gl_pixel_buffer_id)
resource->gl_pixel_buffer_id = context3d->createBuffer();
- context3d->bindBuffer(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->gl_pixel_buffer_id);
- context3d->bufferData(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->size.width() * resource->size.height() * 4,
- NULL,
- GL_DYNAMIC_DRAW);
- context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
+ WGC3Denum target = GetTargetGivenResource(resource);
+ context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
+ if (resource->use_gpu_memory_buffer) {
+ typedef webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
+ Context3DImpl;
+ Context3DImpl* in_process_context =
+ static_cast<Context3DImpl*>(context3d);
jamesr 2013/04/25 22:28:56 you shouldn't be downcasting like this. it means t
kaanb1 2013/04/25 22:43:29 This feature is currently only used for Android We
no sievers 2013/04/25 23:28:14 Keep in mind that ChromeOS might implement 0-copy
kaanb1 2013/04/25 23:55:05 Done.
+ in_process_context->imageBufferDataCHROMIUM(
+ target,
+ resource->size.width(),
+ resource->size.height());
+ } else {
+ context3d->bufferData(
+ target,
+ resource->size.width() * resource->size.height() * 4,
+ NULL,
+ GL_DYNAMIC_DRAW);
+ }
+ context3d->bindBuffer(target, 0);
}
if (resource->pixels) {
@@ -911,16 +929,19 @@ void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
if (resource->gl_id) {
DCHECK(resource->gl_pixel_buffer_id);
WebGraphicsContext3D* context3d = output_surface_->context3d();
+ WGC3Denum target = GetTargetGivenResource(resource);
DCHECK(context3d);
- context3d->bindBuffer(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->gl_pixel_buffer_id);
- context3d->bufferData(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- 0,
- NULL,
- GL_DYNAMIC_DRAW);
- context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
+ context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
+ if (resource->use_gpu_memory_buffer) {
+ typedef webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
+ Context3DImpl;
+ Context3DImpl* in_process_context =
+ static_cast<Context3DImpl*>(context3d);
+ in_process_context->imageBufferDataCHROMIUM(target, 0, 0);
+ } else {
+ context3d->bufferData(target, 0, NULL, GL_DYNAMIC_DRAW);
+ }
+ context3d->bindBuffer(target, 0);
}
if (resource->pixels) {
@@ -943,13 +964,11 @@ uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
- context3d->bindBuffer(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->gl_pixel_buffer_id);
+ WGC3Denum target = GetTargetGivenResource(resource);
+ context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
uint8_t* image = static_cast<uint8_t*>(
- context3d->mapBufferCHROMIUM(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY));
- context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
+ context3d->mapBufferCHROMIUM(target, GL_WRITE_ONLY));
+ context3d->bindBuffer(target, 0);
DCHECK(image);
return image;
}
@@ -972,12 +991,10 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
- context3d->bindBuffer(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->gl_pixel_buffer_id);
- context3d->unmapBufferCHROMIUM(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM);
- context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
+ WGC3Denum target = GetTargetGivenResource(resource);
+ context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
+ context3d->unmapBufferCHROMIUM(target);
+ context3d->bindBuffer(target, 0);
}
}
@@ -991,6 +1008,7 @@ void ResourceProvider::SetPixelsFromBuffer(ResourceId id) {
DCHECK(!resource->external);
DCHECK(!resource->exported);
DCHECK(ReadLockFenceHasPassed(resource));
+ DCHECK(!resource->use_gpu_memory_buffer);
LazyAllocate(resource);
if (resource->gl_id) {
@@ -1068,37 +1086,42 @@ void ResourceProvider::BeginSetPixels(ResourceId id) {
DCHECK(context3d);
DCHECK(resource->gl_pixel_buffer_id);
context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
- context3d->bindBuffer(
- GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- resource->gl_pixel_buffer_id);
- if (!resource->gl_upload_query_id)
- resource->gl_upload_query_id = context3d->createQueryEXT();
- context3d->beginQueryEXT(
- GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
- resource->gl_upload_query_id);
- if (allocate) {
- context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
- 0, /* level */
- resource->format,
- resource->size.width(),
- resource->size.height(),
- 0, /* border */
- resource->format,
- GL_UNSIGNED_BYTE,
- NULL);
+ if (resource->use_gpu_memory_buffer) {
+ context3d->bindTexImage2DCHROMIUM(
+ GL_TEXTURE_2D, resource->gl_pixel_buffer_id);
} else {
- context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
- 0, /* level */
- 0, /* x */
- 0, /* y */
- resource->size.width(),
- resource->size.height(),
- resource->format,
- GL_UNSIGNED_BYTE,
- NULL);
+ context3d->bindBuffer(
+ GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
+ resource->gl_pixel_buffer_id);
+ if (!resource->gl_upload_query_id)
+ resource->gl_upload_query_id = context3d->createQueryEXT();
+ context3d->beginQueryEXT(
+ GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
+ resource->gl_upload_query_id);
+ if (allocate) {
+ context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
+ 0, /* level */
+ resource->format,
+ resource->size.width(),
+ resource->size.height(),
+ 0, /* border */
+ resource->format,
+ GL_UNSIGNED_BYTE,
+ NULL);
+ } else {
+ context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
+ 0, /* level */
+ 0, /* x */
+ 0, /* y */
+ resource->size.width(),
+ resource->size.height(),
+ resource->format,
+ GL_UNSIGNED_BYTE,
+ NULL);
+ }
+ context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
+ context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
}
- context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
- context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
}
if (resource->pixels)
@@ -1116,6 +1139,7 @@ void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) {
DCHECK(resource->locked_for_write);
DCHECK(resource->pending_set_pixels);
DCHECK(!resource->set_pixels_completion_forced);
+ DCHECK(!resource->use_gpu_memory_buffer);
if (resource->gl_id) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
@@ -1134,6 +1158,7 @@ bool ResourceProvider::DidSetPixelsComplete(ResourceId id) {
Resource* resource = &it->second;
DCHECK(resource->locked_for_write);
DCHECK(resource->pending_set_pixels);
+ DCHECK(!resource->use_gpu_memory_buffer);
if (resource->gl_id) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
@@ -1161,6 +1186,7 @@ void ResourceProvider::AbortSetPixels(ResourceId id) {
Resource* resource = &it->second;
DCHECK(resource->locked_for_write);
DCHECK(resource->pending_set_pixels);
+ DCHECK(!resource->use_gpu_memory_buffer);
if (resource->gl_id) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
@@ -1227,4 +1253,14 @@ void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
resource->enable_read_lock_fences = enable;
}
+void ResourceProvider::SetUseGpuMemoryBuffers(bool use_gpu_memory_buffers) {
+ use_gpu_memory_buffers_ = use_gpu_memory_buffers;
+}
+
+GLenum ResourceProvider::GetTargetGivenResource(Resource* resource) {
+ return resource->use_gpu_memory_buffer
+ ? GL_IMAGE_BUFFER_CHROMIUM
+ : GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM;
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698