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

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

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 | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_family.h » ('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 #include "ui/gfx/image/image.h" 5 #include "ui/gfx/image/image.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/threading/thread_checker.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/image/image_png_rep.h" 18 #include "ui/gfx/image/image_png_rep.h"
18 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/image/image_skia_source.h" 20 #include "ui/gfx/image/image_skia_source.h"
20 21
21 #if !defined(OS_IOS) 22 #if !defined(OS_IOS)
22 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
23 #endif 24 #endif
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 : default_representation_type_(default_type) 351 : default_representation_type_(default_type)
351 #if defined(OS_MACOSX) && !defined(OS_IOS) 352 #if defined(OS_MACOSX) && !defined(OS_IOS)
352 , 353 ,
353 default_representation_color_space_( 354 default_representation_color_space_(
354 base::mac::GetGenericRGBColorSpace()) 355 base::mac::GetGenericRGBColorSpace())
355 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 356 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
356 { 357 {
357 } 358 }
358 359
359 Image::RepresentationType default_representation_type() { 360 Image::RepresentationType default_representation_type() {
361 CheckCalledOnValidThread();
360 return default_representation_type_; 362 return default_representation_type_;
361 } 363 }
362 Image::RepresentationMap& representations() { return representations_; } 364 Image::RepresentationMap& representations() {
365 CheckCalledOnValidThread();
366 return representations_;
367 }
363 368
364 #if defined(OS_MACOSX) && !defined(OS_IOS) 369 #if defined(OS_MACOSX) && !defined(OS_IOS)
365 void set_default_representation_color_space(CGColorSpaceRef color_space) { 370 void set_default_representation_color_space(CGColorSpaceRef color_space) {
371 CheckCalledOnValidThread();
366 default_representation_color_space_ = color_space; 372 default_representation_color_space_ = color_space;
367 } 373 }
368 CGColorSpaceRef default_representation_color_space() { 374 CGColorSpaceRef default_representation_color_space() {
375 CheckCalledOnValidThread();
369 return default_representation_color_space_; 376 return default_representation_color_space_;
370 } 377 }
371 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 378 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
372 379
380 void DisableThreadChecking() {
381 thread_checking_disabled_ = true;
382 }
383
384 void DetachFromThread() {
385 thread_checker_.DetachFromThread();
386 }
387
388 // DCHECKs that the current thread matches the valid thread in
389 // |thread_checker_|.
390 void CheckCalledOnValidThread() const {
391 if (!thread_checking_disabled_)
392 DCHECK(thread_checker_.CalledOnValidThread());
393 }
394
373 private: 395 private:
374 friend class base::RefCounted<ImageStorage>; 396 friend class base::RefCounted<ImageStorage>;
375 397
376 ~ImageStorage() {} 398 ~ImageStorage() {
399 CheckCalledOnValidThread();
400 }
377 401
378 // The type of image that was passed to the constructor. This key will always 402 // The type of image that was passed to the constructor. This key will always
379 // exist in the |representations_| map. 403 // exist in the |representations_| map.
380 Image::RepresentationType default_representation_type_; 404 Image::RepresentationType default_representation_type_;
381 405
382 #if defined(OS_MACOSX) && !defined(OS_IOS) 406 #if defined(OS_MACOSX) && !defined(OS_IOS)
383 // The default representation's colorspace. This is used for converting to 407 // The default representation's colorspace. This is used for converting to
384 // NSImage. This field exists to compensate for PNGCodec not writing or 408 // NSImage. This field exists to compensate for PNGCodec not writing or
385 // reading colorspace ancillary chunks. (sRGB, iCCP). 409 // reading colorspace ancillary chunks. (sRGB, iCCP).
386 // Not owned. 410 // Not owned.
387 CGColorSpaceRef default_representation_color_space_; 411 CGColorSpaceRef default_representation_color_space_;
388 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 412 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
389 413
390 // All the representations of an Image. Size will always be at least one, with 414 // All the representations of an Image. Size will always be at least one, with
391 // more for any converted representations. 415 // more for any converted representations.
392 Image::RepresentationMap representations_; 416 Image::RepresentationMap representations_;
393 417
418 bool thread_checking_disabled_ = false;
419
420 // Used to verify that Images are not used from different threads at the same
421 // time, in Debug builds.
422 base::ThreadChecker thread_checker_;
423
394 DISALLOW_COPY_AND_ASSIGN(ImageStorage); 424 DISALLOW_COPY_AND_ASSIGN(ImageStorage);
395 }; 425 };
396 426
397 } // namespace internal 427 } // namespace internal
398 428
399 Image::Image() { 429 Image::Image() {
400 // |storage_| is NULL for empty Images. 430 // |storage_| is NULL for empty Images.
401 } 431 }
402 432
403 Image::Image(const std::vector<ImagePNGRep>& image_reps) { 433 Image::Image(const std::vector<ImagePNGRep>& image_reps) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 storage_.swap(other->storage_); 763 storage_.swap(other->storage_);
734 } 764 }
735 765
736 #if defined(OS_MACOSX) && !defined(OS_IOS) 766 #if defined(OS_MACOSX) && !defined(OS_IOS)
737 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { 767 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) {
738 if (storage_.get()) 768 if (storage_.get())
739 storage_->set_default_representation_color_space(color_space); 769 storage_->set_default_representation_color_space(color_space);
740 } 770 }
741 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 771 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
742 772
773 void Image::DisableThreadChecking() {
774 storage_->DisableThreadChecking();
775 }
776
777 void Image::DetachFromThread() {
778 storage_->DetachFromThread();
779 }
780
743 Image::RepresentationType Image::DefaultRepresentationType() const { 781 Image::RepresentationType Image::DefaultRepresentationType() const {
744 CHECK(storage_.get()); 782 CHECK(storage_.get());
745 return storage_->default_representation_type(); 783 return storage_->default_representation_type();
746 } 784 }
747 785
748 internal::ImageRep* Image::GetRepresentation( 786 internal::ImageRep* Image::GetRepresentation(
749 RepresentationType rep_type, bool must_exist) const { 787 RepresentationType rep_type, bool must_exist) const {
750 CHECK(storage_.get()); 788 CHECK(storage_.get());
751 RepresentationMap::const_iterator it = 789 RepresentationMap::const_iterator it =
752 storage_->representations().find(rep_type); 790 storage_->representations().find(rep_type);
(...skipping 12 matching lines...) Expand all
765 storage_->representations().insert(std::make_pair(type, std::move(rep))); 803 storage_->representations().insert(std::make_pair(type, std::move(rep)));
766 804
767 // insert should not fail (implies that there was already a representation of 805 // insert should not fail (implies that there was already a representation of
768 // that type in the map). 806 // that type in the map).
769 CHECK(result.second) << "type was already in map."; 807 CHECK(result.second) << "type was already in map.";
770 808
771 return result.first->second.get(); 809 return result.first->second.get();
772 } 810 }
773 811
774 } // namespace gfx 812 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_family.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698