Commit 9656d1f1 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

viz/mac: Fix InProcessGpuMemoryBufferManager client id

InProcessCommandBuffer::CreateImageOnGpuThread assumes that its client
id is zero, but InProcessGpuMemoryBufferManager uses the constant one.

Put the constant in a InProcessCommandBuffer to keep them the same.

Bug: 772576
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I18f48dff252af04a438e09382277f0a5c7208d44
Reviewed-on: https://chromium-review.googlesource.com/882442Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532271}
parent 087318f1
......@@ -5,6 +5,7 @@
#include "components/viz/service/display_embedder/in_process_gpu_memory_buffer_manager.h"
#include "gpu/ipc/client/gpu_memory_buffer_impl.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
......@@ -12,7 +13,9 @@ namespace viz {
InProcessGpuMemoryBufferManager::InProcessGpuMemoryBufferManager(
gpu::GpuChannelManager* channel_manager)
: client_id_(1), channel_manager_(channel_manager), weak_factory_(this) {
: client_id_(gpu::InProcessCommandBuffer::kGpuMemoryBufferClientId),
channel_manager_(channel_manager),
weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
}
......
......@@ -137,6 +137,8 @@ scoped_refptr<InProcessCommandBuffer::Service> GetInitialService(
} // anonyous namespace
const int InProcessCommandBuffer::kGpuMemoryBufferClientId = 1;
InProcessCommandBuffer::Service::Service(
const GpuPreferences& gpu_preferences,
MailboxManager* mailbox_manager,
......@@ -814,12 +816,9 @@ void InProcessCommandBuffer::CreateImageOnGpuThread(
return;
}
// Note: this assumes that client ID is always 0.
const int kClientId = 0;
scoped_refptr<gl::GLImage> image =
image_factory_->CreateImageForGpuMemoryBuffer(
handle, size, format, internalformat, kClientId,
handle, size, format, internalformat, kGpuMemoryBufferClientId,
kNullSurfaceHandle);
if (!image.get()) {
LOG(ERROR) << "Failed to create image for buffer.";
......
......@@ -215,6 +215,8 @@ class GL_IN_PROCESS_CONTEXT_EXPORT InProcessCommandBuffer
return decoder_->GetTransferCacheForTest();
}
static const int kGpuMemoryBufferClientId;
// The serializer interface to the GPU service (i.e. thread).
class Service {
public:
......
......@@ -14,6 +14,11 @@
namespace gpu {
namespace {
// A GpuMemoryBuffer with client_id = 0 behaves like anonymous shared memory.
const int kAnonymousClientId = 0;
} // namespace
GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
}
......@@ -32,11 +37,12 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
bool should_clear = (client_id != 0);
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
gfx::CreateIOSurface(size, format, should_clear));
if (!io_surface)
if (!io_surface) {
DLOG(ERROR) << "Failed to allocate IOSurface.";
return gfx::GpuMemoryBufferHandle();
}
// A GpuMemoryBuffer with client_id = 0 behaves like anonymous shared memory.
if (client_id != 0) {
if (client_id != kAnonymousClientId) {
base::AutoLock lock(io_surfaces_lock_);
IOSurfaceMapKey key(id, client_id);
......@@ -80,13 +86,17 @@ GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer(
DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER);
IOSurfaceMapKey key(handle.id, client_id);
IOSurfaceMap::iterator it = io_surfaces_.find(key);
if (it == io_surfaces_.end())
if (it == io_surfaces_.end()) {
DLOG(ERROR) << "Failed to find IOSurface based on key.";
return scoped_refptr<gl::GLImage>();
}
scoped_refptr<gl::GLImageIOSurface> image(
gl::GLImageIOSurface::Create(size, internalformat));
if (!image->Initialize(it->second.get(), handle.id, format))
if (!image->Initialize(it->second.get(), handle.id, format)) {
DLOG(ERROR) << "Failed to initialize GLImage for IOSurface.";
return scoped_refptr<gl::GLImage>();
}
return image;
}
......@@ -101,7 +111,7 @@ GpuMemoryBufferFactoryIOSurface::CreateAnonymousImage(const gfx::Size& size,
// directly exposed to other processes, only via a mailbox.
gfx::GpuMemoryBufferHandle handle = CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId(next_anonymous_image_id_++), size, format, usage,
0 /* client_id */, gpu::kNullSurfaceHandle);
kAnonymousClientId, gpu::kNullSurfaceHandle);
base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
io_surface.reset(IOSurfaceLookupFromMachPort(handle.mach_port.get()));
......@@ -109,8 +119,10 @@ GpuMemoryBufferFactoryIOSurface::CreateAnonymousImage(const gfx::Size& size,
scoped_refptr<gl::GLImageIOSurface> image(
gl::GLImageIOSurface::Create(size, internalformat));
if (!image->Initialize(io_surface.get(), handle.id, format))
if (!image->Initialize(io_surface.get(), handle.id, format)) {
DLOG(ERROR) << "Failed to initialize anonymous GLImage.";
return scoped_refptr<gl::GLImage>();
}
*is_cleared = false;
return image;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment