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

gpu: Remove in-process GPU service support for CHROMIUM_image.

This also removes the android_webview GpuMemoryBuffer
implementation.

BUG=418553

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

Cr-Commit-Position: refs/heads/master@{#297224}
parent 6b2ce16b
...@@ -137,8 +137,6 @@ ...@@ -137,8 +137,6 @@
'browser/global_tile_manager.cc', 'browser/global_tile_manager.cc',
'browser/global_tile_manager.h', 'browser/global_tile_manager.h',
'browser/global_tile_manager_client.h', 'browser/global_tile_manager_client.h',
'browser/gpu_memory_buffer_factory_impl.cc',
'browser/gpu_memory_buffer_factory_impl.h',
'browser/hardware_renderer.cc', 'browser/hardware_renderer.cc',
'browser/hardware_renderer.h', 'browser/hardware_renderer.h',
'browser/icon_helper.cc', 'browser/icon_helper.cc',
......
...@@ -76,7 +76,7 @@ class TracedValue : public base::debug::ConvertableToTraceFormat { ...@@ -76,7 +76,7 @@ class TracedValue : public base::debug::ConvertableToTraceFormat {
} // namespace } // namespace
// static // static
void BrowserViewRenderer::CalculateTileMemoryPolicy(bool use_zero_copy) { void BrowserViewRenderer::CalculateTileMemoryPolicy() {
CommandLine* cl = CommandLine::ForCurrentProcess(); CommandLine* cl = CommandLine::ForCurrentProcess();
// If the value was overridden on the command line, use the specified value. // If the value was overridden on the command line, use the specified value.
...@@ -90,27 +90,12 @@ void BrowserViewRenderer::CalculateTileMemoryPolicy(bool use_zero_copy) { ...@@ -90,27 +90,12 @@ void BrowserViewRenderer::CalculateTileMemoryPolicy(bool use_zero_copy) {
g_memory_override_in_bytes *= 1024 * 1024; g_memory_override_in_bytes *= 1024 * 1024;
} }
if (!use_zero_copy) { // Use chrome's default tile size, which varies from 256 to 512.
// Use chrome's default tile size, which varies from 256 to 512. // Be conservative here and use the smallest tile size possible.
// Be conservative here and use the smallest tile size possible. g_tile_area = 256 * 256;
g_tile_area = 256 * 256;
// Also use a high tile limit since there are no file descriptor issues. // Also use a high tile limit since there are no file descriptor issues.
GlobalTileManager::GetInstance()->SetTileLimit(1000); GlobalTileManager::GetInstance()->SetTileLimit(1000);
return;
}
const char kDefaultTileSize[] = "384";
if (!cl->HasSwitch(switches::kDefaultTileWidth))
cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize);
if (!cl->HasSwitch(switches::kDefaultTileHeight))
cl->AppendSwitchASCII(switches::kDefaultTileHeight, kDefaultTileSize);
size_t tile_size;
base::StringToSizeT(kDefaultTileSize, &tile_size);
g_tile_area = tile_size * tile_size;
} }
BrowserViewRenderer::BrowserViewRenderer( BrowserViewRenderer::BrowserViewRenderer(
......
...@@ -60,7 +60,7 @@ class BrowserViewRendererJavaHelper { ...@@ -60,7 +60,7 @@ class BrowserViewRendererJavaHelper {
class BrowserViewRenderer : public content::SynchronousCompositorClient, class BrowserViewRenderer : public content::SynchronousCompositorClient,
public GlobalTileManagerClient { public GlobalTileManagerClient {
public: public:
static void CalculateTileMemoryPolicy(bool use_zero_copy); static void CalculateTileMemoryPolicy();
BrowserViewRenderer( BrowserViewRenderer(
BrowserViewRendererClient* client, BrowserViewRendererClient* client,
......
// Copyright 2013 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 "android_webview/browser/gpu_memory_buffer_factory_impl.h"
#include "android_webview/public/browser/draw_gl.h"
#include "base/logging.h"
#include "gpu/command_buffer/service/in_process_command_buffer.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/size.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_android_native_buffer.h"
namespace android_webview {
namespace {
// Provides hardware rendering functions from the Android glue layer.
AwDrawGLFunctionTable* g_gl_draw_functions = NULL;
class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
public:
GpuMemoryBufferImpl(long buffer_id, const gfx::Size& size)
: buffer_id_(buffer_id), size_(size), mapped_(false) {
DCHECK(buffer_id_);
}
virtual ~GpuMemoryBufferImpl() {
g_gl_draw_functions->release_graphic_buffer(buffer_id_);
}
// Overridden from gfx::GpuMemoryBuffer:
virtual void* Map() OVERRIDE {
void* vaddr = NULL;
int err = g_gl_draw_functions->map(buffer_id_, MAP_READ_WRITE, &vaddr);
DCHECK(!err);
mapped_ = true;
return vaddr;
}
virtual void Unmap() OVERRIDE {
int err = g_gl_draw_functions->unmap(buffer_id_);
DCHECK(!err);
mapped_ = false;
}
virtual bool IsMapped() const OVERRIDE { return mapped_; }
virtual uint32 GetStride() const OVERRIDE {
return g_gl_draw_functions->get_stride(buffer_id_);
}
virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::ANDROID_NATIVE_BUFFER;
handle.buffer_id = buffer_id_;
return handle;
}
private:
long buffer_id_;
gfx::Size size_;
bool mapped_;
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
};
} // namespace
GpuMemoryBufferFactoryImpl::GpuMemoryBufferFactoryImpl() {
}
GpuMemoryBufferFactoryImpl::~GpuMemoryBufferFactoryImpl() {
}
scoped_ptr<gfx::GpuMemoryBuffer>
GpuMemoryBufferFactoryImpl::AllocateGpuMemoryBuffer(size_t width,
size_t height,
unsigned internalformat,
unsigned usage) {
// For Android WebView we assume the |internalformat| will always be
// GL_RGBA8_OES.
CHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
CHECK(g_gl_draw_functions);
long buffer_id = g_gl_draw_functions->create_graphic_buffer(width, height);
if (!buffer_id)
return scoped_ptr<gfx::GpuMemoryBuffer>();
return make_scoped_ptr(
new GpuMemoryBufferImpl(buffer_id, gfx::Size(width, height)))
.PassAs<gfx::GpuMemoryBuffer>();
}
scoped_refptr<gfx::GLImage>
GpuMemoryBufferFactoryImpl::CreateImageForGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat) {
DCHECK_EQ(gfx::ANDROID_NATIVE_BUFFER, handle.type);
EGLClientBuffer native_buffer =
g_gl_draw_functions->get_native_buffer(handle.buffer_id);
DCHECK(native_buffer);
scoped_refptr<gfx::GLImageAndroidNativeBuffer> image(
new gfx::GLImageAndroidNativeBuffer(size));
if (!image->Initialize(native_buffer))
return scoped_refptr<gfx::GLImage>();
return image;
}
// static
void GpuMemoryBufferFactoryImpl::SetAwDrawGLFunctionTable(
AwDrawGLFunctionTable* table) {
g_gl_draw_functions = table;
}
bool GpuMemoryBufferFactoryImpl::Initialize() {
if (!g_gl_draw_functions)
return false;
gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory(this);
return true;
}
} // namespace android_webview
// Copyright 2013 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 ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_
#define ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "gpu/command_buffer/service/in_process_command_buffer.h"
struct AwDrawGLFunctionTable;
namespace android_webview {
class GpuMemoryBufferFactoryImpl : public gpu::InProcessGpuMemoryBufferFactory {
public:
GpuMemoryBufferFactoryImpl();
virtual ~GpuMemoryBufferFactoryImpl();
static void SetAwDrawGLFunctionTable(AwDrawGLFunctionTable* table);
bool Initialize();
// Overridden from gpu::InProcessGpuMemoryBufferFactory:
virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
size_t width,
size_t height,
unsigned internalformat,
unsigned usage) OVERRIDE;
virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactoryImpl);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "android_webview/browser/aw_content_browser_client.h" #include "android_webview/browser/aw_content_browser_client.h"
#include "android_webview/browser/browser_view_renderer.h" #include "android_webview/browser/browser_view_renderer.h"
#include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
#include "android_webview/lib/aw_browser_dependency_factory_impl.h" #include "android_webview/lib/aw_browser_dependency_factory_impl.h"
#include "android_webview/native/aw_media_url_interceptor.h" #include "android_webview/native/aw_media_url_interceptor.h"
...@@ -40,8 +39,7 @@ base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > ...@@ -40,8 +39,7 @@ base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
} }
AwMainDelegate::AwMainDelegate() AwMainDelegate::AwMainDelegate() {
: gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
} }
AwMainDelegate::~AwMainDelegate() { AwMainDelegate::~AwMainDelegate() {
...@@ -50,23 +48,12 @@ AwMainDelegate::~AwMainDelegate() { ...@@ -50,23 +48,12 @@ AwMainDelegate::~AwMainDelegate() {
bool AwMainDelegate::BasicStartupComplete(int* exit_code) { bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
content::SetContentClient(&content_client_); content::SetContentClient(&content_client_);
CommandLine* cl = CommandLine::ForCurrentProcess();
bool zero_copy_disabled_by_switch = cl->HasSwitch(switches::kDisableZeroCopy);
bool use_zero_copy = !zero_copy_disabled_by_switch &&
cl->HasSwitch(switches::kEnableZeroCopy) &&
gpu_memory_buffer_factory_.get()->Initialize();
if (use_zero_copy) {
cl->AppendSwitch(switches::kEnableZeroCopy);
} else if (!zero_copy_disabled_by_switch) {
cl->AppendSwitch(switches::kDisableZeroCopy);
}
content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
new AwMediaUrlInterceptor()); new AwMediaUrlInterceptor());
BrowserViewRenderer::CalculateTileMemoryPolicy(use_zero_copy); BrowserViewRenderer::CalculateTileMemoryPolicy();
CommandLine* cl = CommandLine::ForCurrentProcess();
cl->AppendSwitch(switches::kEnableBeginFrameScheduling); cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
cl->AppendSwitch(switches::kEnableImplSidePainting); cl->AppendSwitch(switches::kEnableImplSidePainting);
......
...@@ -20,7 +20,6 @@ namespace android_webview { ...@@ -20,7 +20,6 @@ namespace android_webview {
class AwContentBrowserClient; class AwContentBrowserClient;
class AwContentRendererClient; class AwContentRendererClient;
class GpuMemoryBufferFactoryImpl;
// Android WebView implementation of ContentMainDelegate. // Android WebView implementation of ContentMainDelegate.
class AwMainDelegate : public content::ContentMainDelegate, class AwMainDelegate : public content::ContentMainDelegate,
...@@ -58,7 +57,6 @@ class AwMainDelegate : public content::ContentMainDelegate, ...@@ -58,7 +57,6 @@ class AwMainDelegate : public content::ContentMainDelegate,
AwContentClient content_client_; AwContentClient content_client_;
scoped_ptr<AwContentBrowserClient> content_browser_client_; scoped_ptr<AwContentBrowserClient> content_browser_client_;
scoped_ptr<AwContentRendererClient> content_renderer_client_; scoped_ptr<AwContentRendererClient> content_renderer_client_;
scoped_ptr<GpuMemoryBufferFactoryImpl> gpu_memory_buffer_factory_;
DISALLOW_COPY_AND_ASSIGN(AwMainDelegate); DISALLOW_COPY_AND_ASSIGN(AwMainDelegate);
}; };
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "android_webview/browser/aw_resource_context.h" #include "android_webview/browser/aw_resource_context.h"
#include "android_webview/browser/browser_view_renderer.h" #include "android_webview/browser/browser_view_renderer.h"
#include "android_webview/browser/deferred_gpu_command_service.h" #include "android_webview/browser/deferred_gpu_command_service.h"
#include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
#include "android_webview/browser/hardware_renderer.h" #include "android_webview/browser/hardware_renderer.h"
#include "android_webview/browser/net_disk_cache_remover.h" #include "android_webview/browser/net_disk_cache_remover.h"
#include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h" #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h"
...@@ -328,8 +327,6 @@ static void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, ...@@ -328,8 +327,6 @@ static void SetAwDrawSWFunctionTable(JNIEnv* env, jclass,
static void SetAwDrawGLFunctionTable(JNIEnv* env, jclass, static void SetAwDrawGLFunctionTable(JNIEnv* env, jclass,
jlong function_table) { jlong function_table) {
GpuMemoryBufferFactoryImpl::SetAwDrawGLFunctionTable(
reinterpret_cast<AwDrawGLFunctionTable*>(function_table));
} }
static jlong GetAwDrawGLFunction(JNIEnv* env, jclass) { static jlong GetAwDrawGLFunction(JNIEnv* env, jclass) {
......
...@@ -47,8 +47,6 @@ namespace gpu { ...@@ -47,8 +47,6 @@ namespace gpu {
namespace { namespace {
static InProcessGpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL;
template <typename T> template <typename T>
static void RunTaskWithResult(base::Callback<T(void)> task, static void RunTaskWithResult(base::Callback<T(void)> task,
T* result, T* result,
...@@ -305,11 +303,9 @@ bool InProcessCommandBuffer::Initialize( ...@@ -305,11 +303,9 @@ bool InProcessCommandBuffer::Initialize(
base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion)); base::Bind(&RunTaskWithResult<bool>, init_task, &result, &completion));
completion.Wait(); completion.Wait();
if (result) { if (result)
capabilities_ = capabilities; capabilities_ = capabilities;
capabilities_.map_image =
capabilities_.map_image && g_gpu_memory_buffer_factory;
}
return result; return result;
} }
...@@ -619,78 +615,12 @@ gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer( ...@@ -619,78 +615,12 @@ gfx::GpuMemoryBuffer* InProcessCommandBuffer::CreateGpuMemoryBuffer(
unsigned internalformat, unsigned internalformat,
unsigned usage, unsigned usage,
int32* id) { int32* id) {
CheckSequencedThread(); NOTREACHED();
return NULL;
*id = -1;
scoped_ptr<gfx::GpuMemoryBuffer> buffer =
g_gpu_memory_buffer_factory->AllocateGpuMemoryBuffer(
width, height, internalformat, usage);
if (!buffer.get())
return NULL;
static int32 next_id = 1;
int32 new_id = next_id++;
base::Closure task =
base::Bind(&InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread,
base::Unretained(this),
new_id,
buffer->GetHandle(),
width,
height,
internalformat);
QueueTask(task);
*id = new_id;
DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end());
return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second;
}
void InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread(
int32 id,
const gfx::GpuMemoryBufferHandle& handle,
size_t width,
size_t height,
unsigned internalformat) {
scoped_refptr<gfx::GLImage> image =
g_gpu_memory_buffer_factory->CreateImageForGpuMemoryBuffer(
handle, gfx::Size(width, height), internalformat);
if (!image.get())
return;
// For Android specific workaround.
gles2::ContextGroup* context_group = decoder_->GetContextGroup();
if (context_group->feature_info()->workarounds().release_image_after_use)
image->SetReleaseAfterUse();
if (decoder_) {
gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager();
DCHECK(image_manager);
image_manager->AddImage(image.get(), id);
}
} }
void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) { void InProcessCommandBuffer::DestroyGpuMemoryBuffer(int32 id) {
CheckSequencedThread(); NOTREACHED();
base::Closure task =
base::Bind(&InProcessCommandBuffer::UnregisterGpuMemoryBufferOnGpuThread,
base::Unretained(this),
id);
QueueTask(task);
gpu_memory_buffers_.erase(id);
}
void InProcessCommandBuffer::UnregisterGpuMemoryBufferOnGpuThread(int32 id) {
if (decoder_) {
gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager();
DCHECK(image_manager);
image_manager->RemoveImage(id);
}
} }
uint32 InProcessCommandBuffer::InsertSyncPoint() { uint32 InProcessCommandBuffer::InsertSyncPoint() {
...@@ -849,10 +779,4 @@ InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { ...@@ -849,10 +779,4 @@ InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) {
} }
#endif #endif
// static
void InProcessCommandBuffer::SetGpuMemoryBufferFactory(
InProcessGpuMemoryBufferFactory* factory) {
g_gpu_memory_buffer_factory = factory;
}
} // namespace gpu } // namespace gpu
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "gpu/command_buffer/client/gpu_control.h" #include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/gpu_export.h" #include "gpu/gpu_export.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/gpu_preference.h" #include "ui/gl/gpu_preference.h"
...@@ -56,26 +55,6 @@ class CommandBufferServiceBase; ...@@ -56,26 +55,6 @@ class CommandBufferServiceBase;
class GpuScheduler; class GpuScheduler;
class TransferBufferManagerInterface; class TransferBufferManagerInterface;
// TODO(reveman): Remove this interface when InProcessCommandBuffer doesn't need
// a custom factory interface and android_webview implementation of GPU memory
// buffers can use the same mechanism for buffer allocation as what's used for
// out of process GPU service.
class GPU_EXPORT InProcessGpuMemoryBufferFactory {
public:
virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
size_t width,
size_t height,
unsigned internalformat,
unsigned usage) = 0;
virtual scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
const gfx::GpuMemoryBufferHandle& handle,
const gfx::Size& size,
unsigned internalformat) = 0;
protected:
virtual ~InProcessGpuMemoryBufferFactory() {}
};
// This class provides a thread-safe interface to the global GPU service (for // This class provides a thread-safe interface to the global GPU service (for
// example GPU thread) when being run in single process mode. // example GPU thread) when being run in single process mode.
// However, the behavior for accessing one context (i.e. one instance of this // However, the behavior for accessing one context (i.e. one instance of this
...@@ -87,9 +66,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -87,9 +66,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
explicit InProcessCommandBuffer(const scoped_refptr<Service>& service); explicit InProcessCommandBuffer(const scoped_refptr<Service>& service);
virtual ~InProcessCommandBuffer(); virtual ~InProcessCommandBuffer();
static void SetGpuMemoryBufferFactory(
InProcessGpuMemoryBufferFactory* factory);
// If |surface| is not NULL, use it directly; in this case, the command // If |surface| is not NULL, use it directly; in this case, the command
// buffer gpu thread must be the same as the client thread. Otherwise create // buffer gpu thread must be the same as the client thread. Otherwise create
// a new GLSurface. // a new GLSurface.
...@@ -206,13 +182,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -206,13 +182,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
const base::Closure& callback); const base::Closure& callback);
void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback); void SignalQueryOnGpuThread(unsigned query_id, const base::Closure& callback);
void DestroyTransferBufferOnGpuThread(int32 id); void DestroyTransferBufferOnGpuThread(int32 id);
void RegisterGpuMemoryBufferOnGpuThread(
int32 id,
const gfx::GpuMemoryBufferHandle& handle,
size_t width,
size_t height,
unsigned internalformat);
void UnregisterGpuMemoryBufferOnGpuThread(int32 id);
// Callbacks: // Callbacks:
void OnContextLost(); void OnContextLost();
...@@ -238,9 +207,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, ...@@ -238,9 +207,6 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer,
State last_state_; State last_state_;
int32 last_put_offset_; int32 last_put_offset_;
gpu::Capabilities capabilities_; gpu::Capabilities capabilities_;
typedef base::ScopedPtrHashMap<int32, gfx::GpuMemoryBuffer>
GpuMemoryBufferMap;
GpuMemoryBufferMap gpu_memory_buffers_;
// Accessed on both threads: // Accessed on both threads:
scoped_ptr<CommandBufferServiceBase> command_buffer_; scoped_ptr<CommandBufferServiceBase> command_buffer_;
......
...@@ -220,8 +220,6 @@ component("gl") { ...@@ -220,8 +220,6 @@ component("gl") {
sources += [ sources += [
"gl_egl_api_implementation.cc", "gl_egl_api_implementation.cc",
"gl_egl_api_implementation.h", "gl_egl_api_implementation.h",
"gl_image_android_native_buffer.cc",
"gl_image_android_native_buffer.h",
"gl_image_surface_texture.cc", "gl_image_surface_texture.cc",
"gl_image_surface_texture.h", "gl_image_surface_texture.h",
] ]
......
...@@ -278,8 +278,6 @@ ...@@ -278,8 +278,6 @@
'gl_jni_headers', 'gl_jni_headers',
], ],
'sources': [ 'sources': [
'gl_image_android_native_buffer.cc',
'gl_image_android_native_buffer.h',
'gl_image_surface_texture.cc', 'gl_image_surface_texture.cc',
'gl_image_surface_texture.h', 'gl_image_surface_texture.h',
], ],
......
// Copyright 2014 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 "ui/gl/gl_image_android_native_buffer.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/scoped_binders.h"
namespace gfx {
GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size)
: GLImageEGL(size),
release_after_use_(false),
in_use_(false),
target_(0),
egl_image_for_unbind_(EGL_NO_IMAGE_KHR),
texture_id_for_unbind_(0) {
}
GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() {
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
DCHECK_EQ(0u, texture_id_for_unbind_);
}
bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) {
EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
return GLImageEGL::Initialize(
EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs);
}
void GLImageAndroidNativeBuffer::Destroy(bool have_context) {
if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) {
eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
egl_image_for_unbind_);
egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
}
if (texture_id_for_unbind_) {
if (have_context)
glDeleteTextures(1, &texture_id_for_unbind_);
texture_id_for_unbind_ = 0u;
}
GLImageEGL::Destroy(have_context);
}
bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) {
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
if (target == GL_TEXTURE_RECTANGLE_ARB) {
LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target";
return false;
}
if (target_ && target_ != target) {
LOG(ERROR) << "EGLImage can only be bound to one target";
return false;
}
target_ = target;
// Defer ImageTargetTexture2D if not currently in use.
if (!in_use_)
return true;
glEGLImageTargetTexture2DOES(target_, egl_image_);
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
return true;
}
void GLImageAndroidNativeBuffer::WillUseTexImage() {
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
DCHECK(!in_use_);
in_use_ = true;
glEGLImageTargetTexture2DOES(target_, egl_image_);
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
void GLImageAndroidNativeBuffer::DidUseTexImage() {
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
DCHECK(in_use_);
in_use_ = false;
if (!release_after_use_)
return;
if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) {
DCHECK_EQ(0u, texture_id_for_unbind_);
glGenTextures(1, &texture_id_for_unbind_);
{
ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_for_unbind_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
char zero[4] = {0, };
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero);
}
EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
// Need to pass current EGL rendering context to eglCreateImageKHR for
// target type EGL_GL_TEXTURE_2D_KHR.
egl_image_for_unbind_ = eglCreateImageKHR(
GLSurfaceEGL::GetHardwareDisplay(),
eglGetCurrentContext(),
EGL_GL_TEXTURE_2D_KHR,
reinterpret_cast<EGLClientBuffer>(texture_id_for_unbind_),
attrs);
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_for_unbind_)
<< "Error creating EGLImage: " << eglGetError();
}
glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
bool GLImageAndroidNativeBuffer::ScheduleOverlayPlane(
gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
const RectF& crop_rect) {
return false;
}
void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
release_after_use_ = true;
}
} // namespace gfx
// Copyright 2014 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 UI_GL_GL_IMAGE_ANDROID_NATIVE_BUFFER_H_
#define UI_GL_GL_IMAGE_ANDROID_NATIVE_BUFFER_H_
#include "ui/gl/gl_image_egl.h"
namespace gfx {
class GL_EXPORT GLImageAndroidNativeBuffer : public GLImageEGL {
public:
explicit GLImageAndroidNativeBuffer(const gfx::Size& size);
bool Initialize(EGLClientBuffer native_buffer);
// Overridden from GLImage:
virtual void Destroy(bool have_context) OVERRIDE;
virtual bool BindTexImage(unsigned target) OVERRIDE;
virtual void WillUseTexImage() OVERRIDE;
virtual void DidUseTexImage() OVERRIDE;
virtual void SetReleaseAfterUse() OVERRIDE;
virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
const RectF& crop_rect) OVERRIDE;
protected:
virtual ~GLImageAndroidNativeBuffer();
private:
bool release_after_use_;
bool in_use_;
unsigned target_;
EGLImageKHR egl_image_for_unbind_;
GLuint texture_id_for_unbind_;
DISALLOW_COPY_AND_ASSIGN(GLImageAndroidNativeBuffer);
};
} // namespace gfx
#endif // UI_GL_GL_IMAGE_ANDROID_NATIVE_BUFFER_H_
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