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

Side by Side Diff: ui/gfx/image/image.h

Issue 1771033003: gfx::Image: Added thread checker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove UpdateShortcutWorker changes; instead just disable thread checking. Created 3 years, 5 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 | « chrome/browser/web_applications/web_app_win.cc ('k') | ui/gfx/image/image.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) 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 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage, 5 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage,
6 // or a SkBitmap. This also provides easy conversion to other image types 6 // or a SkBitmap. This also provides easy conversion to other image types
7 // through operator overloading. It will cache the converted representations 7 // through operator overloading. It will cache the converted representations
8 // internally to prevent double-conversion. 8 // internally to prevent double-conversion.
9 // 9 //
10 // The lifetime of both the initial representation and any converted ones are 10 // The lifetime of both the initial representation and any converted ones are
11 // tied to the lifetime of the Image's internal storage. To allow Images to be 11 // tied to the lifetime of the Image's internal storage. To allow Images to be
12 // cheaply passed around by value, the actual image data is stored in a ref- 12 // cheaply passed around by value, the actual image data is stored in a ref-
13 // counted member. When all Images referencing this storage are deleted, the 13 // counted member. When all Images referencing this storage are deleted, the
14 // actual representations are deleted, too. 14 // actual representations are deleted, too.
15 // 15 //
16 // Images can be empty, in which case they have no backing representation. 16 // Images can be empty, in which case they have no backing representation.
17 // Attempting to use an empty Image will result in a crash. 17 // Attempting to use an empty Image will result in a crash.
18 //
19 // Image is *not thread-safe* for reads or writes. In Debug builds, a thread
20 // checker will check that Images are not being used across multiple threads. If
21 // you need to pass an image from one thread to another, you have two options:
22 // 1. Ensure that you are the sole reference holder of the Image (keeping in
23 // mind that if the Image has been copied that the place you copied it from
24 // will hold a reference to it), and call DetachFromThread() just before
25 // passing the Image to another thread.
26 // 2. Get the underlying image representation (e.g., ImageSkia) out of the
27 // image, ensure that it is thread-safe (ImageSkia requires special attention
28 // to make it thread-safe), pass that to another thread, then create a new
29 // Image object on the other side.
18 30
19 #ifndef UI_GFX_IMAGE_IMAGE_H_ 31 #ifndef UI_GFX_IMAGE_IMAGE_H_
20 #define UI_GFX_IMAGE_IMAGE_H_ 32 #define UI_GFX_IMAGE_IMAGE_H_
21 33
22 #include <stddef.h> 34 #include <stddef.h>
23 35
24 #include <map> 36 #include <map>
25 #include <memory> 37 #include <memory>
26 #include <vector> 38 #include <vector>
27 39
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Swaps this image's internal representations with |other|. 184 // Swaps this image's internal representations with |other|.
173 void SwapRepresentations(gfx::Image* other); 185 void SwapRepresentations(gfx::Image* other);
174 186
175 #if defined(OS_MACOSX) && !defined(OS_IOS) 187 #if defined(OS_MACOSX) && !defined(OS_IOS)
176 // Set the default representation's color space. This is used for converting 188 // Set the default representation's color space. This is used for converting
177 // to NSImage. This is used to compensate for PNGCodec not writing or reading 189 // to NSImage. This is used to compensate for PNGCodec not writing or reading
178 // colorspace ancillary chunks. (sRGB, iCCP). 190 // colorspace ancillary chunks. (sRGB, iCCP).
179 void SetSourceColorSpace(CGColorSpaceRef color_space); 191 void SetSourceColorSpace(CGColorSpaceRef color_space);
180 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 192 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
181 193
194 // Turns off thread checking on this Image (and all Images sharing its backing
195 // store). This should be used to mark code that is not currently thread-safe
196 // and any usage of this method should be considered a bug and accompanied by
197 // a TODO.
198 // TODO(mgiuca): Remove this method after all uses of Image are thread-safe.
199 void DisableThreadChecking();
200
201 // Informs the thread checker that this Image is about to be moved to another
202 // thread. Should only be used when this Image is the sole reference holder of
203 // its backing store.
204 void DetachFromThread();
205
182 private: 206 private:
183 // Returns the type of the default representation. 207 // Returns the type of the default representation.
184 RepresentationType DefaultRepresentationType() const; 208 RepresentationType DefaultRepresentationType() const;
185 209
186 // Returns the ImageRep of the appropriate type or NULL if there is no 210 // Returns the ImageRep of the appropriate type or NULL if there is no
187 // representation of that type (and must_exist is false). 211 // representation of that type (and must_exist is false).
188 internal::ImageRep* GetRepresentation( 212 internal::ImageRep* GetRepresentation(
189 RepresentationType rep_type, bool must_exist) const; 213 RepresentationType rep_type, bool must_exist) const;
190 214
191 // Stores a representation into the map. A representation of that type must 215 // Stores a representation into the map. A representation of that type must
192 // not already be in the map. Returns a pointer to the representation stored 216 // not already be in the map. Returns a pointer to the representation stored
193 // inside the map. 217 // inside the map.
194 internal::ImageRep* AddRepresentation( 218 internal::ImageRep* AddRepresentation(
195 std::unique_ptr<internal::ImageRep> rep) const; 219 std::unique_ptr<internal::ImageRep> rep) const;
196 220
197 // Internal class that holds all the representations. This allows the Image to 221 // Internal class that holds all the representations. This allows the Image to
198 // be cheaply copied. 222 // be cheaply copied.
199 scoped_refptr<internal::ImageStorage> storage_; 223 scoped_refptr<internal::ImageStorage> storage_;
200 }; 224 };
201 225
202 } // namespace gfx 226 } // namespace gfx
203 227
204 #endif // UI_GFX_IMAGE_IMAGE_H_ 228 #endif // UI_GFX_IMAGE_IMAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_win.cc ('k') | ui/gfx/image/image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698