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

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

Issue 183008: Avoids the use of "namespace using-directives" in a few places.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: with gfx:: Created 11 years, 3 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
« no previous file with comments | « skia/ext/image_operations.cc ('k') | webkit/glue/devtools/bound_object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "skia/ext/skia_utils_mac.h" 7 #include "skia/ext/skia_utils_mac.h"
8 #include "third_party/skia/include/core/SkMatrix.h" 8 #include "third_party/skia/include/core/SkMatrix.h"
9 #include "third_party/skia/include/core/SkPath.h" 9 #include "third_party/skia/include/core/SkPath.h"
10 #include "third_party/skia/include/core/SkTypes.h" 10 #include "third_party/skia/include/core/SkTypes.h"
11 #include "third_party/skia/include/core/SkUtils.h" 11 #include "third_party/skia/include/core/SkUtils.h"
12 12
13 namespace skia { 13 namespace skia {
14 14
15 // TODO(brettw) remove this when the gfx namespaces are all removed.
16 using namespace gfx;
17
18 namespace { 15 namespace {
19 16
20 // Constrains position and size to fit within available_size. 17 // Constrains position and size to fit within available_size.
21 bool constrain(int available_size, int* position, int *size) { 18 bool constrain(int available_size, int* position, int *size) {
22 if (*position < 0) { 19 if (*position < 0) {
23 *size += *position; 20 *size += *position;
24 *position = 0; 21 *position = 0;
25 } 22 }
26 if (*size > 0 && *position < available_size) { 23 if (*size > 0 && *position < available_size) {
27 int overflow = (*position + *size) - available_size; 24 int overflow = (*position + *size) - available_size;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 86
90 // static 87 // static
91 void PlatformDevice::LoadTransformToCGContext(CGContextRef context, 88 void PlatformDevice::LoadTransformToCGContext(CGContextRef context,
92 const SkMatrix& matrix) { 89 const SkMatrix& matrix) {
93 // CoreGraphics can concatenate transforms, but not reset the current one. 90 // CoreGraphics can concatenate transforms, but not reset the current one.
94 // So in order to get the required behavior here, we need to first make 91 // So in order to get the required behavior here, we need to first make
95 // the current transformation matrix identity and only then load the new one. 92 // the current transformation matrix identity and only then load the new one.
96 93
97 // Reset matrix to identity. 94 // Reset matrix to identity.
98 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); 95 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context);
99 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix) ; 96 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(
97 orig_cg_matrix);
100 CGContextConcatCTM(context, orig_cg_matrix_inv); 98 CGContextConcatCTM(context, orig_cg_matrix_inv);
101 99
102 // assert that we have indeed returned to the identity Matrix. 100 // assert that we have indeed returned to the identity Matrix.
103 SkASSERT(CGAffineTransformIsIdentity(CGContextGetCTM(context))); 101 SkASSERT(CGAffineTransformIsIdentity(CGContextGetCTM(context)));
104 102
105 // Convert xform to CG-land. 103 // Convert xform to CG-land.
106 // Our coordinate system is flipped to match WebKit's so we need to modify 104 // Our coordinate system is flipped to match WebKit's so we need to modify
107 // the xform to match that. 105 // the xform to match that.
108 SkMatrix transformed_matrix = matrix; 106 SkMatrix transformed_matrix = matrix;
109 SkScalar sy = matrix.getScaleY() * (SkScalar)-1; 107 SkScalar sy = matrix.getScaleY() * (SkScalar)-1;
110 transformed_matrix.setScaleY(sy); 108 transformed_matrix.setScaleY(sy);
111 size_t height = CGBitmapContextGetHeight(context); 109 size_t height = CGBitmapContextGetHeight(context);
112 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. 110 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped.
113 transformed_matrix.setTranslateY(ty + (SkScalar)height); 111 transformed_matrix.setTranslateY(ty + (SkScalar)height);
114 112
115 CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); 113 CGAffineTransform cg_matrix = gfx::SkMatrixToCGAffineTransform(
114 transformed_matrix);
116 115
117 // Load final transform into context. 116 // Load final transform into context.
118 CGContextConcatCTM(context, cg_matrix); 117 CGContextConcatCTM(context, cg_matrix);
119 } 118 }
120 119
121 // static 120 // static
122 void PlatformDevice::LoadClippingRegionToCGContext( 121 void PlatformDevice::LoadClippingRegionToCGContext(
123 CGContextRef context, 122 CGContextRef context,
124 const SkRegion& region, 123 const SkRegion& region,
125 const SkMatrix& transformation) { 124 const SkMatrix& transformation) {
126 if (region.isEmpty()) { 125 if (region.isEmpty()) {
127 // region can be empty, in which case everything will be clipped. 126 // region can be empty, in which case everything will be clipped.
128 SkRect rect; 127 SkRect rect;
129 rect.setEmpty(); 128 rect.setEmpty();
130 CGContextClipToRect(context, SkRectToCGRect(rect)); 129 CGContextClipToRect(context, gfx::SkRectToCGRect(rect));
131 } else if (region.isRect()) { 130 } else if (region.isRect()) {
132 // Do the transformation. 131 // Do the transformation.
133 SkRect rect; 132 SkRect rect;
134 rect.set(region.getBounds()); 133 rect.set(region.getBounds());
135 transformation.mapRect(&rect); 134 transformation.mapRect(&rect);
136 SkIRect irect; 135 SkIRect irect;
137 rect.round(&irect); 136 rect.round(&irect);
138 CGContextClipToRect(context, SkIRectToCGRect(irect)); 137 CGContextClipToRect(context, gfx::SkIRectToCGRect(irect));
139 } else { 138 } else {
140 // It is complex. 139 // It is complex.
141 SkPath path; 140 SkPath path;
142 region.getBoundaryPath(&path); 141 region.getBoundaryPath(&path);
143 // Clip. Note that windows clipping regions are not affected by the 142 // Clip. Note that windows clipping regions are not affected by the
144 // transform so apply it manually. 143 // transform so apply it manually.
145 path.transform(transformation); 144 path.transform(transformation);
146 // TODO(playmobil): Implement. 145 // TODO(playmobil): Implement.
147 SkASSERT(false); 146 SkASSERT(false);
148 // LoadPathToDC(context, path); 147 // LoadPathToDC(context, path);
149 // hrgn = PathToRegion(context); 148 // hrgn = PathToRegion(context);
150 } 149 }
151 } 150 }
152 151
153 } // namespace skia 152 } // namespace skia
154 153
OLDNEW
« no previous file with comments | « skia/ext/image_operations.cc ('k') | webkit/glue/devtools/bound_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698