summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 23:45:16 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 23:45:16 +0000
commitf78ac522f8fc1463797b4de6831f9f0ee58566f8 (patch)
treeb683be43f4ce2aa22198e2ede71497bb41265ec6
parent2f19a0632eb3212d3b230f5de41ae2004e15056c (diff)
downloadchromium_src-f78ac522f8fc1463797b4de6831f9f0ee58566f8.zip
chromium_src-f78ac522f8fc1463797b4de6831f9f0ee58566f8.tar.gz
chromium_src-f78ac522f8fc1463797b4de6831f9f0ee58566f8.tar.bz2
Separate CompositingIOSurface from its GL context
This is towards making all CompositingIOSurfaces in a window to share a single GL context. BUG=180463 Review URL: https://chromiumcodereview.appspot.com/13363002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191935 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/compositing_iosurface_context_mac.h56
-rw-r--r--content/browser/renderer_host/compositing_iosurface_context_mac.mm107
-rw-r--r--content/browser/renderer_host/compositing_iosurface_mac.h15
-rw-r--r--content/browser/renderer_host/compositing_iosurface_mac.mm127
-rw-r--r--content/browser/renderer_host/compositing_iosurface_shader_programs_mac.cc9
-rw-r--r--content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h11
-rw-r--r--content/browser/renderer_host/compositing_iosurface_transformer_mac.cc13
-rw-r--r--content/browser/renderer_host/compositing_iosurface_transformer_mac.h6
-rw-r--r--content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc8
-rw-r--r--content/content_browser.gypi2
10 files changed, 223 insertions, 131 deletions
diff --git a/content/browser/renderer_host/compositing_iosurface_context_mac.h b/content/browser/renderer_host/compositing_iosurface_context_mac.h
new file mode 100644
index 0000000..bf4dd56
--- /dev/null
+++ b/content/browser/renderer_host/compositing_iosurface_context_mac.h
@@ -0,0 +1,56 @@
+// Copyright (c) 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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
+#define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
+
+#import <AppKit/NSOpenGL.h>
+#include <OpenGL/OpenGL.h>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_nsobject.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/browser/renderer_host/compositing_iosurface_mac.h"
+
+namespace content {
+
+class CompositingIOSurfaceShaderPrograms;
+
+class CompositingIOSurfaceContext
+ : public base::RefCounted<CompositingIOSurfaceContext> {
+ public:
+ static scoped_refptr<CompositingIOSurfaceContext> Get(
+ CompositingIOSurfaceMac::SurfaceOrder surface_order);
+
+ CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
+ return shader_program_cache_.get();
+ }
+ NSOpenGLContext* nsgl_context() const { return nsgl_context_; }
+ CGLContextObj cgl_context() const { return cgl_context_; }
+ bool is_vsync_disabled() const { return is_vsync_disabled_; }
+
+ private:
+ friend class base::RefCounted<CompositingIOSurfaceContext>;
+
+ CompositingIOSurfaceContext(
+ CompositingIOSurfaceMac::SurfaceOrder surface_order,
+ NSOpenGLContext* nsgl_context,
+ CGLContextObj clg_context,
+ bool is_vsync_disabled_,
+ scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
+ ~CompositingIOSurfaceContext();
+
+ // The value for NSOpenGLCPSurfaceOrder for this GL context, 1 will
+ // render above the window and -1 will render below the window.
+ GLint surface_order_;
+ scoped_nsobject<NSOpenGLContext> nsgl_context_;
+ CGLContextObj cgl_context_; // weak, backed by |nsgl_context_|
+ bool is_vsync_disabled_;
+ scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
diff --git a/content/browser/renderer_host/compositing_iosurface_context_mac.mm b/content/browser/renderer_host/compositing_iosurface_context_mac.mm
new file mode 100644
index 0000000..ede46b4
--- /dev/null
+++ b/content/browser/renderer_host/compositing_iosurface_context_mac.mm
@@ -0,0 +1,107 @@
+// Copyright (c) 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 "content/browser/renderer_host/compositing_iosurface_context_mac.h"
+
+#include <OpenGL/gl.h>
+#include <OpenGL/OpenGL.h>
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h"
+#include "ui/gl/gl_switches.h"
+#include "ui/gl/gpu_switching_manager.h"
+
+namespace content {
+
+scoped_refptr<CompositingIOSurfaceContext>
+ CompositingIOSurfaceContext::Get(
+ CompositingIOSurfaceMac::SurfaceOrder surface_order) {
+ std::vector<NSOpenGLPixelFormatAttribute> attributes;
+ attributes.push_back(NSOpenGLPFADoubleBuffer);
+ // We don't need a depth buffer - try setting its size to 0...
+ attributes.push_back(NSOpenGLPFADepthSize); attributes.push_back(0);
+ if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus())
+ attributes.push_back(NSOpenGLPFAAllowOfflineRenderers);
+ attributes.push_back(0);
+
+ scoped_nsobject<NSOpenGLPixelFormat> glPixelFormat(
+ [[NSOpenGLPixelFormat alloc] initWithAttributes:&attributes.front()]);
+ if (!glPixelFormat) {
+ LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed";
+ return NULL;
+ }
+
+ scoped_nsobject<NSOpenGLContext> nsgl_context(
+ [[NSOpenGLContext alloc] initWithFormat:glPixelFormat
+ shareContext:nil]);
+ if (!nsgl_context) {
+ LOG(ERROR) << "NSOpenGLContext initWithFormat failed";
+ return NULL;
+ }
+
+ // If requested, ask the WindowServer to render the OpenGL surface underneath
+ // the window. This, combined with a hole punched in the window, will allow
+ // for views to "overlap" the GL surface from the user's point of view.
+ if (surface_order == CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW) {
+ GLint gl_surface_order = -1;
+ [nsgl_context setValues:&gl_surface_order
+ forParameter:NSOpenGLCPSurfaceOrder];
+ }
+
+ CGLContextObj cgl_context = (CGLContextObj)[nsgl_context CGLContextObj];
+ if (!cgl_context) {
+ LOG(ERROR) << "CGLContextObj failed";
+ return NULL;
+ }
+
+ // Draw at beam vsync.
+ bool is_vsync_disabled =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync);
+ GLint swapInterval = is_vsync_disabled ? 0 : 1;
+ [nsgl_context setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
+
+ // Prepare the shader program cache. Precompile only the shader programs
+ // needed to draw the IO Surface.
+ CGLSetCurrentContext(cgl_context);
+ scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache(
+ new CompositingIOSurfaceShaderPrograms());
+ const bool prepared = (
+ shader_program_cache->UseBlitProgram() &&
+ shader_program_cache->UseSolidWhiteProgram());
+ glUseProgram(0u);
+ CGLSetCurrentContext(0);
+ if (!prepared) {
+ LOG(ERROR) << "IOSurface failed to compile/link required shader programs.";
+ return NULL;
+ }
+
+ return new CompositingIOSurfaceContext(
+ surface_order,
+ nsgl_context.release(),
+ cgl_context,
+ is_vsync_disabled,
+ shader_program_cache.Pass());
+}
+
+CompositingIOSurfaceContext::CompositingIOSurfaceContext(
+ CompositingIOSurfaceMac::SurfaceOrder surface_order,
+ NSOpenGLContext* nsgl_context,
+ CGLContextObj cgl_context,
+ bool is_vsync_disabled,
+ scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache)
+ : surface_order_(surface_order),
+ nsgl_context_(nsgl_context),
+ cgl_context_(cgl_context),
+ shader_program_cache_(shader_program_cache.Pass()) {
+}
+
+CompositingIOSurfaceContext::~CompositingIOSurfaceContext() {
+ CGLSetCurrentContext(cgl_context_);
+ shader_program_cache_->Reset();
+ CGLSetCurrentContext(0);
+}
+
+} // namespace content
diff --git a/content/browser/renderer_host/compositing_iosurface_mac.h b/content/browser/renderer_host/compositing_iosurface_mac.h
index 4dcaac5..3bbe3e5 100644
--- a/content/browser/renderer_host/compositing_iosurface_mac.h
+++ b/content/browser/renderer_host/compositing_iosurface_mac.h
@@ -13,7 +13,6 @@
#include "base/callback.h"
#include "base/mac/scoped_cftyperef.h"
-#include "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "base/time.h"
@@ -33,6 +32,7 @@ class Rect;
namespace content {
+class CompositingIOSurfaceContext;
class CompositingIOSurfaceShaderPrograms;
class CompositingIOSurfaceTransformer;
class RenderWidgetHostViewFrameSubscriber;
@@ -110,7 +110,7 @@ class CompositingIOSurfaceMac {
// In cocoa view units / DIPs.
const gfx::Size& io_surface_size() const { return io_surface_size_; }
- bool is_vsync_disabled() const { return is_vsync_disabled_; }
+ bool is_vsync_disabled() const;
// Get vsync scheduling parameters.
// |interval_numerator/interval_denominator| equates to fractional number of
@@ -205,10 +205,7 @@ class CompositingIOSurfaceMac {
CompositingIOSurfaceMac(
IOSurfaceSupport* io_surface_support,
- NSOpenGLContext* glContext,
- CGLContextObj cglContext,
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache,
- bool is_vsync_disabled,
+ scoped_refptr<CompositingIOSurfaceContext> context,
CVDisplayLinkRef display_link);
bool IsVendorIntel();
@@ -286,8 +283,7 @@ class CompositingIOSurfaceMac {
IOSurfaceSupport* io_surface_support_;
// GL context
- scoped_nsobject<NSOpenGLContext> glContext_;
- CGLContextObj cglContext_; // weak, backed by |glContext_|.
+ scoped_refptr<CompositingIOSurfaceContext> context_;
// IOSurface data.
uint64 io_surface_handle_;
@@ -309,13 +305,10 @@ class CompositingIOSurfaceMac {
// Timer for finishing a copy operation.
base::Timer finish_copy_timer_;
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
scoped_ptr<CompositingIOSurfaceTransformer> transformer_;
SurfaceQuad quad_;
- bool is_vsync_disabled_;
-
// CVDisplayLink for querying Vsync timing info and throttling swaps.
CVDisplayLinkRef display_link_;
diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm
index 10e3259..cfb4054 100644
--- a/content/browser/renderer_host/compositing_iosurface_mac.mm
+++ b/content/browser/renderer_host/compositing_iosurface_mac.mm
@@ -16,6 +16,7 @@
#include "base/mac/mac_util.h"
#include "base/message_loop.h"
#include "base/threading/platform_thread.h"
+#include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h"
#include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h"
#include "content/common/content_constants_internal.h"
@@ -26,8 +27,6 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
#include "ui/gl/gl_context.h"
-#include "ui/gl/gl_switches.h"
-#include "ui/gl/gpu_switching_manager.h"
#include "ui/gfx/size_conversions.h"
#include "ui/surface/io_surface_support_mac.h"
@@ -51,9 +50,6 @@ const int kFinishCopyRetryCycles = 100;
// This value is shorter than 16ms such that copy can complete within a vsync.
const int kFinishCopyPollingPeriodMs = 10;
-// Everything uses only the GL_TEXTURE0 texture unit.
-const int kTextureUnit = 0;
-
bool HasAppleFenceExtension() {
static bool initialized_has_fence = false;
static bool has_fence = false;
@@ -201,62 +197,8 @@ CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(SurfaceOrder order) {
return NULL;
}
- std::vector<NSOpenGLPixelFormatAttribute> attributes;
- attributes.push_back(NSOpenGLPFADoubleBuffer);
- // We don't need a depth buffer - try setting its size to 0...
- attributes.push_back(NSOpenGLPFADepthSize); attributes.push_back(0);
- if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus())
- attributes.push_back(NSOpenGLPFAAllowOfflineRenderers);
- attributes.push_back(0);
-
- scoped_nsobject<NSOpenGLPixelFormat> glPixelFormat(
- [[NSOpenGLPixelFormat alloc] initWithAttributes:&attributes.front()]);
- if (!glPixelFormat) {
- LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed";
- return NULL;
- }
-
- scoped_nsobject<NSOpenGLContext> glContext(
- [[NSOpenGLContext alloc] initWithFormat:glPixelFormat
- shareContext:nil]);
- if (!glContext) {
- LOG(ERROR) << "NSOpenGLContext initWithFormat failed";
- return NULL;
- }
-
- // If requested, ask the WindowServer to render the OpenGL surface underneath
- // the window. This, combined with a hole punched in the window, will allow
- // for views to "overlap" the GL surface from the user's point of view.
- if (order == SURFACE_ORDER_BELOW_WINDOW) {
- GLint belowWindow = -1;
- [glContext setValues:&belowWindow forParameter:NSOpenGLCPSurfaceOrder];
- }
-
- CGLContextObj cglContext = (CGLContextObj)[glContext CGLContextObj];
- if (!cglContext) {
- LOG(ERROR) << "CGLContextObj failed";
- return NULL;
- }
-
- // Draw at beam vsync.
- bool is_vsync_disabled =
- CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync);
- GLint swapInterval = is_vsync_disabled ? 0 : 1;
- [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
-
- // Prepare the shader program cache. Precompile only the shader programs
- // needed to draw the IO Surface.
- CGLSetCurrentContext(cglContext);
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache(
- new CompositingIOSurfaceShaderPrograms());
- const bool prepared = (shader_program_cache->UseBlitProgram(kTextureUnit) &&
- shader_program_cache->UseSolidWhiteProgram());
- glUseProgram(0u);
- CGLSetCurrentContext(0);
- if (!prepared) {
- LOG(ERROR) << "IOSurface failed to compile/link required shader programs.";
- return NULL;
- }
+ scoped_refptr<CompositingIOSurfaceContext> context =
+ CompositingIOSurfaceContext::Get(order);
CVDisplayLinkRef display_link;
CVReturn ret = CVDisplayLinkCreateWithActiveCGDisplays(&display_link);
@@ -265,23 +207,17 @@ CompositingIOSurfaceMac* CompositingIOSurfaceMac::Create(SurfaceOrder order) {
return NULL;
}
- return new CompositingIOSurfaceMac(io_surface_support, glContext.release(),
- cglContext,
- shader_program_cache.Pass(),
- is_vsync_disabled,
+ return new CompositingIOSurfaceMac(io_surface_support,
+ context,
display_link);
}
CompositingIOSurfaceMac::CompositingIOSurfaceMac(
IOSurfaceSupport* io_surface_support,
- NSOpenGLContext* glContext,
- CGLContextObj cglContext,
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache,
- bool is_vsync_disabled,
+ scoped_refptr<CompositingIOSurfaceContext> context,
CVDisplayLinkRef display_link)
: io_surface_support_(io_surface_support),
- glContext_(glContext),
- cglContext_(cglContext),
+ context_(context),
io_surface_handle_(0),
texture_(0),
finish_copy_timer_(
@@ -290,8 +226,6 @@ CompositingIOSurfaceMac::CompositingIOSurfaceMac(
base::Bind(&CompositingIOSurfaceMac::FinishAllCopies,
base::Unretained(this)),
true),
- shader_program_cache_(shader_program_cache.Pass()),
- is_vsync_disabled_(is_vsync_disabled),
display_link_(display_link),
display_link_stop_timer_(FROM_HERE, base::TimeDelta::FromSeconds(1),
this, &CompositingIOSurfaceMac::StopDisplayLink),
@@ -323,6 +257,10 @@ CompositingIOSurfaceMac::CompositingIOSurfaceMac(
StopDisplayLink();
}
+bool CompositingIOSurfaceMac::is_vsync_disabled() const {
+ return context_->is_vsync_disabled();
+}
+
void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase,
uint32* interval_numerator,
uint32* interval_denominator) {
@@ -335,24 +273,24 @@ void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase,
CompositingIOSurfaceMac::~CompositingIOSurfaceMac() {
FailAllCopies();
CVDisplayLinkRelease(display_link_);
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
CleanupAllCopiesWithinContext();
UnrefIOSurfaceWithContextCurrent();
- shader_program_cache_->Reset();
CGLSetCurrentContext(0);
+ context_ = nil;
}
void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle,
const gfx::Size& size) {
pixel_io_surface_size_ = size;
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
MapIOSurfaceToTexture(io_surface_handle);
CGLSetCurrentContext(0);
}
int CompositingIOSurfaceMac::GetRendererID() {
GLint current_renderer_id = -1;
- if (CGLGetParameter(cglContext_,
+ if (CGLGetParameter(context_->cgl_context(),
kCGLCPCurrentRendererID,
&current_renderer_id) == kCGLNoError)
return current_renderer_id & kCGLRendererIDMatchingMask;
@@ -362,14 +300,14 @@ int CompositingIOSurfaceMac::GetRendererID() {
void CompositingIOSurfaceMac::DrawIOSurface(
NSView* view, float scale_factor,
RenderWidgetHostViewFrameSubscriber* frame_subscriber) {
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_);
TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface",
"has_io_surface", has_io_surface);
- [glContext_ setView:view];
+ [context_->nsgl_context() setView:view];
gfx::Size window_size(NSSizeToCGSize([view frame].size));
gfx::Size pixel_window_size = gfx::ToFlooredSize(
gfx::ScaleSize(window_size, scale_factor));
@@ -395,8 +333,8 @@ void CompositingIOSurfaceMac::DrawIOSurface(
glDisable(GL_BLEND);
if (has_io_surface) {
- shader_program_cache_->UseBlitProgram(kTextureUnit);
- glActiveTexture(GL_TEXTURE0 + kTextureUnit);
+ context_->shader_program_cache()->UseBlitProgram();
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_);
DrawQuad(quad_);
@@ -406,7 +344,7 @@ void CompositingIOSurfaceMac::DrawIOSurface(
// Fill the resize gutters with white.
if (window_size.width() > io_surface_size_.width() ||
window_size.height() > io_surface_size_.height()) {
- shader_program_cache_->UseSolidWhiteProgram();
+ context_->shader_program_cache()->UseSolidWhiteProgram();
SurfaceQuad filler_quad;
if (window_size.width() > io_surface_size_.width()) {
// Draw right-side gutter down to the bottom of the window.
@@ -473,7 +411,7 @@ void CompositingIOSurfaceMac::DrawIOSurface(
}
}
- CGLFlushDrawable(cglContext_);
+ CGLFlushDrawable(context_->cgl_context());
// For latency_tests.cc:
UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete",
@@ -492,7 +430,7 @@ void CompositingIOSurfaceMac::DrawIOSurface(
StartOrContinueDisplayLink();
- if (!is_vsync_disabled_)
+ if (!is_vsync_disabled())
RateLimitDraws();
}
@@ -513,7 +451,7 @@ void CompositingIOSurfaceMac::CopyTo(
<< "Stride is required to be equal to width for GPU readback.";
output->setIsOpaque(true);
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
const base::Closure copy_done_callback = CopyToSelectedOutputWithinContext(
src_pixel_subrect, src_scale_factor, gfx::Rect(dst_pixel_size), false,
output.get(), NULL,
@@ -528,7 +466,7 @@ void CompositingIOSurfaceMac::CopyToVideoFrame(
float src_scale_factor,
const scoped_refptr<media::VideoFrame>& target,
const base::Callback<void(bool)>& callback) {
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
const base::Closure copy_done_callback = CopyToVideoFrameWithinContext(
src_pixel_subrect, src_scale_factor, false, target, callback);
CGLSetCurrentContext(0);
@@ -596,7 +534,7 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
GLuint plane = 0;
CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D(
- cglContext_,
+ context_->cgl_context(),
target,
GL_RGBA,
rounded_size.width(),
@@ -615,7 +553,7 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
}
void CompositingIOSurfaceMac::UnrefIOSurface() {
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
UnrefIOSurfaceWithContextCurrent();
CGLSetCurrentContext(0);
}
@@ -634,7 +572,7 @@ void CompositingIOSurfaceMac::DrawQuad(const SurfaceQuad& quad) {
bool CompositingIOSurfaceMac::IsVendorIntel() {
GLint screen;
- CGLGetVirtualScreen(cglContext_, &screen);
+ CGLGetVirtualScreen(context_->cgl_context(), &screen);
if (screen != screen_)
initialized_is_intel_ = false;
screen_ = screen;
@@ -661,11 +599,11 @@ void CompositingIOSurfaceMac::UnrefIOSurfaceWithContextCurrent() {
}
void CompositingIOSurfaceMac::GlobalFrameDidChange() {
- [glContext_ update];
+ [context_->nsgl_context() update];
}
void CompositingIOSurfaceMac::ClearDrawable() {
- [glContext_ clearDrawable];
+ [context_->nsgl_context() clearDrawable];
UnrefIOSurface();
}
@@ -766,8 +704,9 @@ base::Closure CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext(
// Create the transformer_ on first use.
if (!transformer_) {
transformer_.reset(new CompositingIOSurfaceTransformer(
- GL_TEXTURE_RECTANGLE_ARB, kTextureUnit, true,
- shader_program_cache_.get()));
+ GL_TEXTURE_RECTANGLE_ARB,
+ true,
+ context_->shader_program_cache()));
}
// Send transform commands to the GPU.
@@ -873,7 +812,7 @@ void CompositingIOSurfaceMac::AsynchronousReadbackForCopy(
void CompositingIOSurfaceMac::FinishAllCopies() {
std::vector<base::Closure> done_callbacks;
- CGLSetCurrentContext(cglContext_);
+ CGLSetCurrentContext(context_->cgl_context());
FinishAllCopiesWithinContext(&done_callbacks);
CGLSetCurrentContext(0);
for (size_t i = 0; i < done_callbacks.size(); ++i)
diff --git a/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.cc b/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.cc
index 40575df..12988a1 100644
--- a/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.cc
+++ b/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.cc
@@ -332,13 +332,12 @@ void CompositingIOSurfaceShaderPrograms::Reset() {
texel_scale_x_var_locations_[i] = -1;
}
-bool CompositingIOSurfaceShaderPrograms::UseBlitProgram(
- int texture_unit_offset) {
+bool CompositingIOSurfaceShaderPrograms::UseBlitProgram() {
const GLuint program = GetShaderProgram(SHADER_PROGRAM_BLIT);
if (program == 0u)
return false;
glUseProgram(program);
- BindUniformTextureVariable(SHADER_PROGRAM_BLIT, texture_unit_offset);
+ BindUniformTextureVariable(SHADER_PROGRAM_BLIT, 0);
return true;
}
@@ -351,7 +350,7 @@ bool CompositingIOSurfaceShaderPrograms::UseSolidWhiteProgram() {
}
bool CompositingIOSurfaceShaderPrograms::UseRGBToYV12Program(
- int pass_number, int texture_unit_offset, float texel_scale_x) {
+ int pass_number, float texel_scale_x) {
const int which = SHADER_PROGRAM_RGB_TO_YV12__1_OF_2 + pass_number - 1;
DCHECK_GE(which, SHADER_PROGRAM_RGB_TO_YV12__1_OF_2);
DCHECK_LE(which, SHADER_PROGRAM_RGB_TO_YV12__2_OF_2);
@@ -360,7 +359,7 @@ bool CompositingIOSurfaceShaderPrograms::UseRGBToYV12Program(
if (program == 0u)
return false;
glUseProgram(program);
- BindUniformTextureVariable(which, texture_unit_offset);
+ BindUniformTextureVariable(which, 0);
if (which == SHADER_PROGRAM_RGB_TO_YV12__1_OF_2) {
BindUniformTexelScaleXVariable(which, texel_scale_x);
} else {
diff --git a/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h b/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h
index ce6bfa9..152858c 100644
--- a/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h
+++ b/content/browser/renderer_host/compositing_iosurface_shader_programs_mac.h
@@ -26,8 +26,8 @@ class CompositingIOSurfaceShaderPrograms {
void Reset();
// Begin using the "blit" program, which is set up to sample the texture at
- // GL_TEXTURE_0 + |texture_unit_offset|. Returns false on error.
- bool UseBlitProgram(int texture_unit_offset);
+ // GL_TEXTURE_0. Returns false on error.
+ bool UseBlitProgram();
// Begin using the program that just draws solid white very efficiently.
// Returns false on error.
@@ -35,10 +35,9 @@ class CompositingIOSurfaceShaderPrograms {
// Begin using one of the two RGB-to-YV12 color conversion programs, as
// specified by |pass_number| 1 or 2. The programs will sample the texture at
- // GL_TEXTURE0 + |texture_unit_offset|, and account for scaling in the X
- // direction by |texel_scale_x|. Returns false on error.
- bool UseRGBToYV12Program(
- int pass_number, int texture_unit_offset, float texel_scale_x);
+ // GL_TEXTURE0, and account for scaling in the X direction by |texel_scale_x|.
+ // Returns false on error.
+ bool UseRGBToYV12Program(int pass_number, float texel_scale_x);
private:
enum { kNumShaderPrograms = 4 };
diff --git a/content/browser/renderer_host/compositing_iosurface_transformer_mac.cc b/content/browser/renderer_host/compositing_iosurface_transformer_mac.cc
index be9d264..da2ba6a 100644
--- a/content/browser/renderer_host/compositing_iosurface_transformer_mac.cc
+++ b/content/browser/renderer_host/compositing_iosurface_transformer_mac.cc
@@ -142,10 +142,9 @@ void DrawQuad(float src_x, float src_y, float src_width, float src_height,
} // namespace
CompositingIOSurfaceTransformer::CompositingIOSurfaceTransformer(
- GLenum texture_target, GLint texture_unit, bool src_texture_needs_y_flip,
+ GLenum texture_target, bool src_texture_needs_y_flip,
CompositingIOSurfaceShaderPrograms* shader_program_cache)
: texture_target_(texture_target),
- texture_unit_(texture_unit),
src_texture_needs_y_flip_(src_texture_needs_y_flip),
shader_program_cache_(shader_program_cache) {
DCHECK(texture_target_ == GL_TEXTURE_RECTANGLE_ARB)
@@ -168,7 +167,7 @@ bool CompositingIOSurfaceTransformer::ResizeBilinear(
if (src_subrect.IsEmpty() || dst_size.IsEmpty())
return false;
- glActiveTexture(GL_TEXTURE0 + texture_unit_);
+ glActiveTexture(GL_TEXTURE0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
@@ -188,7 +187,7 @@ bool CompositingIOSurfaceTransformer::ResizeBilinear(
texture_target_, src_subrect.size() == dst_size ? GL_NEAREST : GL_LINEAR,
GL_CLAMP_TO_EDGE);
- const bool prepared = shader_program_cache_->UseBlitProgram(texture_unit_);
+ const bool prepared = shader_program_cache_->UseBlitProgram();
DCHECK(prepared);
SetTransformationsForOffScreenRendering(dst_size);
DrawQuad(src_subrect.x(), src_subrect.y(),
@@ -218,7 +217,7 @@ bool CompositingIOSurfaceTransformer::TransformRGBToYV12(
TRACE_EVENT0("gpu", "TransformRGBToYV12");
- glActiveTexture(GL_TEXTURE0 + texture_unit_);
+ glActiveTexture(GL_TEXTURE0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
@@ -270,7 +269,7 @@ bool CompositingIOSurfaceTransformer::TransformRGBToYV12(
// Use the first-pass shader program and draw the scene.
const bool prepared_pass_1 = shader_program_cache_->UseRGBToYV12Program(
- 1, texture_unit_,
+ 1,
static_cast<float>(src_subrect.width()) / dst_size.width());
DCHECK(prepared_pass_1);
SetTransformationsForOffScreenRendering(*packed_y_size);
@@ -297,7 +296,7 @@ bool CompositingIOSurfaceTransformer::TransformRGBToYV12(
// Use the second-pass shader program and draw the scene.
const bool prepared_pass_2 =
- shader_program_cache_->UseRGBToYV12Program(2, texture_unit_, 1.0f);
+ shader_program_cache_->UseRGBToYV12Program(2, 1.0f);
DCHECK(prepared_pass_2);
SetTransformationsForOffScreenRendering(*packed_uv_size);
DrawQuad(0.0f, 0.0f,
diff --git a/content/browser/renderer_host/compositing_iosurface_transformer_mac.h b/content/browser/renderer_host/compositing_iosurface_transformer_mac.h
index c38c0e0..d401b92 100644
--- a/content/browser/renderer_host/compositing_iosurface_transformer_mac.h
+++ b/content/browser/renderer_host/compositing_iosurface_transformer_mac.h
@@ -25,13 +25,12 @@ class CompositingIOSurfaceTransformer {
public:
// Construct a transformer that always uses the given parameters for texture
// bindings. |texture_target| is one of the valid enums to use with
- // glBindTexture(). |texture_unit| selects the texture unit to be used when
- // running the shader programs (i.e., specify 0 for GL_TEXTURE0).
+ // glBindTexture().
// |src_texture_needs_y_flip| is true when the |src_texture| argument to any
// of the methods below uses upside-down Y coordinates.
// |shader_program_cache| is not owned by this instance.
CompositingIOSurfaceTransformer(
- GLenum texture_target, int texture_unit, bool src_texture_needs_y_flip,
+ GLenum texture_target, bool src_texture_needs_y_flip,
CompositingIOSurfaceShaderPrograms* shader_program_cache);
~CompositingIOSurfaceTransformer();
@@ -78,7 +77,6 @@ class CompositingIOSurfaceTransformer {
// textures being created and read). Generally, this is
// GL_TEXTURE_RECTANGLE_ARB.
const GLenum texture_target_;
- const int texture_unit_;
const bool src_texture_needs_y_flip_;
CompositingIOSurfaceShaderPrograms* const shader_program_cache_;
diff --git a/content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc b/content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc
index 110d79a..baaa64a 100644
--- a/content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc
+++ b/content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc
@@ -276,7 +276,7 @@ class CompositingIOSurfaceTransformerTest : public testing::Test {
CGLSetCurrentContext(context_);
shader_program_cache_.reset(new CompositingIOSurfaceShaderPrograms());
transformer_.reset(new CompositingIOSurfaceTransformer(
- kGLTextureTarget, 0, false, shader_program_cache_.get()));
+ kGLTextureTarget, false, shader_program_cache_.get()));
}
virtual ~CompositingIOSurfaceTransformerTest() {
@@ -415,10 +415,10 @@ class CompositingIOSurfaceTransformerTest : public testing::Test {
TEST_F(CompositingIOSurfaceTransformerTest,
DISABLED_ShaderProgramsCompileAndLink) {
// Attempt to use each program, binding its required uniform variables.
- EXPECT_NO_GL_ERROR(shader_program_cache()->UseBlitProgram(0));
+ EXPECT_NO_GL_ERROR(shader_program_cache()->UseBlitProgram());
EXPECT_NO_GL_ERROR(shader_program_cache()->UseSolidWhiteProgram());
- EXPECT_NO_GL_ERROR(shader_program_cache()->UseRGBToYV12Program(1, 0, 1.0f));
- EXPECT_NO_GL_ERROR(shader_program_cache()->UseRGBToYV12Program(2, 0, 1.0f));
+ EXPECT_NO_GL_ERROR(shader_program_cache()->UseRGBToYV12Program(1, 1.0f));
+ EXPECT_NO_GL_ERROR(shader_program_cache()->UseRGBToYV12Program(2, 1.0f));
EXPECT_NO_GL_ERROR(glUseProgram(0));
}
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 127551a..ad13958 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -654,6 +654,8 @@
'browser/renderer_host/clipboard_message_filter_mac.mm',
'browser/renderer_host/compositor_impl_android.cc',
'browser/renderer_host/compositor_impl_android.h',
+ 'browser/renderer_host/compositing_iosurface_context_mac.mm',
+ 'browser/renderer_host/compositing_iosurface_context_mac.h',
'browser/renderer_host/compositing_iosurface_mac.h',
'browser/renderer_host/compositing_iosurface_mac.mm',
'browser/renderer_host/compositing_iosurface_shader_programs_mac.cc',