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

Side by Side Diff: skia/ext/bitmap_platform_device_mac.cc

Issue 1508893003: Use proper namespace in skia/ext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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
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 #include "skia/ext/bitmap_platform_device_mac.h" 5 #include "skia/ext/bitmap_platform_device_mac.h"
6 6
7 #import <ApplicationServices/ApplicationServices.h> 7 #import <ApplicationServices/ApplicationServices.h>
8 #include <time.h> 8 #include <time.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // Our coordinate system is flipped to match WebKit's so we need to modify 92 // Our coordinate system is flipped to match WebKit's so we need to modify
93 // the xform to match that. 93 // the xform to match that.
94 SkMatrix transformed_matrix = matrix; 94 SkMatrix transformed_matrix = matrix;
95 SkScalar sy = -matrix.getScaleY(); 95 SkScalar sy = -matrix.getScaleY();
96 transformed_matrix.setScaleY(sy); 96 transformed_matrix.setScaleY(sy);
97 size_t height = CGBitmapContextGetHeight(context); 97 size_t height = CGBitmapContextGetHeight(context);
98 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. 98 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped.
99 transformed_matrix.setTranslateY(ty + (SkScalar)height); 99 transformed_matrix.setTranslateY(ty + (SkScalar)height);
100 100
101 CGAffineTransform cg_matrix = 101 CGAffineTransform cg_matrix =
102 gfx::SkMatrixToCGAffineTransform(transformed_matrix); 102 skia::SkMatrixToCGAffineTransform(transformed_matrix);
103 103
104 // Load final transform into context. 104 // Load final transform into context.
105 CGContextConcatCTM(context, cg_matrix); 105 CGContextConcatCTM(context, cg_matrix);
106 } 106 }
107 107
108 // Loads a SkRegion into the CG context. 108 // Loads a SkRegion into the CG context.
109 static void LoadClippingRegionToCGContext(CGContextRef context, 109 static void LoadClippingRegionToCGContext(CGContextRef context,
110 const SkRegion& region, 110 const SkRegion& region,
111 const SkMatrix& transformation) { 111 const SkMatrix& transformation) {
112 if (region.isEmpty()) { 112 if (region.isEmpty()) {
113 // region can be empty, in which case everything will be clipped. 113 // region can be empty, in which case everything will be clipped.
114 SkRect rect; 114 SkRect rect;
115 rect.setEmpty(); 115 rect.setEmpty();
116 CGContextClipToRect(context, gfx::SkRectToCGRect(rect)); 116 CGContextClipToRect(context, skia::SkRectToCGRect(rect));
117 } else if (region.isRect()) { 117 } else if (region.isRect()) {
118 // CoreGraphics applies the current transform to clip rects, which is 118 // CoreGraphics applies the current transform to clip rects, which is
119 // unwanted. Inverse-transform the rect before sending it to CG. This only 119 // unwanted. Inverse-transform the rect before sending it to CG. This only
120 // works for translations and scaling, but not for rotations (but the 120 // works for translations and scaling, but not for rotations (but the
121 // viewport is never rotated anyway). 121 // viewport is never rotated anyway).
122 SkMatrix t; 122 SkMatrix t;
123 bool did_invert = transformation.invert(&t); 123 bool did_invert = transformation.invert(&t);
124 if (!did_invert) 124 if (!did_invert)
125 t.reset(); 125 t.reset();
126 // Do the transformation. 126 // Do the transformation.
127 SkRect rect; 127 SkRect rect;
128 rect.set(region.getBounds()); 128 rect.set(region.getBounds());
129 t.mapRect(&rect); 129 t.mapRect(&rect);
130 SkIRect irect; 130 SkIRect irect;
131 rect.round(&irect); 131 rect.round(&irect);
132 CGContextClipToRect(context, gfx::SkIRectToCGRect(irect)); 132 CGContextClipToRect(context, skia::SkIRectToCGRect(irect));
133 } else { 133 } else {
134 // It is complex. 134 // It is complex.
135 SkPath path; 135 SkPath path;
136 region.getBoundaryPath(&path); 136 region.getBoundaryPath(&path);
137 // Clip. Note that windows clipping regions are not affected by the 137 // Clip. Note that windows clipping regions are not affected by the
138 // transform so apply it manually. 138 // transform so apply it manually.
139 path.transform(transformation); 139 path.transform(transformation);
140 // TODO(playmobil): Implement. 140 // TODO(playmobil): Implement.
141 SkASSERT(false); 141 SkASSERT(false);
142 // LoadPathToDC(context, path); 142 // LoadPathToDC(context, path);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 293
294 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, 294 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
295 uint8_t* data, OnFailureType failureType) { 295 uint8_t* data, OnFailureType failureType) {
296 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( 296 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef(
297 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); 297 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque));
298 return CreateCanvas(dev, failureType); 298 return CreateCanvas(dev, failureType);
299 } 299 }
300 300
301 } // namespace skia 301 } // namespace skia
OLDNEW
« no previous file with comments | « ios/chrome/browser/suggestions/image_fetcher_impl.mm ('k') | skia/ext/bitmap_platform_device_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698