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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/skia/SkiaUtils.h

Issue 1810813002: [TEST] Non-oilpan build test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix #2 only Created 4 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/paint/SkPictureBuilder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 // All of the functions in this file should move to new homes and this file shou ld be deleted. 31 // All of the functions in this file should move to new homes and this file shou ld be deleted.
32 32
33 #ifndef SkiaUtils_h 33 #ifndef SkiaUtils_h
34 #define SkiaUtils_h 34 #define SkiaUtils_h
35 35
36 #include "platform/PlatformExport.h" 36 #include "platform/PlatformExport.h"
37 #include "platform/graphics/GraphicsTypes.h" 37 #include "platform/graphics/GraphicsTypes.h"
38 #include "platform/graphics/Image.h" 38 #include "platform/graphics/Image.h"
39 #include "platform/transforms/AffineTransform.h" 39 #include "platform/transforms/AffineTransform.h"
40 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
41 #include "third_party/skia/include/core/SkRefCnt.h"
41 #include "wtf/MathExtras.h" 42 #include "wtf/MathExtras.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 class GraphicsContext; 46 class GraphicsContext;
46 47
47 SkXfermode::Mode PLATFORM_EXPORT WebCoreCompositeToSkiaComposite(CompositeOperat or, WebBlendMode = WebBlendModeNormal); 48 SkXfermode::Mode PLATFORM_EXPORT WebCoreCompositeToSkiaComposite(CompositeOperat or, WebBlendMode = WebBlendModeNormal);
48 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode); 49 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode);
49 WebBlendMode PLATFORM_EXPORT blendModeFromSkia(SkXfermode::Mode); 50 WebBlendMode PLATFORM_EXPORT blendModeFromSkia(SkXfermode::Mode);
50 51
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width); 120 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width);
120 121
121 // TODO(fmalita): remove in favor of direct SrcRectConstraint use. 122 // TODO(fmalita): remove in favor of direct SrcRectConstraint use.
122 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image ::ImageClampingMode clampMode) 123 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image ::ImageClampingMode clampMode)
123 { 124 {
124 return clampMode == Image::ClampImageToSourceRect 125 return clampMode == Image::ClampImageToSourceRect
125 ? SkCanvas::kStrict_SrcRectConstraint 126 ? SkCanvas::kStrict_SrcRectConstraint
126 : SkCanvas::kFast_SrcRectConstraint; 127 : SkCanvas::kFast_SrcRectConstraint;
127 } 128 }
128 129
130
129 } // namespace blink 131 } // namespace blink
130 132
133 namespace WTF {
134
135 // Skia's smart pointer APIs are preferable over their legacy raw pointer counte rparts.
136 // The following helpers ensure interoperability between Skia's SkRefCnt wrapper sk_sp<T> and
137 // Blink's RefPtr<T>/PassRefPtr<T>.
138 //
139 // - adoptRef(sk_sp<T>): adopts an sk_sp rvalue into a PassRefPtr (to be used when
140 // transferring ownership from Skia to Blink).
141 // - adoptSkSp(PassRefPtr<T>): adopts a PassRefPtr rvalue into a sk_sp (to be used when
142 // transferring ownership from Blink to Skia).
143 //
144 // General guidelines
145 //
146 // When receiving ref counted objects from Skia:
147 //
148 // 1) use sk_sp-based Skia factories if available (e.g. SkShader::MakeFoo() in stead of
149 // SkShader::CreateFoo())
150 //
151 // 2) use sk_sp<T> locals for temporary objects (to be immediately transferred back to Skia)
152 //
153 // 3) use RefPtr<T>/PassRefPtr<T> for objects to be retained in Blink, use
154 // adoptRef(sk_sp<T>) to convert
155 //
156 // When passing ref counted objects to Skia:
157 //
158 // 1) use sk_sk-based Skia APIs when available (e.g. SkPaint::setShader(sk_sp< SkShader>)
159 // instead of SkPaint::setShader(SkShader*))
160 //
161 // 2) if the object ownership is being passed to Skia, use std::move(sk_sp<T>) or
162 // adoptSkSp(PassRefPtr<T>) to transfer without refcount churn
163 //
164 // 3) if the object ownership is shared with Skia (Blink retains a reference), use
165 // sk_ref_sp(RefPtr<T>::get())
166 //
167 // Example (creating a SkShader and setting it on SkPaint):
168 //
169 // a) legacy/old style
170 //
171 // RefPtr<SkShader> shader = adoptRef(SkShader::CreateFoo(...));
172 // paint.setShader(shader.get());
173 //
174 // (Note: the legacy approach introduces refcount churn as Skia grabs a ref whi le Blink is
175 // temporarily holding on to its own)
176 //
177 // b) new style, ownership transferred
178 //
179 // // using Skia smart pointer locals
180 // sk_sp<SkShader> shader = SkShader::MakeFoo(...);
181 // paint.setShader(std::move(shader));
182 //
183 // // using Blink smart pointer locals
184 // RefPtr<SkShader> shader = adoptRef(SkShader::MakeFoo(...));
185 // paint.setShader(adoptSkSp(shader.release());
186 //
187 // // using no locals
188 // paint.setShader(SkShader::MakeFoo(...));
189 //
190 // c) new style, shared ownership
191 //
192 // RefPtr<SkShader> m_shader = adoptRef(SkShader::MakeFoo(...));
193 // paint.setShader(adoptSkSp<SkShader>(m_shader));
194 //
195 template <typename T> PassRefPtr<T> adoptRef(sk_sp<T> sp)
196 {
197 return adoptRef(sp.release());
198 }
199
200 template <typename T> sk_sp<T> adoptSkSp(PassRefPtr<T> ref)
201 {
202 return sk_sp<T>(ref.leakRef());
203 }
204
205 } // namespace WTF
206
207 using WTF::adoptRef;
208 using WTF::adoptSkSp;
209
131 #endif // SkiaUtils_h 210 #endif // SkiaUtils_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/paint/SkPictureBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698