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

Unified Diff: content/renderer/gpu/webgraphicscontext3d_guest.cc

Issue 9609008: Implemented Browser Plugin (NOT FOR REVIEW) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merged with Tip-of-Tree Created 8 years, 9 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
« no previous file with comments | « content/renderer/gpu/webgraphicscontext3d_guest.h ('k') | content/renderer/guest_render_view_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/gpu/webgraphicscontext3d_guest.cc
diff --git a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc b/content/renderer/gpu/webgraphicscontext3d_guest.cc
similarity index 63%
copy from content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
copy to content/renderer/gpu/webgraphicscontext3d_guest.cc
index ea5f90d78151db78e0026a1ef679b03d66b1bf18..1a70e597df10b6ee90c19766e50ec9d044009c46 100644
--- a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc
+++ b/content/renderer/gpu/webgraphicscontext3d_guest.cc
@@ -2,13 +2,12 @@
// 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"
+#if defined(ENABLE_GPU)
-#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 "content/renderer/gpu/webgraphicscontext3d_guest.h"
+
+#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
+#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255
#include <algorithm>
#include <set>
@@ -22,205 +21,81 @@
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/synchronization/lock.h"
-#include "content/common/gpu/gpu_memory_allocation.h"
+#include "content/common/child_process.h"
#include "content/common/gpu/client/command_buffer_proxy.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "content/public/common/content_switches.h"
+#include "content/renderer/guest_to_host_channel.h"
+#include "content/renderer/render_thread_impl.h"
+#include "content/renderer/render_view_impl.h"
+#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
+#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/common/constants.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/glue/gl_bindings_skia_cmd_buffer.h"
-static base::LazyInstance<base::Lock>::Leaky
- g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER;
-static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
- g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER;
-
-namespace {
-
-void ClearSharedContexts() {
- base::AutoLock lock(g_all_shared_contexts_lock.Get());
- g_all_shared_contexts.Pointer()->clear();
-}
-
-} // namespace anonymous
-
-
-WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
- int surface_id,
- const GURL& active_url,
- const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client)
- : initialize_failed_(false),
- context_(NULL),
- gl_(NULL),
- host_(NULL),
- surface_id_(surface_id),
- active_url_(active_url),
- swap_client_(swap_client),
- memory_allocation_changed_callback_(0),
+WebGraphicsContext3DGuest::WebGraphicsContext3DGuest(
+ gpu::CommandBuffer* command_buffer,
+ GuestToHostChannel* channel,
+ WebKit::WebView* webview)
+ : channel_(channel),
+ initialize_failed_(false),
+ web_view_(webview),
context_lost_callback_(0),
context_lost_reason_(GL_NO_ERROR),
- error_message_callback_(0),
swapbuffers_complete_callback_(0),
- gpu_preference_(gfx::PreferIntegratedGpu),
cached_width_(0),
cached_height_(0),
+ dead_(false),
bound_fbo_(0),
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
-}
-
-WebGraphicsContext3DCommandBufferImpl::
- ~WebGraphicsContext3DCommandBufferImpl() {
- if (host_) {
- if (host_->WillGpuSwitchOccur(false, gpu_preference_)) {
- host_->ForciblyCloseChannel();
- ClearSharedContexts();
- }
- }
-
- {
- base::AutoLock lock(g_all_shared_contexts_lock.Get());
- g_all_shared_contexts.Pointer()->erase(this);
+ command_buffer_.reset(command_buffer);
+ if (!command_buffer_->Initialize()) {
+ initialize_failed_ = true;
+ return;
}
- delete context_;
}
-bool WebGraphicsContext3DCommandBufferImpl::Initialize(
- const WebGraphicsContext3D::Attributes& attributes) {
- DCHECK(!context_);
- TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize");
- GpuChannelHostFactory* factory = GpuChannelHostFactory::instance();
- if (!factory)
- return false;
-
- // The noExtensions and canRecoverFromContextLoss flags are
- // currently used as hints that we are creating a context on
- // behalf of WebGL or accelerated 2D canvas, respectively.
- if (attributes.noExtensions || !attributes.canRecoverFromContextLoss)
- gpu_preference_ = gfx::PreferDiscreteGpu;
-
- bool retry = false;
-
- // Note similar code in Pepper PlatformContext3DImpl::Init.
- do {
- host_ = factory->EstablishGpuChannelSync(
- content::
- CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE);
- if (!host_)
- return false;
- DCHECK(host_->state() == GpuChannelHost::kConnected);
-
- if (!retry) {
- // If the creation of this context requires all contexts for this
- // client to be destroyed on the GPU process side, then drop the
- // channel and recreate it.
- if (host_->WillGpuSwitchOccur(true, gpu_preference_)) {
- host_->ForciblyCloseChannel();
- ClearSharedContexts();
- retry = true;
- }
- } else {
- retry = false;
- }
- } while (retry);
-
- const content::GPUInfo& gpu_info = host_->gpu_info();
- UMA_HISTOGRAM_ENUMERATION(
- "GPU.WebGraphicsContext3D_Init_CanLoseContext",
- attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context,
- 4);
- if (attributes.canRecoverFromContextLoss == false) {
- if (gpu_info.can_lose_context)
- return false;
- }
-
- attributes_ = attributes;
- return true;
+WebGraphicsContext3DGuest::~WebGraphicsContext3DGuest() {
}
-bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
- if (context_)
+bool WebGraphicsContext3DGuest::MaybeInitializeGL() {
+ if (gl_.get())
return true;
+
if (initialize_failed_)
return false;
- TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL");
-
- // Convert WebGL context creation attributes into ContentGLContext / EGL size
- // requests.
- const int alpha_size = attributes_.alpha ? 8 : 0;
- const int depth_size = attributes_.depth ? 24 : 0;
- const int stencil_size = attributes_.stencil ? 8 : 0;
- const int samples = attributes_.antialias ? 4 : 0;
- const int sample_buffers = attributes_.antialias ? 1 : 0;
- const int32 attribs[] = {
- ContentGLContext::ALPHA_SIZE, alpha_size,
- ContentGLContext::DEPTH_SIZE, depth_size,
- ContentGLContext::STENCIL_SIZE, stencil_size,
- ContentGLContext::SAMPLES, samples,
- ContentGLContext::SAMPLE_BUFFERS, sample_buffers,
- ContentGLContext::SHARE_RESOURCES, attributes_.shareResources ? 1 : 0,
- ContentGLContext::BIND_GENERATES_RESOURCES, 0,
- ContentGLContext::NONE,
- };
-
- const char* preferred_extensions = "*";
-
- // We need to lock g_all_shared_contexts until after ContentGLContext::Create
- // to ensure that the context we picked for our share group isn't deleted.
- // (There's also a lock in our destructor.)
- {
- base::AutoLock lock(g_all_shared_contexts_lock.Get());
- ContentGLContext* share_group = NULL;
- if (attributes_.shareResources) {
- share_group = g_all_shared_contexts.Pointer()->empty() ?
- NULL : (*g_all_shared_contexts.Pointer()->begin())->context_;
- }
-
- if (surface_id_) {
- context_ = ContentGLContext::CreateViewContext(
- host_,
- surface_id_,
- share_group,
- preferred_extensions,
- attribs,
- active_url_,
- gpu_preference_);
- } else {
- context_ = ContentGLContext::CreateOffscreenContext(
- host_,
- gfx::Size(1, 1),
- share_group,
- preferred_extensions,
- attribs,
- active_url_,
- gpu_preference_);
- }
+ // Create the GLES2 helper, which writes the command buffer protocol.
+ gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
+ if (!gles2_helper_->Initialize(kCommandBufferSize)) {
+ initialize_failed_ = true;
+ return false;
}
-
- if (!context_)
+ // Map the buffer into the renderer process's address space.
+ transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
+
+ // Create the object exposing the OpenGL API.
+ gl_.reset(new gpu::gles2::GLES2Implementation(
+ gles2_helper_.get(),
+ transfer_buffer_.get(),
+ false,
+ true));
+
+ // TODO(fsamuel): Is this right?
+ if (!gl_->Initialize(
+ kTransferBufferSize,
+ kTransferBufferSize,
+ kTransferBufferSize))
return false;
- gl_ = context_->GetImplementation();
-
- // 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");
-
- context_->SetContextLostCallback(
- base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost,
- weak_ptr_factory_.GetWeakPtr()));
-
- context_->GetCommandBufferProxy()->SetOnConsoleMessageCallback(
- base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage,
- weak_ptr_factory_.GetWeakPtr()));
-
- // TODO(gman): Remove this.
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) {
- context_->DisableShaderTranslation();
+ if (!channel_->BindGraphics()) {
+ initialize_failed_ = true;
+ return false;
}
-
// Set attributes_ from created offscreen context.
{
GLint alpha_bits = 0;
@@ -237,57 +112,65 @@ bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
attributes_.antialias = samples > 0;
}
- if (attributes_.shareResources) {
- base::AutoLock lock(g_all_shared_contexts_lock.Get());
- g_all_shared_contexts.Pointer()->insert(this);
- }
-
- context_->SetMemoryAllocationChangedCallback(base::Bind(
- &WebGraphicsContext3DCommandBufferImpl::OnMemoryAllocationChanged,
- weak_ptr_factory_.GetWeakPtr()));
-
return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
+bool WebGraphicsContext3DGuest::makeContextCurrent() {
if (!MaybeInitializeGL())
return false;
- return ContentGLContext::MakeCurrent(context_);
+ gles2::SetGLContext(gl_.get());
+
+ // Don't request latest error status from service. Just use the locally
+ // cached information from the last flush.
+ // TODO(apatrick): I'm not sure if this should actually change the
+ // current context if it fails. For now it gets changed even if it fails
+ // because making GL calls with a NULL context crashes.
+ if (command_buffer_->GetLastState().error != gpu::error::kNoError)
+ return false;
+ return true;
}
-int WebGraphicsContext3DCommandBufferImpl::width() {
+int WebGraphicsContext3DGuest::width() {
return cached_width_;
}
-int WebGraphicsContext3DCommandBufferImpl::height() {
+int WebGraphicsContext3DGuest::height() {
return cached_height_;
}
-bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() {
+void WebGraphicsContext3DGuest::playDead() {
+ dead_ = true;
+ OnContextLost();
+}
+
+bool WebGraphicsContext3DGuest::isGLES2Compliant() {
return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::setParentContext(
+bool WebGraphicsContext3DGuest::setParentContext(
WebGraphicsContext3D* parent_context) {
- WebGraphicsContext3DCommandBufferImpl* parent_context_impl =
- static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context);
- return context_->SetParent(
- parent_context_impl ? parent_context_impl->context() : NULL);
+ NOTIMPLEMENTED();
+ return true;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() {
- return context_->GetParentTextureId();
+WebGLId WebGraphicsContext3DGuest::getPlatformTextureId() {
+ NOTIMPLEMENTED();
+ return 0;
}
-void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
+void WebGraphicsContext3DGuest::prepareTexture() {
// Copies the contents of the off-screen render target into the texture
// used by the compositor.
- if (ShouldUseSwapClient())
- swap_client_->OnViewContextSwapBuffersPosted();
- context_->SwapBuffers();
- context_->Echo(base::Bind(
- &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete,
- weak_ptr_factory_.GetWeakPtr()));
+ RenderViewImpl* renderview =
+ web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL;
+ if (renderview)
+ renderview->OnViewContextSwapBuffersPosted();
+
+ // Swap buffers
+ gl_->SwapBuffers();
+ channel_->IssueSwapBuffers();
+ // TODO(fsamuel): GuestToHostChannel will call OnSwapBuffersComplete
+ // when it receives a swap buffers ACK message from the host.
#if defined(OS_MACOSX)
// It appears that making the compositor's on-screen context current on
// other platforms implies this flush. TODO(kbr): this means that the
@@ -296,34 +179,37 @@ void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
#endif
}
-void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM(
+void WebGraphicsContext3DGuest::postSubBufferCHROMIUM(
int x, int y, int width, int height) {
- // Same flow control as WebGraphicsContext3DCommandBufferImpl::prepareTexture
+ // Same flow control as WebGraphicsContext3DGuest::prepareTexture
// (see above).
- if (ShouldUseSwapClient())
- swap_client_->OnViewContextSwapBuffersPosted();
+ RenderViewImpl* renderview =
+ web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL;
+ if (renderview)
+ renderview->OnViewContextSwapBuffersPosted();
gl_->PostSubBufferCHROMIUM(x, y, width, height);
- context_->Echo(base::Bind(
- &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete,
- weak_ptr_factory_.GetWeakPtr()));
+ channel_->IssueSwapBuffers();
}
-void WebGraphicsContext3DCommandBufferImpl::reshape(int width, int height) {
+void WebGraphicsContext3DGuest::reshape(int width, int height) {
cached_width_ = width;
cached_height_ = height;
gl_->ResizeCHROMIUM(width, height);
+
+#ifdef FLIP_FRAMEBUFFER_VERTICALLY
+ scanline_.reset(new uint8[width * 4]);
+#endif // FLIP_FRAMEBUFFER_VERTICALLY
}
#ifdef FLIP_FRAMEBUFFER_VERTICALLY
-void WebGraphicsContext3DCommandBufferImpl::FlipVertically(
+void WebGraphicsContext3DGuest::FlipVertically(
uint8* framebuffer,
unsigned int width,
unsigned int height) {
- if (width == 0)
+ uint8* scanline = scanline_.get();
+ if (!scanline)
return;
- scanline_.resize(width * 4);
- uint8* scanline = &scanline_[0];
unsigned int row_bytes = width * 4;
unsigned int count = height / 2;
for (unsigned int i = 0; i < count; i++) {
@@ -340,7 +226,7 @@ void WebGraphicsContext3DCommandBufferImpl::FlipVertically(
}
#endif
-bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
+bool WebGraphicsContext3DGuest::readBackFramebuffer(
unsigned char* pixels,
size_t buffer_size,
WebGLId buffer,
@@ -382,13 +268,13 @@ bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::readBackFramebuffer(
+bool WebGraphicsContext3DGuest::readBackFramebuffer(
unsigned char* pixels,
size_t buffer_size) {
return readBackFramebuffer(pixels, buffer_size, 0, width(), height());
}
-void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
+void WebGraphicsContext3DGuest::synthesizeGLError(
WGC3Denum error) {
if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
synthetic_errors_.end()) {
@@ -396,7 +282,7 @@ void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
}
}
-void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM(
+void* WebGraphicsContext3DGuest::mapBufferSubDataCHROMIUM(
WGC3Denum target,
WGC3Dintptr offset,
WGC3Dsizeiptr size,
@@ -404,12 +290,12 @@ void* WebGraphicsContext3DCommandBufferImpl::mapBufferSubDataCHROMIUM(
return gl_->MapBufferSubDataCHROMIUM(target, offset, size, access);
}
-void WebGraphicsContext3DCommandBufferImpl::unmapBufferSubDataCHROMIUM(
+void WebGraphicsContext3DGuest::unmapBufferSubDataCHROMIUM(
const void* mem) {
return gl_->UnmapBufferSubDataCHROMIUM(mem);
}
-void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM(
+void* WebGraphicsContext3DGuest::mapTexSubImage2DCHROMIUM(
WGC3Denum target,
WGC3Dint level,
WGC3Dint xoffset,
@@ -423,48 +309,43 @@ void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM(
target, level, xoffset, yoffset, width, height, format, type, access);
}
-void WebGraphicsContext3DCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
+void WebGraphicsContext3DGuest::unmapTexSubImage2DCHROMIUM(
const void* mem) {
gl_->UnmapTexSubImage2DCHROMIUM(mem);
}
-void WebGraphicsContext3DCommandBufferImpl::setVisibilityCHROMIUM(
+void WebGraphicsContext3DGuest::setVisibilityCHROMIUM(
bool visible) {
gl_->Flush();
- context_->SetSurfaceVisible(visible);
+ // TODO(fsamuel): There doesn't seem to be an equivalent ppapi
+ // message. Do we care?
+ //context_->SetSurfaceVisible(visible);
if (!visible)
gl_->FreeEverything();
}
-void WebGraphicsContext3DCommandBufferImpl::
- setMemoryAllocationChangedCallbackCHROMIUM(
- WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) {
- memory_allocation_changed_callback_ = callback;
-}
-
-
-void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
+void WebGraphicsContext3DGuest::copyTextureToParentTextureCHROMIUM(
WebGLId texture, WebGLId parentTexture) {
NOTIMPLEMENTED();
}
-void WebGraphicsContext3DCommandBufferImpl::
+void WebGraphicsContext3DGuest::
rateLimitOffscreenContextCHROMIUM() {
gl_->RateLimitOffscreenContextCHROMIUM();
}
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::
+WebKit::WebString WebGraphicsContext3DGuest::
getRequestableExtensionsCHROMIUM() {
return WebKit::WebString::fromUTF8(
gl_->GetRequestableExtensionsCHROMIUM());
}
-void WebGraphicsContext3DCommandBufferImpl::requestExtensionCHROMIUM(
+void WebGraphicsContext3DGuest::requestExtensionCHROMIUM(
const char* extension) {
gl_->RequestExtensionCHROMIUM(extension);
}
-void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM(
+void WebGraphicsContext3DGuest::blitFramebufferCHROMIUM(
WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
WGC3Dbitfield mask, WGC3Denum filter) {
@@ -474,7 +355,7 @@ void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM(
mask, filter);
}
-void WebGraphicsContext3DCommandBufferImpl::
+void WebGraphicsContext3DGuest::
renderbufferStorageMultisampleCHROMIUM(
WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat,
WGC3Dsizei width, WGC3Dsizei height) {
@@ -485,72 +366,72 @@ void WebGraphicsContext3DCommandBufferImpl::
// Helper macros to reduce the amount of code.
#define DELEGATE_TO_GL(name, glname) \
-void WebGraphicsContext3DCommandBufferImpl::name() { \
+void WebGraphicsContext3DGuest::name() { \
gl_->glname(); \
}
#define DELEGATE_TO_GL_1(name, glname, t1) \
-void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+void WebGraphicsContext3DGuest::name(t1 a1) { \
gl_->glname(a1); \
}
#define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+rt WebGraphicsContext3DGuest::name(t1 a1) { \
return gl_->glname(a1); \
}
#define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
-rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
+rt WebGraphicsContext3DGuest::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 WebGraphicsContext3DGuest::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 WebGraphicsContext3DGuest::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 WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3) { \
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 WebGraphicsContext3DGuest::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
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, \
+void WebGraphicsContext3DGuest::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, \
+void WebGraphicsContext3DGuest::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, \
+void WebGraphicsContext3DGuest::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, \
+void WebGraphicsContext3DGuest::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, \
+void WebGraphicsContext3DGuest::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); \
@@ -565,7 +446,7 @@ DELEGATE_TO_GL_3(bindAttribLocation, BindAttribLocation, WebGLId,
DELEGATE_TO_GL_2(bindBuffer, BindBuffer, WGC3Denum, WebGLId)
-void WebGraphicsContext3DCommandBufferImpl::bindFramebuffer(
+void WebGraphicsContext3DGuest::bindFramebuffer(
WGC3Denum target,
WebGLId framebuffer) {
gl_->BindFramebuffer(target, framebuffer);
@@ -645,7 +526,7 @@ DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
-void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode,
+void WebGraphicsContext3DGuest::drawElements(WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
WGC3Dintptr offset) {
@@ -673,7 +554,7 @@ DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
-bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
+bool WebGraphicsContext3DGuest::getActiveAttrib(
WebGLId program, WGC3Duint index, ActiveInfo& info) {
if (!program) {
synthesizeGLError(GL_INVALID_VALUE);
@@ -703,7 +584,7 @@ bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib(
return true;
}
-bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform(
+bool WebGraphicsContext3DGuest::getActiveUniform(
WebGLId program, WGC3Duint index, ActiveInfo& info) {
GLint max_name_length = -1;
gl_->GetProgramiv(
@@ -741,11 +622,11 @@ DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
WGC3Denum, WGC3Denum, WGC3Dint*)
WebKit::WebGraphicsContext3D::Attributes
-WebGraphicsContext3DCommandBufferImpl::getContextAttributes() {
+WebGraphicsContext3DGuest::getContextAttributes() {
return attributes_;
}
-WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
+WGC3Denum WebGraphicsContext3DGuest::getError() {
if (!synthetic_errors_.empty()) {
std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
WGC3Denum err = *iter;
@@ -756,10 +637,10 @@ WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() {
return gl_->GetError();
}
-bool WebGraphicsContext3DCommandBufferImpl::isContextLost() {
- return initialize_failed_ ||
- (context_ && context_->IsCommandBufferContextLost()) ||
- context_lost_reason_ != GL_NO_ERROR;
+bool WebGraphicsContext3DGuest::isContextLost() {
+ // TODO(fsamuel): Context is assumed to be never lost
+ // until I find a cleaner way to do this.
+ return dead_ || initialize_failed_;
}
DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
@@ -772,7 +653,7 @@ DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog(
+WebKit::WebString WebGraphicsContext3DGuest::getProgramInfoLog(
WebGLId program) {
GLint logLength = 0;
gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
@@ -795,7 +676,7 @@ DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
+WebKit::WebString WebGraphicsContext3DGuest::getShaderInfoLog(
WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
@@ -813,7 +694,7 @@ WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog(
return res;
}
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
+WebKit::WebString WebGraphicsContext3DGuest::getShaderSource(
WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
@@ -833,7 +714,7 @@ WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource(
return res;
}
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::
+WebKit::WebString WebGraphicsContext3DGuest::
getTranslatedShaderSourceANGLE(WebGLId shader) {
GLint logLength = 0;
gl_->GetShaderiv(
@@ -854,7 +735,7 @@ WebKit::WebString WebGraphicsContext3DCommandBufferImpl::
return res;
}
-WebKit::WebString WebGraphicsContext3DCommandBufferImpl::getString(
+WebKit::WebString WebGraphicsContext3DGuest::getString(
WGC3Denum name) {
return WebKit::WebString::fromUTF8(
reinterpret_cast<const char*>(gl_->GetString(name)));
@@ -879,7 +760,7 @@ DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
WGC3Duint, WGC3Denum, WGC3Dint*)
-WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset(
+WGC3Dsizeiptr WebGraphicsContext3DGuest::getVertexAttribOffset(
WGC3Duint index, WGC3Denum pname) {
GLvoid* value = NULL;
// NOTE: If pname is ever a value that returns more then 1 element
@@ -916,7 +797,7 @@ DELEGATE_TO_GL_7(readPixels, ReadPixels,
WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
WGC3Denum, void*)
-void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() {
+void WebGraphicsContext3DGuest::releaseShaderCompiler() {
}
DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
@@ -926,7 +807,7 @@ DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
-void WebGraphicsContext3DCommandBufferImpl::shaderSource(
+void WebGraphicsContext3DGuest::shaderSource(
WebGLId shader, const WGC3Dchar* string) {
GLint length = strlen(string);
gl_->ShaderSource(shader, 1, &string, &length);
@@ -957,7 +838,7 @@ DELEGATE_TO_GL_3(texParameterf, TexParameterf,
static const unsigned int kTextureWrapR = 0x8072;
-void WebGraphicsContext3DCommandBufferImpl::texParameteri(
+void WebGraphicsContext3DGuest::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
@@ -1048,7 +929,7 @@ DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
const WGC3Dfloat*)
-void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer(
+void WebGraphicsContext3DGuest::vertexAttribPointer(
WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
WGC3Dsizei stride, WGC3Dintptr offset) {
gl_->VertexAttribPointer(
@@ -1059,23 +940,23 @@ void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer(
DELEGATE_TO_GL_4(viewport, Viewport,
WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
-WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() {
+WebGLId WebGraphicsContext3DGuest::createBuffer() {
GLuint o;
gl_->GenBuffers(1, &o);
return o;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() {
+WebGLId WebGraphicsContext3DGuest::createFramebuffer() {
GLuint o = 0;
gl_->GenFramebuffers(1, &o);
return o;
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createProgram() {
+WebGLId WebGraphicsContext3DGuest::createProgram() {
return gl_->CreateProgram();
}
-WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() {
+WebGLId WebGraphicsContext3DGuest::createRenderbuffer() {
GLuint o;
gl_->GenRenderbuffers(1, &o);
return o;
@@ -1083,82 +964,63 @@ WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() {
DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId);
-WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() {
+WebGLId WebGraphicsContext3DGuest::createTexture() {
GLuint o;
gl_->GenTextures(1, &o);
return o;
}
-void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) {
+void WebGraphicsContext3DGuest::deleteBuffer(WebGLId buffer) {
gl_->DeleteBuffers(1, &buffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer(
+void WebGraphicsContext3DGuest::deleteFramebuffer(
WebGLId framebuffer) {
gl_->DeleteFramebuffers(1, &framebuffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteProgram(WebGLId program) {
+void WebGraphicsContext3DGuest::deleteProgram(WebGLId program) {
gl_->DeleteProgram(program);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer(
+void WebGraphicsContext3DGuest::deleteRenderbuffer(
WebGLId renderbuffer) {
gl_->DeleteRenderbuffers(1, &renderbuffer);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) {
+void WebGraphicsContext3DGuest::deleteShader(WebGLId shader) {
gl_->DeleteShader(shader);
}
-void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) {
+void WebGraphicsContext3DGuest::deleteTexture(WebGLId texture) {
gl_->DeleteTextures(1, &texture);
}
-bool WebGraphicsContext3DCommandBufferImpl::ShouldUseSwapClient() {
- GpuChannelHostFactory* factory = GpuChannelHostFactory::instance();
- return factory && factory->IsMainThread() && swap_client_.get();
-}
-
-void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() {
- typedef WebGraphicsContext3DSwapBuffersClient WGC3DSwapClient;
+void WebGraphicsContext3DGuest::OnSwapBuffersComplete() {
// This may be called after tear-down of the RenderView.
- if (ShouldUseSwapClient()) {
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &WGC3DSwapClient::OnViewContextSwapBuffersComplete, swap_client_));
+ RenderViewImpl* renderview =
+ web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL;
+ if (renderview) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&RenderViewImpl::OnViewContextSwapBuffersComplete,
+ renderview));
}
if (swapbuffers_complete_callback_)
swapbuffers_complete_callback_->onSwapBuffersComplete();
}
-void WebGraphicsContext3DCommandBufferImpl::OnMemoryAllocationChanged(
- const GpuMemoryAllocation& allocation) {
- if (memory_allocation_changed_callback_)
- memory_allocation_changed_callback_->onMemoryAllocationChanged(
- allocation.gpu_resource_size_in_bytes);
-}
-
-void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback(
- WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
- error_message_callback_ = cb;
-}
-
-void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback(
+void WebGraphicsContext3DGuest::setContextLostCallback(
WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
context_lost_callback_ = cb;
}
-WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() {
- if (context_->IsCommandBufferContextLost() &&
- context_lost_reason_ == GL_NO_ERROR) {
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
- }
-
- return context_lost_reason_;
+WGC3Denum WebGraphicsContext3DGuest::getGraphicsResetStatusARB() {
+ return dead_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR;
}
-void WebGraphicsContext3DCommandBufferImpl::
+void WebGraphicsContext3DGuest::
setSwapBuffersCompleteCallbackCHROMIUM(
WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) {
swapbuffers_complete_callback_ = cb;
@@ -1170,47 +1032,14 @@ DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
-#if WEBKIT_USING_SKIA
-GrGLInterface* WebGraphicsContext3DCommandBufferImpl::onCreateGrGLInterface() {
- return webkit_glue::CreateCommandBufferSkiaGLBinding();
-}
-#endif
-
-namespace {
-
-WGC3Denum convertReason(ContentGLContext::ContextLostReason reason) {
- switch (reason) {
- case ContentGLContext::kGuilty:
- return GL_GUILTY_CONTEXT_RESET_ARB;
- case ContentGLContext::kInnocent:
- return GL_INNOCENT_CONTEXT_RESET_ARB;
- case ContentGLContext::kUnknown:
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
- }
-
- NOTREACHED();
- return GL_UNKNOWN_CONTEXT_RESET_ARB;
-}
-
-} // anonymous namespace
-
-void WebGraphicsContext3DCommandBufferImpl::OnContextLost(
- ContentGLContext::ContextLostReason reason) {
- context_lost_reason_ = convertReason(reason);
- if (context_lost_callback_) {
- context_lost_callback_->onContextLost();
- }
- if (attributes_.shareResources)
- ClearSharedContexts();
- if (ShouldUseSwapClient())
- swap_client_->OnViewContextSwapBuffersAborted();
-}
-
-void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage(
- const std::string& message, int id) {
- if (error_message_callback_) {
- WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str());
- error_message_callback_->onErrorMessage(str, id);
+void WebGraphicsContext3DGuest::OnContextLost() {
+ fprintf(stderr, ">>>>%s\n", __PRETTY_FUNCTION__);
+ RenderViewImpl* renderview =
+ web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL;
+ if (renderview) {
+ fprintf(stderr, ">>>Found a renderview\n");
+ renderview->OnViewContextSwapBuffersAborted();
}
}
+#endif // defined(ENABLE_GPU)
« no previous file with comments | « content/renderer/gpu/webgraphicscontext3d_guest.h ('k') | content/renderer/guest_render_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698