Commit a68c2628 authored by reveman's avatar reveman Committed by Commit bot

content: Remove use of GLImage from GpuMemoryBufferImpl.

GpuMemoryBuffer implementations should not depend on
GLImage. This moves the capabilities and size checks
needed for compressed formats to the ImageFactory
interface.

BUG=462541

Review URL: https://codereview.chromium.org/968283002

Cr-Commit-Position: refs/heads/master@{#318990}
parent e1c5537e
......@@ -139,6 +139,7 @@ void BrowserGpuMemoryBufferManager::AllocateGpuMemoryBufferForChildProcess(
format, usage)) {
// Early out if we cannot fallback to shared memory buffer.
if (!GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) ||
!GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(size, format) ||
usage != gfx::GpuMemoryBuffer::MAP) {
callback.Run(gfx::GpuMemoryBufferHandle());
return;
......
......@@ -371,6 +371,8 @@ int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer,
channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(),
&requires_sync_point);
DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
gfx::Size(width, height), gpu_memory_buffer->GetFormat()));
DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
internalformat, gpu_memory_buffer->GetFormat()));
if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_,
......
......@@ -8,7 +8,6 @@
#include "base/numerics/safe_math.h"
#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_memory.h"
#if defined(OS_MACOSX)
#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
......@@ -34,7 +33,6 @@ GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id,
callback_(callback),
mapped_(false),
destruction_sync_point_(0) {
DCHECK(gfx::GLImageMemory::ValidSize(size, format));
}
GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
......
......@@ -24,6 +24,8 @@ GpuMemoryBufferImplSharedMemory::GpuMemoryBufferImplSharedMemory(
scoped_ptr<base::SharedMemory> shared_memory)
: GpuMemoryBufferImpl(id, size, format, callback),
shared_memory_(shared_memory.Pass()) {
DCHECK(IsFormatSupported(format));
DCHECK(IsSizeValidForFormat(size, format));
}
GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {
......@@ -131,6 +133,29 @@ bool GpuMemoryBufferImplSharedMemory::IsFormatSupported(Format format) {
return false;
}
// static
bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(
const gfx::Size& size,
Format format) {
switch (format) {
case ATC:
case ATCIA:
case DXT1:
case DXT5:
case ETC1:
// Compressed images must have a width and height that's evenly divisible
// by the block size.
return size.width() % 4 == 0 && size.height() % 4 == 0;
case RGBA_8888:
case BGRA_8888:
case RGBX_8888:
return true;
}
NOTREACHED();
return false;
}
void* GpuMemoryBufferImplSharedMemory::Map() {
DCHECK(!mapped_);
mapped_ = true;
......
......@@ -31,6 +31,7 @@ class GpuMemoryBufferImplSharedMemory : public GpuMemoryBufferImpl {
const DestructionCallback& callback);
static bool IsFormatSupported(Format format);
static bool IsSizeValidForFormat(const gfx::Size& size, Format format);
// Overridden from gfx::GpuMemoryBuffer:
void* Map() override;
......
......@@ -27,6 +27,7 @@
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/service/gl_context_virtual.h"
#include "gpu/command_buffer/service/gl_state_restorer_impl.h"
#include "gpu/command_buffer/service/image_factory.h"
#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/logger.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
......@@ -140,29 +141,6 @@ DevToolsChannelData::CreateForChannel(GpuChannel* channel) {
return new DevToolsChannelData(res.release());
}
bool IsSupportedImageFormat(const gpu::Capabilities& capabilities,
gfx::GpuMemoryBuffer::Format format) {
switch (format) {
case gfx::GpuMemoryBuffer::ATC:
case gfx::GpuMemoryBuffer::ATCIA:
return capabilities.texture_format_atc;
case gfx::GpuMemoryBuffer::BGRA_8888:
return capabilities.texture_format_bgra8888;
case gfx::GpuMemoryBuffer::DXT1:
return capabilities.texture_format_dxt1;
case gfx::GpuMemoryBuffer::DXT5:
return capabilities.texture_format_dxt5;
case gfx::GpuMemoryBuffer::ETC1:
return capabilities.texture_format_etc1;
case gfx::GpuMemoryBuffer::RGBA_8888:
case gfx::GpuMemoryBuffer::RGBX_8888:
return true;
}
NOTREACHED();
return false;
}
} // namespace
GpuCommandBufferStub::GpuCommandBufferStub(
......@@ -979,8 +957,21 @@ void GpuCommandBufferStub::OnCreateImage(int32 id,
return;
}
if (!IsSupportedImageFormat(decoder_->GetCapabilities(), format)) {
LOG(ERROR) << "Image format is not supported.";
if (!gpu::ImageFactory::IsGpuMemoryBufferFormatSupported(
format, decoder_->GetCapabilities())) {
LOG(ERROR) << "Format is not supported.";
return;
}
if (!gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(size,
format)) {
LOG(ERROR) << "Invalid image size for format.";
return;
}
if (!gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
internalformat, format)) {
LOG(ERROR) << "Incompatible image format.";
return;
}
......
......@@ -4,6 +4,7 @@
#include "gpu/command_buffer/service/image_factory.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "ui/gl/gl_bindings.h"
namespace gpu {
......@@ -93,4 +94,52 @@ bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
}
}
// static
bool ImageFactory::IsGpuMemoryBufferFormatSupported(
gfx::GpuMemoryBuffer::Format format,
const gpu::Capabilities& capabilities) {
switch (format) {
case gfx::GpuMemoryBuffer::ATC:
case gfx::GpuMemoryBuffer::ATCIA:
return capabilities.texture_format_atc;
case gfx::GpuMemoryBuffer::BGRA_8888:
return capabilities.texture_format_bgra8888;
case gfx::GpuMemoryBuffer::DXT1:
return capabilities.texture_format_dxt1;
case gfx::GpuMemoryBuffer::DXT5:
return capabilities.texture_format_dxt5;
case gfx::GpuMemoryBuffer::ETC1:
return capabilities.texture_format_etc1;
case gfx::GpuMemoryBuffer::RGBA_8888:
case gfx::GpuMemoryBuffer::RGBX_8888:
return true;
}
NOTREACHED();
return false;
}
// static
bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format) {
switch (format) {
case gfx::GpuMemoryBuffer::ATC:
case gfx::GpuMemoryBuffer::ATCIA:
case gfx::GpuMemoryBuffer::DXT1:
case gfx::GpuMemoryBuffer::DXT5:
case gfx::GpuMemoryBuffer::ETC1:
// Compressed images must have a width and height that's evenly divisible
// by the block size.
return size.width() % 4 == 0 && size.height() % 4 == 0;
case gfx::GpuMemoryBuffer::RGBA_8888:
case gfx::GpuMemoryBuffer::BGRA_8888:
case gfx::GpuMemoryBuffer::RGBX_8888:
return true;
}
NOTREACHED();
return false;
}
} // namespace gpu
......@@ -15,6 +15,7 @@ class GLImage;
}
namespace gpu {
struct Capabilities;
class GPU_EXPORT ImageFactory {
public:
......@@ -35,6 +36,16 @@ class GPU_EXPORT ImageFactory {
unsigned internalformat,
gfx::GpuMemoryBuffer::Format format);
// Returns true if |format| is supported by |capabilities|.
static bool IsGpuMemoryBufferFormatSupported(
gfx::GpuMemoryBuffer::Format format,
const Capabilities& capabilities);
// Returns true if |size| is valid for |format|.
static bool IsImageSizeValidForGpuMemoryBufferFormat(
const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format);
// Creates a GLImage instance for GPU memory buffer identified by |handle|.
// |client_id| should be set to the client requesting the creation of instance
// and can be used by factory implementation to verify access rights.
......
......@@ -183,30 +183,6 @@ bool GLImageMemory::StrideInBytes(size_t width,
return false;
}
// static
bool GLImageMemory::ValidSize(const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format) {
switch (format) {
case gfx::GpuMemoryBuffer::ATC:
case gfx::GpuMemoryBuffer::ATCIA:
case gfx::GpuMemoryBuffer::DXT1:
case gfx::GpuMemoryBuffer::DXT5:
case gfx::GpuMemoryBuffer::ETC1:
// Compressed images must have a width and height that's evenly divisible
// by the block size.
return size.width() % 4 == 0 && size.height() % 4 == 0;
case gfx::GpuMemoryBuffer::RGBA_8888:
case gfx::GpuMemoryBuffer::BGRA_8888:
return true;
case gfx::GpuMemoryBuffer::RGBX_8888:
NOTREACHED();
return false;
}
NOTREACHED();
return false;
}
bool GLImageMemory::Initialize(const unsigned char* memory,
gfx::GpuMemoryBuffer::Format format) {
if (!ValidInternalFormat(internalformat_)) {
......@@ -221,6 +197,8 @@ bool GLImageMemory::Initialize(const unsigned char* memory,
DCHECK(memory);
DCHECK(!memory_);
DCHECK_IMPLIES(IsCompressedFormat(format), size_.width() % 4 == 0);
DCHECK_IMPLIES(IsCompressedFormat(format), size_.height() % 4 == 0);
memory_ = memory;
format_ = format;
return true;
......
......@@ -26,9 +26,6 @@ class GL_EXPORT GLImageMemory : public GLImage {
gfx::GpuMemoryBuffer::Format format,
size_t* stride_in_bytes);
static bool ValidSize(const gfx::Size& size,
gfx::GpuMemoryBuffer::Format format);
bool Initialize(const unsigned char* memory,
gfx::GpuMemoryBuffer::Format format);
......
......@@ -18,9 +18,6 @@ bool SizeInBytes(const gfx::Size& size,
if (size.IsEmpty())
return false;
if (!GLImageMemory::ValidSize(size, format))
return false;
size_t stride_in_bytes = 0;
if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes))
return false;
......
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