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

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

Issue 1814473003: Revert of Add sk_sp helpers and switch Blink SkShader clients to the new APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
42 #include "wtf/MathExtras.h" 41 #include "wtf/MathExtras.h"
43 42
44 namespace blink { 43 namespace blink {
45 44
46 class GraphicsContext; 45 class GraphicsContext;
47 46
48 SkXfermode::Mode PLATFORM_EXPORT WebCoreCompositeToSkiaComposite(CompositeOperat or, WebBlendMode = WebBlendModeNormal); 47 SkXfermode::Mode PLATFORM_EXPORT WebCoreCompositeToSkiaComposite(CompositeOperat or, WebBlendMode = WebBlendModeNormal);
49 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode); 48 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode);
50 WebBlendMode PLATFORM_EXPORT blendModeFromSkia(SkXfermode::Mode); 49 WebBlendMode PLATFORM_EXPORT blendModeFromSkia(SkXfermode::Mode);
51 50
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width); 119 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width);
121 120
122 // TODO(fmalita): remove in favor of direct SrcRectConstraint use. 121 // TODO(fmalita): remove in favor of direct SrcRectConstraint use.
123 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image ::ImageClampingMode clampMode) 122 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint(Image ::ImageClampingMode clampMode)
124 { 123 {
125 return clampMode == Image::ClampImageToSourceRect 124 return clampMode == Image::ClampImageToSourceRect
126 ? SkCanvas::kStrict_SrcRectConstraint 125 ? SkCanvas::kStrict_SrcRectConstraint
127 : SkCanvas::kFast_SrcRectConstraint; 126 : SkCanvas::kFast_SrcRectConstraint;
128 } 127 }
129 128
130
131 // Skia's smart pointer APIs are preferable over their legacy raw pointer counte rparts.
132 // The following helpers ensure interoperability between Skia's SkRefCnt wrapper sk_sp<T> and
133 // Blink's RefPtr<T>/PassRefPtr<T>.
134 //
135 // - adoptRef(sk_sp<T>): adopts an sk_sp rvalue into a PassRefPtr (to be used when
136 // transferring ownership from Skia to Blink).
137 // - adoptSkSp(PassRefPtr<T>): adopts a PassRefPtr rvalue into a sk_sp (to be used when
138 // transferring ownership from Blink to Skia).
139 //
140 // General guidelines
141 //
142 // When receiving ref counted objects from Skia:
143 //
144 // 1) use sk_sp-based Skia factories if available (e.g. SkShader::MakeFoo() in stead of
145 // SkShader::CreateFoo())
146 //
147 // 2) use sk_sp<T> locals for temporary objects (to be immediately transferred back to Skia)
148 //
149 // 3) use RefPtr<T>/PassRefPtr<T> for objects to be retained in Blink, use
150 // adoptRef(sk_sp<T>) to convert
151 //
152 // When passing ref counted objects to Skia:
153 //
154 // 1) use sk_sk-based Skia APIs when available (e.g. SkPaint::setShader(sk_sp< SkShader>)
155 // instead of SkPaint::setShader(SkShader*))
156 //
157 // 2) if the object ownership is being passed to Skia, use std::move(sk_sp<T>) or
158 // adoptSkSp(PassRefPtr<T>) to transfer without refcount churn
159 //
160 // 3) if the object ownership is shared with Skia (Blink retains a reference), use
161 // sk_ref_sp(RefPtr<T>::get())
162 //
163 // Example (creating a SkShader and setting it on SkPaint):
164 //
165 // a) legacy/old style
166 //
167 // RefPtr<SkShader> shader = adoptRef(SkShader::CreateFoo(...));
168 // paint.setShader(shader.get());
169 //
170 // (Note: the legacy approach introduces refcount churn as Skia grabs a ref whi le Blink is
171 // temporarily holding on to its own)
172 //
173 // b) new style, ownership transferred
174 //
175 // // using Skia smart pointer locals
176 // sk_sp<SkShader> shader = SkShader::MakeFoo(...);
177 // paint.setShader(std::move(shader));
178 //
179 // // using Blink smart pointer locals
180 // RefPtr<SkShader> shader = adoptRef(SkShader::MakeFoo(...));
181 // paint.setShader(adoptSkSp(shader.release());
182 //
183 // // using no locals
184 // paint.setShader(SkShader::MakeFoo(...));
185 //
186 // c) new style, shared ownership
187 //
188 // RefPtr<SkShader> m_shader = adoptRef(SkShader::MakeFoo(...));
189 // paint.setShader(adoptSkSp<SkShader>(m_shader));
190 //
191 template <typename T> PassRefPtr<T> adoptRef(sk_sp<T> sp)
192 {
193 return adoptRef(sp.release());
194 }
195
196 template <typename T> sk_sp<T> adoptSkSp(PassRefPtr<T> ref)
197 {
198 return sk_sp<T>(ref.leakRef());
199 }
200
201 } // namespace blink 129 } // namespace blink
202 130
203 #endif // SkiaUtils_h 131 #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