OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SCOPED_PIXEL_LOCK_H_ | |
6 #define SCOPED_PIXEL_LOCK_H_ | |
7 | |
8 #include <tr1/memory> | |
9 #include "nacl_app/locking_image_data.h" | |
10 | |
11 namespace flocking_geese { | |
12 | |
13 // A small helper RAII class used to acquire and release the pixel lock based | |
14 // on C++ scoping rules. | |
15 class ScopedPixelLock { | |
16 public: | |
17 explicit ScopedPixelLock( | |
18 const std::tr1::shared_ptr<LockingImageData>& pixel_owner) | |
19 : pixel_owner_(pixel_owner) { | |
20 pixels_ = pixel_owner_ == NULL ? NULL : pixel_owner->LockPixels(); | |
21 } | |
22 | |
23 ~ScopedPixelLock() { | |
24 pixels_ = NULL; | |
25 if (pixel_owner_ != NULL) | |
26 pixel_owner_->UnlockPixels(); | |
27 } | |
28 | |
29 bool is_valid() const { | |
30 return pixels_ != NULL; | |
31 } | |
32 | |
33 uint32_t* pixels() const { | |
34 return pixels_; | |
35 } | |
36 | |
37 private: | |
38 std::tr1::shared_ptr<LockingImageData> pixel_owner_; | |
39 uint32_t* pixels_; // Weak reference. | |
40 }; | |
41 } // namespace flocking_geese | |
42 | |
43 #endif // SCOPED_PIXEL_LOCK_H_ | |
44 | |
OLD | NEW |