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 SPRITE_H_ | |
6 #define SPRITE_H_ | |
7 | |
8 #include <vector> | |
9 #include "boost/scoped_ptr.hpp" | |
10 #include "boost/noncopyable.hpp" | |
11 #include "ppapi/cpp/point.h" | |
12 #include "ppapi/cpp/rect.h" | |
13 #include "ppapi/cpp/size.h" | |
14 | |
15 namespace flocking_geese { | |
16 | |
17 // A Sprite is a simple container of a pixel buffer. It knows how to | |
18 // composite itself to another pixel buffer of the same format. | |
19 class Sprite : public boost::noncopyable { | |
20 public: | |
21 // Initialize a Sprite to use the attached pixel buffer. The Sprite takes | |
22 // ownership of the pixel buffer, deleting it in the dtor. The pixel | |
23 // buffer is assumed to be 32-bit ARGB-8-8-8-8 pixel format, with pre- | |
24 // multiplied alpha. If |row_bytes| is 0, then the number of bytes per row | |
25 // is assumed to be size.width() * sizeof(uint32_t). | |
26 Sprite(uint32_t* pixel_buffer, const pp::Size& size, int32_t row_bytes); | |
27 | |
28 // Delete the pixel buffer. It is assumed that the pixel buffer was created | |
29 // using malloc(). | |
30 ~Sprite() {} | |
31 | |
32 // Reset the internal pixel buffer to a new one. Deletes the old pixel | |
33 // buffer. Sprite takes ownership of the new pixel buffer. If |row_bytes| | |
34 // is 0, then the number of bytes per row is assumed to be size.width() * | |
35 // sizeof(uint32_t). | |
36 void SetPixelBuffer(uint32_t* pixel_buffer, | |
37 const pp::Size& size, | |
38 int32_t row_bytes); | |
39 | |
40 // Composite the section of the Sprite contained in |src_rect| into the given | |
41 // pixel buffer at |dest_point|. Performs a "source-over" composite | |
42 // operation, and all necessary clipping. Assumes pre-mulitplied alpha. | |
43 void CompositeFromRectToPoint(const pp::Rect& src_rect, | |
44 uint32_t* dest_pixel_buffer, | |
45 const pp::Rect& dest_bounds, | |
46 int32_t dest_row_bytes, | |
47 const pp::Point& dest_point) const; | |
48 | |
49 // Accessors. | |
50 const pp::Size& size() const { | |
51 return pixel_buffer_size_; | |
52 } | |
53 | |
54 private: | |
55 boost::scoped_ptr<uint32_t> pixel_buffer_; | |
56 pp::Size pixel_buffer_size_; | |
57 int32_t row_bytes_; | |
58 | |
59 // Not implemented, do not use. | |
60 Sprite(); | |
61 }; | |
62 | |
63 } // namespace flocking_geese | |
64 | |
65 #endif // SPRITE_H_ | |
OLD | NEW |