summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-11 17:38:24 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-11 17:38:24 +0000
commit4abb018ec6ebdcdd397df702bf13aa2592de1946 (patch)
tree2d77a87072b39202e6330d6e6660c66bf705480c /content
parent6722843fe9f705918d1f801e2193394cad613700 (diff)
downloadchromium_src-4abb018ec6ebdcdd397df702bf13aa2592de1946.zip
chromium_src-4abb018ec6ebdcdd397df702bf13aa2592de1946.tar.gz
chromium_src-4abb018ec6ebdcdd397df702bf13aa2592de1946.tar.bz2
mac: Enable HiDPI for the accelerated path.
WebKit only sends HiDPI IOSurfaces if the screen is "DIP enabled" (see content/browser/web_contents/web_contents_impl.cc around line 590, search for IsDIPEnabled()), so set that to true. BUG=31960 TEST=Poster circle looks good in HiDPI TBR=sky Review URL: https://chromiumcodereview.appspot.com/10544086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/compositing_iosurface_mac.h12
-rw-r--r--content/browser/renderer_host/compositing_iosurface_mac.mm59
-rw-r--r--content/browser/renderer_host/render_widget_host_view_mac.mm44
3 files changed, 72 insertions, 43 deletions
diff --git a/content/browser/renderer_host/compositing_iosurface_mac.h b/content/browser/renderer_host/compositing_iosurface_mac.h
index fe6aaf3..f224dc0 100644
--- a/content/browser/renderer_host/compositing_iosurface_mac.h
+++ b/content/browser/renderer_host/compositing_iosurface_mac.h
@@ -28,9 +28,9 @@ class CompositingIOSurfaceMac {
void SetIOSurface(uint64 io_surface_handle);
// Blit the IOSurface at the upper-left corner of the |view|. If |view| window
- // size is larger than the IOSurface, the remaining left and bottom edges will
- // be white.
- void DrawIOSurface(NSView* view);
+ // size is larger than the IOSurface, the remaining right and bottom edges
+ // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views.
+ void DrawIOSurface(NSView* view, float scale_factor);
// Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef
// into |out|. The image data is transformed so that it fits in |dst_size|.
@@ -51,7 +51,9 @@ class CompositingIOSurfaceMac {
bool HasIOSurface() { return !!io_surface_.get(); }
- const gfx::Size& io_surface_size() const { return io_surface_size_; }
+ const gfx::Size& pixel_io_surface_size() const {
+ return pixel_io_surface_size_;
+ }
bool is_vsync_disabled() const { return is_vsync_disabled_; }
@@ -126,7 +128,7 @@ class CompositingIOSurfaceMac {
base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_;
// The width and height of the io surface.
- gfx::Size io_surface_size_;
+ gfx::Size pixel_io_surface_size_;
// The "live" OpenGL texture referring to this IOSurfaceRef. Note
// that per the CGLTexImageIOSurface2D API we do not need to
diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm
index 8367ab0..0bae917 100644
--- a/content/browser/renderer_host/compositing_iosurface_mac.mm
+++ b/content/browser/renderer_host/compositing_iosurface_mac.mm
@@ -205,7 +205,7 @@ void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle) {
CGLSetCurrentContext(0);
}
-void CompositingIOSurfaceMac::DrawIOSurface(NSView* view) {
+void CompositingIOSurfaceMac::DrawIOSurface(NSView* view, float scale_factor) {
CGLSetCurrentContext(cglContext_);
bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_);
@@ -214,11 +214,22 @@ void CompositingIOSurfaceMac::DrawIOSurface(NSView* view) {
"has_io_surface", has_io_surface);
[glContext_ setView:view];
- gfx::Size window_size([view frame].size.width, [view frame].size.height);
- glViewport(0, 0, window_size.width(), window_size.height());
+ gfx::Size window_size(NSSizeToCGSize([view frame].size));
+ gfx::Size pixel_window_size = window_size.Scale(scale_factor);
+ glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height());
+
+ // TODO: After a resolution change, the DPI-ness of the view and the
+ // IOSurface might not be in sync.
+ gfx::Size io_surface_size = pixel_io_surface_size_;
+ io_surface_size = pixel_io_surface_size_.Scale(1.0 / scale_factor);
+ quad_.set_size(io_surface_size, pixel_io_surface_size_);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
+
+ // Note that the projection keeps things in view units, so the use of
+ // window_size / io_surface_size (as opposed to the pixel_ variants) below is
+ // correct.
glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -239,20 +250,20 @@ void CompositingIOSurfaceMac::DrawIOSurface(NSView* view) {
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR();
// Fill the resize gutters with white.
- if (window_size.width() > io_surface_size_.width() ||
- window_size.height() > io_surface_size_.height()) {
+ if (window_size.width() > io_surface_size.width() ||
+ window_size.height() > io_surface_size.height()) {
glUseProgram(shader_program_white_);
SurfaceQuad filler_quad;
- if (window_size.width() > io_surface_size_.width()) {
+ if (window_size.width() > io_surface_size.width()) {
// Draw right-side gutter down to the bottom of the window.
- filler_quad.set_rect(io_surface_size_.width(), 0.0f,
+ filler_quad.set_rect(io_surface_size.width(), 0.0f,
window_size.width(), window_size.height());
DrawQuad(filler_quad);
}
- if (window_size.height() > io_surface_size_.height()) {
+ if (window_size.height() > io_surface_size.height()) {
// Draw bottom gutter to the width of the IOSurface.
- filler_quad.set_rect(0.0f, io_surface_size_.height(),
- io_surface_size_.width(), window_size.height());
+ filler_quad.set_rect(0.0f, io_surface_size.height(),
+ io_surface_size.width(), window_size.height());
DrawQuad(filler_quad);
}
}
@@ -342,7 +353,7 @@ bool CompositingIOSurfaceMac::CopyTo(const gfx::Size& dst_size, void* out) {
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_);
SurfaceQuad quad;
- quad.set_size(dst_size, io_surface_size_);
+ quad.set_size(dst_size, pixel_io_surface_size_);
DrawQuad(quad);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR();
@@ -380,11 +391,11 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
}
io_surface_handle_ = io_surface_handle;
- io_surface_size_.SetSize(
+ pixel_io_surface_size_.SetSize(
io_surface_support_->IOSurfaceGetWidth(io_surface_),
io_surface_support_->IOSurfaceGetHeight(io_surface_));
- quad_.set_size(io_surface_size_, io_surface_size_);
+ quad_.set_size(pixel_io_surface_size_, pixel_io_surface_size_);
GLenum target = GL_TEXTURE_RECTANGLE_ARB;
glGenTextures(1, &texture_);
@@ -392,17 +403,17 @@ bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
GLuint plane = 0;
- CGLError cglerror =
- io_surface_support_->CGLTexImageIOSurface2D(cglContext_,
- target,
- GL_RGBA,
- io_surface_size_.width(),
- io_surface_size_.height(),
- GL_BGRA,
- GL_UNSIGNED_INT_8_8_8_8_REV,
- io_surface_.get(),
- plane);
- CHECK_GL_ERROR();
+ CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D(
+ cglContext_,
+ target,
+ GL_RGBA,
+ pixel_io_surface_size_.width(),
+ pixel_io_surface_size_.height(),
+ GL_BGRA,
+ GL_UNSIGNED_INT_8_8_8_8_REV,
+ io_surface_.get(),
+ plane);
+ CHECK_GL_ERROR();
if (cglerror != kCGLNoError) {
LOG(ERROR) << "CGLTexImageIOSurface2D: " << cglerror;
return false;
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index ddc7c1c..b48ba3c 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -104,6 +104,10 @@ typedef unsigned long long NSEventMask;
- (CGFloat)backingScaleFactor;
@end
+@interface NSView (NSOpenGLSurfaceResolutionLionAPI)
+- (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag;
+@end
+
#endif // 10.7
@@ -116,6 +120,20 @@ static inline int ToWebKitModifiers(NSUInteger flags) {
return modifiers;
}
+float ScaleFactor(NSView* view) {
+ if (NSWindow* window = [view window]) {
+ if ([window respondsToSelector:@selector(backingScaleFactor)])
+ return [window backingScaleFactor];
+ return [window userSpaceScaleFactor];
+ }
+ if (NSScreen* screen = [NSScreen mainScreen]) {
+ if ([screen respondsToSelector:@selector(backingScaleFactor)])
+ return [screen backingScaleFactor];
+ return [screen userSpaceScaleFactor];
+ }
+ return 1;
+}
+
// Private methods:
@interface RenderWidgetHostViewCocoa ()
@property(nonatomic, assign) NSRange selectedRange;
@@ -792,18 +810,7 @@ BackingStore* RenderWidgetHostViewMac::AllocBackingStore(
const gfx::Size& size) {
// TODO(thakis): Register for backing scale factor change events and pass
// that on.
- float scale = 1;
- if (NSWindow* window = [cocoa_view_ window]) {
- if ([window respondsToSelector:@selector(backingScaleFactor)])
- scale = [window backingScaleFactor];
- else
- scale = [window userSpaceScaleFactor];
- } else if (NSScreen* screen = [NSScreen mainScreen]) {
- if ([screen respondsToSelector:@selector(backingScaleFactor)])
- scale = [screen backingScaleFactor];
- else
- scale = [screen userSpaceScaleFactor];
- }
+ float scale = ScaleFactor(cocoa_view_);
return new BackingStoreMac(render_widget_host_, size, scale);
}
@@ -1081,11 +1088,13 @@ void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
bool RenderWidgetHostViewMac::HasAcceleratedSurface(
const gfx::Size& desired_size) {
+ // TODO: What coordinates is desired_size in? Should it be
+ // compared to the pixel or logical size of compositing_iosurface_?
return last_frame_was_accelerated_ &&
compositing_iosurface_.get() &&
compositing_iosurface_->HasIOSurface() &&
(desired_size.IsEmpty() ||
- compositing_iosurface_->io_surface_size() == desired_size);
+ compositing_iosurface_->pixel_io_surface_size() == desired_size);
}
void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() {
@@ -1298,6 +1307,10 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
focusedPluginIdentifier_ = -1;
// OpenGL support:
+ if ([self respondsToSelector:
+ @selector(setWantsBestResolutionOpenGLSurface:)]) {
+ [self setWantsBestResolutionOpenGLSurface:YES];
+ }
handlingGlobalFrameDidChange_ = NO;
[[NSNotificationCenter defaultCenter]
addObserver:self
@@ -1965,7 +1978,10 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
NSRectFill(dirtyRect);
}
- renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(self);
+ // TODO(thakis): Register for backing scale factor change events and pass
+ // that on.
+ renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
+ self, ScaleFactor(self));
renderWidgetHostView_->AckPendingSwapBuffers();
return;
}