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

Side by Side Diff: content/browser/renderer_host/backing_store_mac.mm

Issue 10548026: mac: Make dynamic DPI changes work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "content/browser/renderer_host/backing_store_mac.h" 7 #include "content/browser/renderer_host/backing_store_mac.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 23 matching lines...) Expand all
34 if (!cg_layer_) { 34 if (!cg_layer_) {
35 // The view isn't in a window yet. Use a CGBitmapContext for now. 35 // The view isn't in a window yet. Use a CGBitmapContext for now.
36 cg_bitmap_.reset(CreateCGBitmapContext()); 36 cg_bitmap_.reset(CreateCGBitmapContext());
37 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); 37 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_);
38 } 38 }
39 } 39 }
40 40
41 BackingStoreMac::~BackingStoreMac() { 41 BackingStoreMac::~BackingStoreMac() {
42 } 42 }
43 43
44 void BackingStoreMac::ScaleFactorChanged(float device_scale_factor) {
45 if (device_scale_factor == device_scale_factor_)
46 return;
47
48 device_scale_factor_ = device_scale_factor;
49
50 base::mac::ScopedCFTypeRef<CGLayerRef> new_layer(CreateCGLayer());
51 // If we have a layer, copy the old contents. A pixelated flash is better
52 // than a white flash.
53 if (new_layer && cg_layer_) {
54 CGContextRef layer = CGLayerGetContext(new_layer);
55 CGContextDrawLayerAtPoint(layer, CGPointMake(0, 0), cg_layer_);
56 }
57
58 cg_layer_.swap(new_layer);
59 if (!cg_layer_) {
60 // The view isn't in a window yet. Use a CGBitmapContext for now.
61 cg_bitmap_.reset(CreateCGBitmapContext());
62 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_);
63 }
64 }
65
44 size_t BackingStoreMac::MemorySize() { 66 size_t BackingStoreMac::MemorySize() {
45 return size().Scale(device_scale_factor_).GetArea() * 4; 67 return size().Scale(device_scale_factor_).GetArea() * 4;
46 } 68 }
47 69
48 void BackingStoreMac::PaintToBackingStore( 70 void BackingStoreMac::PaintToBackingStore(
49 content::RenderProcessHost* process, 71 content::RenderProcessHost* process,
50 TransportDIB::Id bitmap, 72 TransportDIB::Id bitmap,
51 const gfx::Rect& bitmap_rect, 73 const gfx::Rect& bitmap_rect,
52 const std::vector<gfx::Rect>& copy_rects, 74 const std::vector<gfx::Rect>& copy_rects,
53 float scale_factor, 75 float scale_factor,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 pixel_size.width(), 276 pixel_size.width(),
255 pixel_size.height(), 277 pixel_size.height(),
256 8, pixel_size.width() * 4, 278 8, pixel_size.width() * 4,
257 base::mac::GetSystemColorSpace(), 279 base::mac::GetSystemColorSpace(),
258 kCGImageAlphaPremultipliedFirst | 280 kCGImageAlphaPremultipliedFirst |
259 kCGBitmapByteOrder32Host); 281 kCGBitmapByteOrder32Host);
260 DCHECK(context); 282 DCHECK(context);
261 283
262 return context; 284 return context;
263 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698