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

Unified Diff: webkit/common/gpu/webgraphicscontext3d_impl.cc

Issue 305643004: Reducing code duplication between WGC3D(InProcess)CommandBufferImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added WEBKIT_GPU_EXPORT Created 6 years, 7 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: webkit/common/gpu/webgraphicscontext3d_impl.cc
diff --git a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc b/webkit/common/gpu/webgraphicscontext3d_impl.cc
similarity index 59%
copy from content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
copy to webkit/common/gpu/webgraphicscontext3d_impl.cc
index 3638ecfde7a4317558a8ad4872df6cd01d884fa4..a1da8230e105fdc0b9dfe44194033019828574d1 100644
--- a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
+++ b/webkit/common/gpu/webgraphicscontext3d_impl.cc
@@ -2,69 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
-
-#include "third_party/khronos/GLES2/gl2.h"
-#ifndef GL_GLEXT_PROTOTYPES
-#define GL_GLEXT_PROTOTYPES 1
-#endif
-#include "third_party/khronos/GLES2/gl2ext.h"
-
-#include <algorithm>
-#include <map>
+#include "webkit/common/gpu/webgraphicscontext3d_impl.h"
#include "base/atomicops.h"
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/metrics/field_trial.h"
-#include "base/metrics/histogram.h"
-#include "content/common/gpu/client/gpu_channel_host.h"
-#include "content/public/common/content_constants.h"
-#include "content/public/common/content_switches.h"
#include "gpu/GLES2/gl2extchromium.h"
-#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/client/gles2_lib.h"
-#include "gpu/command_buffer/client/gles2_trace_implementation.h"
-#include "gpu/command_buffer/client/transfer_buffer.h"
-#include "gpu/command_buffer/common/constants.h"
-#include "gpu/command_buffer/common/gpu_memory_allocation.h"
-#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
-#include "third_party/skia/include/core/SkTypes.h"
+
+#include "third_party/khronos/GLES2/gl2.h"
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES 1
+#endif
+#include "third_party/khronos/GLES2/gl2ext.h"
namespace content {
namespace {
-static base::LazyInstance<base::Lock>::Leaky
- g_default_share_groups_lock = LAZY_INSTANCE_INITIALIZER;
-
-typedef std::map<GpuChannelHost*,
- scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> >
- ShareGroupMap;
-static base::LazyInstance<ShareGroupMap> g_default_share_groups =
- LAZY_INSTANCE_INITIALIZER;
-
-scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>
- GetDefaultShareGroupForHost(GpuChannelHost* host) {
- base::AutoLock lock(g_default_share_groups_lock.Get());
-
- ShareGroupMap& share_groups = g_default_share_groups.Get();
- ShareGroupMap::iterator it = share_groups.find(host);
- if (it == share_groups.end()) {
- scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> group =
- new WebGraphicsContext3DCommandBufferImpl::ShareGroup();
- share_groups[host] = group;
- return group;
- }
- return it->second;
-}
-
uint32_t GenFlushID() {
static base::subtle::Atomic32 flush_id = 0;
@@ -73,501 +30,173 @@ uint32_t GenFlushID() {
return static_cast<uint32_t>(my_id);
}
-// Singleton used to initialize and terminate the gles2 library.
-class GLES2Initializer {
+} // namespace anonymous
+
+class WebGraphicsContext3DErrorMessageCallback
+ : public gpu::gles2::GLES2ImplementationErrorMessageCallback {
public:
- GLES2Initializer() {
- gles2::Initialize();
+ WebGraphicsContext3DErrorMessageCallback(
+ WebGraphicsContext3DImpl* context)
+ : graphics_context_(context) {
}
- ~GLES2Initializer() {
- gles2::Terminate();
- }
+ virtual void OnErrorMessage(const char* msg, int id) OVERRIDE;
private:
- DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
-base::LazyInstance<GLES2Initializer> g_gles2_initializer =
- LAZY_INSTANCE_INITIALIZER;
+ WebGraphicsContext3DImpl* graphics_context_;
-////////////////////////////////////////////////////////////////////////////////
+ DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
+};
-} // namespace anonymous
+void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
+ const char* msg, int id) {
+ graphics_context_->OnErrorMessage(msg, id);
+}
// Helper macros to reduce the amount of code.
#define DELEGATE_TO_GL(name, glname) \
-void WebGraphicsContext3DCommandBufferImpl::name() { \
+void WebGraphicsContext3DImpl::name() { \
gl_->glname(); \
}
#define DELEGATE_TO_GL_R(name, glname, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name() { \
+rt WebGraphicsContext3DImpl::name() { \
return gl_->glname(); \
}
#define DELEGATE_TO_GL_1(name, glname, t1) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+void WebGraphicsContext3DImpl::name(t1 a1) { \
gl_->glname(a1); \
}
#define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+rt WebGraphicsContext3DImpl::name(t1 a1) { \
return gl_->glname(a1); \
}
#define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+rt WebGraphicsContext3DImpl::name(t1 a1) { \
return gl_->glname(a1) ? true : false; \
}
#define DELEGATE_TO_GL_2(name, glname, t1, t2) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
gl_->glname(a1, a2); \
}
#define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
+rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
return gl_->glname(a1, a2); \
}
#define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
gl_->glname(a1, a2, a3); \
}
#define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
+rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
return gl_->glname(a1, a2, a3); \
}
#define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
gl_->glname(a1, a2, a3, a4); \
}
#define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4) { \
+rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
return gl_->glname(a1, a2, a3, a4); \
}
#define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4, t5 a5) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {\
+ \
gl_->glname(a1, a2, a3, a4, a5); \
}
#define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4, t5 a5, t6 a6) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
+ t6 a6) { \
gl_->glname(a1, a2, a3, a4, a5, a6); \
}
#define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4, t5 a5, t6 a6, \
- t7 a7) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
+ t6 a6, t7 a7) { \
gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
}
#define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4, t5 a5, t6 a6, \
- t7 a7, t8 a8) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
+ t6 a6, t7 a7, t8 a8) { \
gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
}
#define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
- t4 a4, t5 a5, t6 a6, \
- t7 a7, t8 a8, t9 a9) { \
+void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
+ t6 a6, t7 a7, t8 a8, t9 a9) { \
gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
}
-class WebGraphicsContext3DErrorMessageCallback
- : public gpu::gles2::GLES2Implementation::ErrorMessageCallback {
- public:
- WebGraphicsContext3DErrorMessageCallback(
- WebGraphicsContext3DCommandBufferImpl* context)
- : graphics_context_(context) {
- }
-
- virtual void OnErrorMessage(const char* msg, int id) OVERRIDE;
-
- private:
- WebGraphicsContext3DCommandBufferImpl* graphics_context_;
-
- DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
-};
-
-void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
- const char* msg, int id) {
- graphics_context_->OnErrorMessage(msg, id);
+#define DELEGATE_TO_GL_9R(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
+ t9, rt) \
+rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
+ t6 a6, t7 a7, t8 a8, t9 a9) { \
+ return gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
}
-WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits::SharedMemoryLimits()
- : command_buffer_size(kDefaultCommandBufferSize),
- start_transfer_buffer_size(kDefaultStartTransferBufferSize),
- min_transfer_buffer_size(kDefaultMinTransferBufferSize),
- max_transfer_buffer_size(kDefaultMaxTransferBufferSize),
- mapped_memory_reclaim_limit(gpu::gles2::GLES2Implementation::kNoLimit) {}
-
-WebGraphicsContext3DCommandBufferImpl::ShareGroup::ShareGroup() {
-}
-
-WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() {
- DCHECK(contexts_.empty());
-}
-
-WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
- int surface_id,
- const GURL& active_url,
- GpuChannelHost* host,
- const Attributes& attributes,
- bool lose_context_when_out_of_memory,
- const SharedMemoryLimits& limits,
- WebGraphicsContext3DCommandBufferImpl* share_context)
- : initialize_failed_(false),
- visible_(false),
- host_(host),
- surface_id_(surface_id),
- active_url_(active_url),
+WebGraphicsContext3DImpl::WebGraphicsContext3DImpl(
+ const Attributes& attributes,
+ bool lose_context_when_out_of_memory)
+ : initialized_(false),
+ initialize_failed_(false),
context_lost_callback_(0),
context_lost_reason_(GL_NO_ERROR),
error_message_callback_(0),
attributes_(attributes),
- gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu
- : gfx::PreferIntegratedGpu),
- weak_ptr_factory_(this),
- initialized_(false),
gl_(NULL),
lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
- mem_limits_(limits),
flush_id_(0) {
- if (share_context) {
- DCHECK(!attributes_.shareResources);
- share_group_ = share_context->share_group_;
- } else {
- share_group_ = attributes_.shareResources
- ? GetDefaultShareGroupForHost(host)
- : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>(
- new ShareGroup());
- }
-}
-
-WebGraphicsContext3DCommandBufferImpl::
- ~WebGraphicsContext3DCommandBufferImpl() {
- if (real_gl_) {
- real_gl_->SetErrorMessageCallback(NULL);
- }
-
- Destroy();
-}
-
-bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
- if (initialized_)
- return true;
-
- if (initialize_failed_)
- return false;
-
- TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL");
-
- if (!CreateContext(surface_id_ != 0)) {
- Destroy();
- initialize_failed_ = true;
- return false;
- }
-
- // TODO(twiz): This code is too fragile in that it assumes that only WebGL
- // contexts will request noExtensions.
- if (gl_ && attributes_.noExtensions)
- gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
-
- command_buffer_->SetChannelErrorCallback(
- base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost,
- weak_ptr_factory_.GetWeakPtr()));
-
- command_buffer_->SetOnConsoleMessageCallback(
- base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage,
- weak_ptr_factory_.GetWeakPtr()));
-
- client_error_message_callback_.reset(
- new WebGraphicsContext3DErrorMessageCallback(this));
- real_gl_->SetErrorMessageCallback(client_error_message_callback_.get());
-
- // Set attributes_ from created offscreen context.
- {
- static const int pcount = 4;
- static const GLenum pnames[pcount] = {
- GL_ALPHA_BITS,
- GL_DEPTH_BITS,
- GL_STENCIL_BITS,
- GL_SAMPLE_BUFFERS,
- };
- GLint pvalues[pcount] = { 0, 0, 0, 0 };
-
- gl_->GetMultipleIntegervCHROMIUM(pnames, pcount,
- pvalues, sizeof(pvalues));
-
- attributes_.alpha = pvalues[0] > 0;
- attributes_.depth = pvalues[1] > 0;
- attributes_.stencil = pvalues[2] > 0;
- attributes_.antialias = pvalues[3] > 0;
- }
-
- visible_ = true;
- initialized_ = true;
- return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
- bool onscreen, WebGraphicsContext3DCommandBufferImpl* share_context) {
- if (!host_.get())
- return false;
-
- CommandBufferProxyImpl* share_group_command_buffer = NULL;
-
- if (share_context) {
- share_group_command_buffer = share_context->command_buffer_.get();
- }
-
- std::vector<int32> attribs;
- attribs.push_back(ALPHA_SIZE);
- attribs.push_back(attributes_.alpha ? 8 : 0);
- attribs.push_back(DEPTH_SIZE);
- attribs.push_back(attributes_.depth ? 24 : 0);
- attribs.push_back(STENCIL_SIZE);
- attribs.push_back(attributes_.stencil ? 8 : 0);
- attribs.push_back(SAMPLES);
- attribs.push_back(attributes_.antialias ? 4 : 0);
- attribs.push_back(SAMPLE_BUFFERS);
- attribs.push_back(attributes_.antialias ? 1 : 0);
- attribs.push_back(FAIL_IF_MAJOR_PERF_CAVEAT);
- attribs.push_back(attributes_.failIfMajorPerformanceCaveat ? 1 : 0);
- attribs.push_back(LOSE_CONTEXT_WHEN_OUT_OF_MEMORY);
- attribs.push_back(lose_context_when_out_of_memory_ ? 1 : 0);
- attribs.push_back(BIND_GENERATES_RESOURCES);
- attribs.push_back(0);
- attribs.push_back(NONE);
-
- // Create a proxy to a command buffer in the GPU process.
- if (onscreen) {
- command_buffer_.reset(host_->CreateViewCommandBuffer(
- surface_id_,
- share_group_command_buffer,
- attribs,
- active_url_,
- gpu_preference_));
- } else {
- command_buffer_.reset(host_->CreateOffscreenCommandBuffer(
- gfx::Size(1, 1),
- share_group_command_buffer,
- attribs,
- active_url_,
- gpu_preference_));
- }
-
- if (!command_buffer_) {
- DLOG(ERROR) << "GpuChannelHost failed to create command buffer.";
- return false;
- }
+WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() {
- DVLOG_IF(1, gpu::error::IsError(command_buffer_->GetLastError()))
- << "Context dead on arrival. Last error: "
- << command_buffer_->GetLastError();
- // Initialize the command buffer.
- bool result = command_buffer_->Initialize();
- LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed.";
- return result;
}
-bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) {
- // Ensure the gles2 library is initialized first in a thread safe way.
- g_gles2_initializer.Get();
-
- scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group;
-
- scoped_ptr<base::AutoLock> share_group_lock;
- bool add_to_share_group = false;
- if (!command_buffer_) {
- WebGraphicsContext3DCommandBufferImpl* share_context = NULL;
-
- share_group_lock.reset(new base::AutoLock(share_group_->lock()));
- share_context = share_group_->GetAnyContextLocked();
-
- if (!InitializeCommandBuffer(onscreen, share_context)) {
- LOG(ERROR) << "Failed to initialize command buffer.";
- return false;
- }
-
- if (share_context)
- gles2_share_group = share_context->GetImplementation()->share_group();
-
- add_to_share_group = true;
- }
-
- // Create the GLES2 helper, which writes the command buffer protocol.
- gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
- if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) {
- LOG(ERROR) << "Failed to initialize GLES2CmdHelper.";
- return false;
- }
-
- if (attributes_.noAutomaticFlushes)
- gles2_helper_->SetAutomaticFlushes(false);
- // Create a transfer buffer used to copy resources between the renderer
- // process and the GPU process.
- transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get()));
-
- DCHECK(host_.get());
-
- // Create the object exposing the OpenGL API.
- bool bind_generates_resources = false;
- real_gl_.reset(
- new gpu::gles2::GLES2Implementation(gles2_helper_.get(),
- gles2_share_group,
- transfer_buffer_.get(),
- bind_generates_resources,
- lose_context_when_out_of_memory_,
- command_buffer_.get()));
- gl_ = real_gl_.get();
-
- if (!real_gl_->Initialize(
- mem_limits_.start_transfer_buffer_size,
- mem_limits_.min_transfer_buffer_size,
- mem_limits_.max_transfer_buffer_size,
- mem_limits_.mapped_memory_reclaim_limit)) {
- LOG(ERROR) << "Failed to initialize GLES2Implementation.";
- return false;
- }
-
- if (add_to_share_group)
- share_group_->AddContextLocked(this);
-
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableGpuClientTracing)) {
- trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(gl_));
- gl_ = trace_gl_.get();
- }
- return true;
-}
-
-bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
- if (!MaybeInitializeGL()) {
- DLOG(ERROR) << "Failed to initialize context.";
- return false;
- }
- gles2::SetGLContext(gl_);
- if (gpu::error::IsError(command_buffer_->GetLastError())) {
- LOG(ERROR) << "Context dead on arrival. Last error: "
- << command_buffer_->GetLastError();
- return false;
+void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) {
+ if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
+ synthetic_errors_.end()) {
+ synthetic_errors_.push_back(error);
}
-
- return true;
}
-uint32_t WebGraphicsContext3DCommandBufferImpl::lastFlushID() {
+uint32_t WebGraphicsContext3DImpl::lastFlushID() {
return flush_id_;
}
DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
-void WebGraphicsContext3DCommandBufferImpl::Destroy() {
- share_group_->RemoveContext(this);
-
- if (gl_) {
- // First flush the context to ensure that any pending frees of resources
- // are completed. Otherwise, if this context is part of a share group,
- // those resources might leak. Also, any remaining side effects of commands
- // issued on this context might not be visible to other contexts in the
- // share group.
- gl_->Flush();
- gl_ = NULL;
- }
-
- trace_gl_.reset();
- real_gl_.reset();
- transfer_buffer_.reset();
- gles2_helper_.reset();
- real_gl_.reset();
-
- if (command_buffer_) {
- if (host_.get())
- host_->DestroyCommandBuffer(command_buffer_.release());
- command_buffer_.reset();
- }
-
- host_ = NULL;
-}
-
-gpu::ContextSupport*
-WebGraphicsContext3DCommandBufferImpl::GetContextSupport() {
- return real_gl_.get();
-}
-
-void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
- NOTREACHED();
-}
-
-void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM(
- int x, int y, int width, int height) {
- NOTREACHED();
-}
-
DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
-void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
- WGC3Denum error) {
- if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
- synthetic_errors_.end()) {
- synthetic_errors_.push_back(error);
- }
-}
-
DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
const void*)
-void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM(
- WGC3Denum target,
- WGC3Dint level,
- WGC3Dint xoffset,
- WGC3Dint yoffset,
- WGC3Dsizei width,
- WGC3Dsizei height,
- WGC3Denum format,
- WGC3Denum type,
- WGC3Denum access) {
- return gl_->MapTexSubImage2DCHROMIUM(
- target, level, xoffset, yoffset, width, height, format, type, access);
-}
+DELEGATE_TO_GL_9R(mapTexSubImage2DCHROMIUM, MapTexSubImage2DCHROMIUM, WGC3Denum,
+ WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
+ WGC3Denum, WGC3Denum, WGC3Denum, void*)
DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
const void*)
-void WebGraphicsContext3DCommandBufferImpl::setVisibilityCHROMIUM(
- bool visible) {
- NOTREACHED();
-}
-
DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
WGC3Dsizei, const WGC3Denum*)
-void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
- WebGLId texture, WebGLId parentTexture) {
- NOTIMPLEMENTED();
-}
-
-blink::WebString WebGraphicsContext3DCommandBufferImpl::
+blink::WebString WebGraphicsContext3DImpl::
getRequestableExtensionsCHROMIUM() {
return blink::WebString::fromUTF8(
gl_->GetRequestableExtensionsCHROMIUM());
@@ -576,7 +205,7 @@ blink::WebString WebGraphicsContext3DCommandBufferImpl::
DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
const char*)
-void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM(
+void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM(
WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
WGC3Dbitfield mask, WGC3Denum filter) {
@@ -674,7 +303,7 @@ DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
-void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode,
+void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
WGC3Dintptr offset) {
@@ -688,12 +317,12 @@ DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
WGC3Duint)
-void WebGraphicsContext3DCommandBufferImpl::finish() {
+void WebGraphicsContext3DImpl::finish() {
flush_id_ = GenFlushID();
gl_->Finish();
}
-void WebGraphicsContext3DCommandBufferImpl::flush() {
+void WebGraphicsContext3DImpl::flush() {
flush_id_ = GenFlushID();
gl_->Flush();
}
@@ -708,7 +337,7 @@ DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
-bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
+bool WebGraphicsContext3DImpl::getActiveAttrib(
WebGLId program, WGC3Duint index, ActiveInfo& info) {
if (!program) {
synthesizeGLError(GL_INVALID_VALUE);
@@ -738,7 +367,7 @@ bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform(
+bool WebGraphicsContext3DImpl::getActiveUniform(
WebGLId program, WGC3Duint index, ActiveInfo& info) {
GLint max_name_length = -1;
gl_->GetProgramiv(
@@ -776,11 +405,11 @@ DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
WGC3Denum, WGC3Denum, WGC3Dint*)
blink::WebGraphicsContext3D::Attributes
-WebGraphicsContext3DCommandBufferImpl::getContextAttributes() {
+WebGraphicsContext3DImpl::getContextAttributes() {
return attributes_;
}
-WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
+WGC3Denum WebGraphicsContext3DImpl::getError() {
if (!synthetic_errors_.empty()) {
std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
WGC3Denum err = *iter;
@@ -791,12 +420,6 @@ WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
return gl_->GetError();
}
-bool WebGraphicsContext3DCommandBufferImpl::isContextLost() {
- return initialize_failed_ ||
- (command_buffer_ && IsCommandBufferContextLost()) ||
- context_lost_reason_ != GL_NO_ERROR;
-}
-
DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
@@ -807,7 +430,7 @@ DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
-blink::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog(
+blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
WebGLId program) {
GLint logLength = 0;
gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
@@ -830,7 +453,7 @@ DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
-blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
+blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
@@ -851,7 +474,7 @@ blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
-blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
+blink::WebString WebGraphicsContext3DImpl::getShaderSource(
WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
@@ -871,7 +494,7 @@ blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
return res;
}
-blink::WebString WebGraphicsContext3DCommandBufferImpl::
+blink::WebString WebGraphicsContext3DImpl::
getTranslatedShaderSourceANGLE(WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(
@@ -892,7 +515,7 @@ blink::WebString WebGraphicsContext3DCommandBufferImpl::
return res;
}
-blink::WebString WebGraphicsContext3DCommandBufferImpl::getString(
+blink::WebString WebGraphicsContext3DImpl::getString(
WGC3Denum name) {
return blink::WebString::fromUTF8(
reinterpret_cast<const char*>(gl_->GetString(name)));
@@ -917,7 +540,7 @@ DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
WGC3Duint, WGC3Denum, WGC3Dint*)
-WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset(
+WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
WGC3Duint index, WGC3Denum pname) {
GLvoid* value = NULL;
// NOTE: If pname is ever a value that returns more then 1 element
@@ -954,9 +577,6 @@ DELEGATE_TO_GL_7(readPixels, ReadPixels,
WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
WGC3Denum, void*)
-void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() {
-}
-
DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
@@ -964,7 +584,7 @@ DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
-void WebGraphicsContext3DCommandBufferImpl::shaderSource(
+void WebGraphicsContext3DImpl::shaderSource(
WebGLId shader, const WGC3Dchar* string) {
GLint length = strlen(string);
gl_->ShaderSource(shader, 1, &string, &length);
@@ -995,7 +615,7 @@ DELEGATE_TO_GL_3(texParameterf, TexParameterf,
static const unsigned int kTextureWrapR = 0x8072;
-void WebGraphicsContext3DCommandBufferImpl::texParameteri(
+void WebGraphicsContext3DImpl::texParameteri(
WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
// TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
// GraphicsContext3D.cpp is strictly necessary to avoid seams at the
@@ -1086,7 +706,7 @@ DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
const WGC3Dfloat*)
-void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer(
+void WebGraphicsContext3DImpl::vertexAttribPointer(
WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
WGC3Dsizei stride, WGC3Dintptr offset) {
gl_->VertexAttribPointer(
@@ -1114,45 +734,45 @@ DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
-WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() {
+WebGLId WebGraphicsContext3DImpl::createBuffer() {
GLuint o;
gl_->GenBuffers(1, &o);
return o;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() {
+WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
GLuint o = 0;
gl_->GenFramebuffers(1, &o);
return o;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() {
+WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
GLuint o;
gl_->GenRenderbuffers(1, &o);
return o;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() {
+WebGLId WebGraphicsContext3DImpl::createTexture() {
GLuint o;
gl_->GenTextures(1, &o);
return o;
}
-void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) {
+void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
gl_->DeleteBuffers(1, &buffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer(
+void WebGraphicsContext3DImpl::deleteFramebuffer(
WebGLId framebuffer) {
gl_->DeleteFramebuffers(1, &framebuffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer(
+void WebGraphicsContext3DImpl::deleteRenderbuffer(
WebGLId renderbuffer) {
gl_->DeleteRenderbuffers(1, &renderbuffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) {
+void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
gl_->DeleteTextures(1, &texture);
}
@@ -1164,72 +784,29 @@ DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
-void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback(
+void WebGraphicsContext3DImpl::setErrorMessageCallback(
WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
error_message_callback_ = cb;
}
-void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback(
+void WebGraphicsContext3DImpl::setContextLostCallback(
WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
context_lost_callback_ = cb;
}
-WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() {
- if (IsCommandBufferContextLost() &&
- context_lost_reason_ == GL_NO_ERROR) {
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
- }
-
- return context_lost_reason_;
-}
-
-bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() {
- // If the channel shut down unexpectedly, let that supersede the
- // command buffer's state.
- if (host_.get() && host_->IsLost())
- return true;
- gpu::CommandBuffer::State state = command_buffer_->GetLastState();
- return state.error == gpu::error::kLostContext;
-}
-
-// static
-WebGraphicsContext3DCommandBufferImpl*
-WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
- GpuChannelHost* host,
- const WebGraphicsContext3D::Attributes& attributes,
- bool lose_context_when_out_of_memory,
- const GURL& active_url,
- const SharedMemoryLimits& limits,
- WebGraphicsContext3DCommandBufferImpl* share_context) {
- if (!host)
- return NULL;
-
- if (share_context && share_context->IsCommandBufferContextLost())
- return NULL;
-
- return new WebGraphicsContext3DCommandBufferImpl(
- 0,
- active_url,
- host,
- attributes,
- lose_context_when_out_of_memory,
- limits,
- share_context);
-}
-
DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
-WebGLId WebGraphicsContext3DCommandBufferImpl::createQueryEXT() {
+WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
GLuint o;
gl_->GenQueriesEXT(1, &o);
return o;
}
-void WebGraphicsContext3DCommandBufferImpl::deleteQueryEXT(
+void WebGraphicsContext3DImpl::deleteQueryEXT(
WebGLId query) {
gl_->DeleteQueriesEXT(1, &query);
}
@@ -1247,19 +824,19 @@ DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum,
DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
WebGLId, WGC3Dint, const WGC3Dchar*)
-void WebGraphicsContext3DCommandBufferImpl::shallowFlushCHROMIUM() {
+void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
flush_id_ = GenFlushID();
gl_->ShallowFlushCHROMIUM();
}
-void WebGraphicsContext3DCommandBufferImpl::shallowFinishCHROMIUM() {
+void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
flush_id_ = GenFlushID();
gl_->ShallowFinishCHROMIUM();
}
DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
-void WebGraphicsContext3DCommandBufferImpl::loseContextCHROMIUM(
+void WebGraphicsContext3DImpl::loseContextCHROMIUM(
WGC3Denum current, WGC3Denum other) {
gl_->LoseContextCHROMIUM(current, other);
gl_->Flush();
@@ -1271,25 +848,25 @@ DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
WGC3Denum, const WGC3Dbyte*)
-void WebGraphicsContext3DCommandBufferImpl::insertEventMarkerEXT(
+void WebGraphicsContext3DImpl::insertEventMarkerEXT(
const WGC3Dchar* marker) {
gl_->InsertEventMarkerEXT(0, marker);
}
-void WebGraphicsContext3DCommandBufferImpl::pushGroupMarkerEXT(
+void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
const WGC3Dchar* marker) {
gl_->PushGroupMarkerEXT(0, marker);
}
DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
-WebGLId WebGraphicsContext3DCommandBufferImpl::createVertexArrayOES() {
+WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
GLuint array;
gl_->GenVertexArraysOES(1, &array);
return array;
}
-void WebGraphicsContext3DCommandBufferImpl::deleteVertexArrayOES(
+void WebGraphicsContext3DImpl::deleteVertexArrayOES(
WebGLId array) {
gl_->DeleteVertexArraysOES(1, &array);
}
@@ -1322,7 +899,7 @@ DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
WGC3Dint, WGC3Dsizei, WGC3Dsizei)
-void WebGraphicsContext3DCommandBufferImpl::drawElementsInstancedANGLE(
+void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
@@ -1361,51 +938,49 @@ DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
WGC3Denum, WGC3Dsizei, WGC3Dsizei)
-GrGLInterface* WebGraphicsContext3DCommandBufferImpl::createGrGLInterface() {
+GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
makeContextCurrent();
return skia_bindings::CreateCommandBufferSkiaGLBinding();
}
-namespace {
+gpu::gles2::GLES2ImplementationErrorMessageCallback*
+ WebGraphicsContext3DImpl::getErrorMessageCallback() {
+ if (!client_error_message_callback_) {
+ client_error_message_callback_.reset(
+ new WebGraphicsContext3DErrorMessageCallback(this));
+ }
+ return client_error_message_callback_.get();
+}
-WGC3Denum convertReason(gpu::error::ContextLostReason reason) {
- switch (reason) {
- case gpu::error::kGuilty:
- return GL_GUILTY_CONTEXT_RESET_ARB;
- case gpu::error::kInnocent:
- return GL_INNOCENT_CONTEXT_RESET_ARB;
- case gpu::error::kUnknown:
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
+void WebGraphicsContext3DImpl::OnErrorMessage(
+ const std::string& message, int id) {
+ if (error_message_callback_) {
+ blink::WebString str = blink::WebString::fromUTF8(message.c_str());
+ error_message_callback_->onErrorMessage(str, id);
}
+}
+// TODO(bajones): Look into removing these functions from the blink interface
+void WebGraphicsContext3DImpl::prepareTexture() {
NOTREACHED();
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
}
-} // anonymous namespace
-
-void WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost() {
- context_lost_reason_ = convertReason(
- command_buffer_->GetLastState().context_lost_reason);
- if (context_lost_callback_) {
- context_lost_callback_->onContextLost();
- }
+void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
+ int x, int y, int width, int height) {
+ NOTREACHED();
+}
- share_group_->RemoveAllContexts();
+void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
+ bool visible) {
+ NOTREACHED();
+}
- DCHECK(host_.get());
- {
- base::AutoLock lock(g_default_share_groups_lock.Get());
- g_default_share_groups.Get().erase(host_.get());
- }
+void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
+ WebGLId texture, WebGLId parentTexture) {
+ NOTIMPLEMENTED();
}
-void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage(
- const std::string& message, int id) {
- if (error_message_callback_) {
- blink::WebString str = blink::WebString::fromUTF8(message.c_str());
- error_message_callback_->onErrorMessage(str, id);
- }
+void WebGraphicsContext3DImpl::releaseShaderCompiler() {
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698