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

Unified Diff: content/browser/renderer_host/software_layer_mac.mm

Issue 294023012: Use a separate NSView to draw browser composited content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments, clean-u 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
« no previous file with comments | « content/browser/renderer_host/software_layer_mac.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/software_layer_mac.mm
diff --git a/content/browser/renderer_host/software_layer_mac.mm b/content/browser/renderer_host/software_layer_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..896e3d25595aa600684a37ff5ed9cb09e202de11
--- /dev/null
+++ b/content/browser/renderer_host/software_layer_mac.mm
@@ -0,0 +1,66 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/software_layer_mac.h"
+
+#include "base/debug/trace_event.h"
+#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/sdk_forward_declarations.h"
+#include "ui/base/cocoa/animation_utils.h"
+
+@implementation SoftwareLayer
+
+- (id)init {
+ if (self = [super init]) {
+ [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
+ [self setAnchorPoint:CGPointMake(0, 0)];
+ // Setting contents gravity is necessary to prevent the layer from being
+ // scaled during dyanmic resizes (especially with devtools open).
+ [self setContentsGravity:kCAGravityTopLeft];
+ }
+ return self;
+}
+
+- (void)setContentsToData:(const void *)data
+ withRowBytes:(size_t)rowBytes
+ withPixelSize:(gfx::Size)pixelSize
+ withScaleFactor:(float)scaleFactor {
+ TRACE_EVENT0("browser", "-[SoftwareLayer setContentsToData]");
+
+ // Disable animating the contents change or the scale factor change.
+ ScopedCAActionDisabler disabler;
+
+ // Set the contents of the software CALayer to be a CGImage with the provided
+ // pixel data. Make a copy of the data before backing the image with them,
+ // because the same buffer will be reused for the next frame.
+ base::ScopedCFTypeRef<CFDataRef> dataCopy(
+ CFDataCreate(NULL,
+ static_cast<const UInt8 *>(data),
+ rowBytes * pixelSize.height()));
+ base::ScopedCFTypeRef<CGDataProviderRef> dataProvider(
+ CGDataProviderCreateWithCFData(dataCopy));
+ base::ScopedCFTypeRef<CGImageRef> image(
+ CGImageCreate(pixelSize.width(),
+ pixelSize.height(),
+ 8,
+ 32,
+ rowBytes,
+ base::mac::GetSystemColorSpace(),
+ kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
+ dataProvider,
+ NULL,
+ false,
+ kCGRenderingIntentDefault));
+ [self setContents:(id)image.get()];
+
+ // Set the contents scale of the software CALayer.
+ if ([self respondsToSelector:(@selector(contentsScale))] &&
+ [self respondsToSelector:(@selector(setContentsScale:))] &&
+ [self contentsScale] != scaleFactor) {
+ [self setContentsScale:scaleFactor];
+ }
+}
+
+@end
« no previous file with comments | « content/browser/renderer_host/software_layer_mac.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698