OLD | NEW |
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 "ppapi/cpp/image_data.h" | 5 #include "ppapi/cpp/image_data.h" |
6 | 6 |
7 #include <string.h> // Needed for memset. | 7 #include <string.h> // Needed for memset. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return const_cast<ImageData*>(this)->GetAddr32(coord); | 67 return const_cast<ImageData*>(this)->GetAddr32(coord); |
68 } | 68 } |
69 | 69 |
70 uint32_t* ImageData::GetAddr32(const Point& coord) { | 70 uint32_t* ImageData::GetAddr32(const Point& coord) { |
71 // If we add more image format types that aren't 32-bit, we'd want to check | 71 // If we add more image format types that aren't 32-bit, we'd want to check |
72 // here and fail. | 72 // here and fail. |
73 return reinterpret_cast<uint32_t*>( | 73 return reinterpret_cast<uint32_t*>( |
74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]); | 74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]); |
75 } | 75 } |
76 | 76 |
| 77 bool ImageData::Contains(const pp::Rect& rect) const { |
| 78 return rect.width() >= 0 && rect.height() >= 0 && |
| 79 pp::Rect(size()).Contains(rect); |
| 80 } |
| 81 |
77 // static | 82 // static |
78 bool ImageData::IsImageDataFormatSupported(PP_ImageDataFormat format) { | 83 bool ImageData::IsImageDataFormatSupported(PP_ImageDataFormat format) { |
79 if (!has_interface<PPB_ImageData_1_0>()) | 84 if (!has_interface<PPB_ImageData_1_0>()) |
80 return false; | 85 return false; |
81 return PP_ToBool(get_interface<PPB_ImageData_1_0>()-> | 86 return PP_ToBool(get_interface<PPB_ImageData_1_0>()-> |
82 IsImageDataFormatSupported(format)); | 87 IsImageDataFormatSupported(format)); |
83 } | 88 } |
84 | 89 |
85 // static | 90 // static |
86 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { | 91 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { |
87 if (!has_interface<PPB_ImageData_1_0>()) | 92 if (!has_interface<PPB_ImageData_1_0>()) |
88 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. | 93 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. |
89 return get_interface<PPB_ImageData_1_0>()->GetNativeImageDataFormat(); | 94 return get_interface<PPB_ImageData_1_0>()->GetNativeImageDataFormat(); |
90 } | 95 } |
91 | 96 |
92 void ImageData::InitData() { | 97 void ImageData::InitData() { |
93 if (!has_interface<PPB_ImageData_1_0>()) | 98 if (!has_interface<PPB_ImageData_1_0>()) |
94 return; | 99 return; |
95 if (get_interface<PPB_ImageData_1_0>()->Describe(pp_resource(), &desc_)) { | 100 if (get_interface<PPB_ImageData_1_0>()->Describe(pp_resource(), &desc_)) { |
96 data_ = get_interface<PPB_ImageData_1_0>()->Map(pp_resource()); | 101 data_ = get_interface<PPB_ImageData_1_0>()->Map(pp_resource()); |
97 if (data_) | 102 if (data_) |
98 return; | 103 return; |
99 } | 104 } |
100 *this = ImageData(); | 105 *this = ImageData(); |
101 } | 106 } |
102 | 107 |
103 } // namespace pp | 108 } // namespace pp |
OLD | NEW |