| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 levels()))); | 89 levels()))); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void Texture2D::DrawImage(Bitmap* src_img, | 92 void Texture2D::DrawImage(Bitmap* src_img, |
| 93 int src_x, int src_y, | 93 int src_x, int src_y, |
| 94 int src_width, int src_height, | 94 int src_width, int src_height, |
| 95 int dst_x, int dst_y, | 95 int dst_x, int dst_y, |
| 96 int dst_width, int dst_height, int dest_mip) { | 96 int dst_width, int dst_height, int dest_mip) { |
| 97 DCHECK(src_img->image_data()); | 97 DCHECK(src_img->image_data()); |
| 98 | 98 |
| 99 int mip_width = std::max(1, width() >> dest_mip); | 99 unsigned int mip_width = std::max(1, width() >> dest_mip); |
| 100 int mip_height = std::max(1, height() >> dest_mip); | 100 unsigned int mip_height = std::max(1, height() >> dest_mip); |
| 101 | 101 |
| 102 // Clip source and destination rectangles to | 102 // Clip source and destination rectangles to |
| 103 // source and destination bitmaps. | 103 // source and destination bitmaps. |
| 104 // if src or dest rectangle is out of boundary, | 104 // if src or dest rectangle is out of boundary, |
| 105 // do nothing and return. | 105 // do nothing and return. |
| 106 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y, | 106 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y, |
| 107 &src_width, &src_height, | 107 &src_width, &src_height, |
| 108 src_img->width(), src_img->height(), | 108 src_img->width(), src_img->height(), |
| 109 &dst_x, &dst_y, | 109 &dst_x, &dst_y, |
| 110 &dst_width, &dst_height, | 110 &dst_width, &dst_height, |
| 111 mip_width, mip_height)) | 111 mip_width, mip_height)) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 unsigned int components = 0; | 114 unsigned int components = 0; |
| 115 // check formats of source and dest images. | 115 // check formats of source and dest images. |
| 116 // format of source and dest should be the same. | 116 // format of source and dest should be the same. |
| 117 if (src_img->format() != format()) { | 117 if (src_img->format() != format()) { |
| 118 O3D_ERROR(service_locator()) << "DrawImage does not support " | 118 O3D_ERROR(service_locator()) << "DrawImage does not support " |
| 119 << "different formats."; | 119 << "different formats."; |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 // if src and dest are in the same size and drawImage is copying | 122 // if src and dest are in the same size and drawImage is copying |
| 123 // the entire bitmap on dest image, just perform memcpy. | 123 // the entire bitmap on dest image, just perform memcpy. |
| 124 if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && | 124 if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && |
| 125 src_img->width() == mip_width && src_img->height() == mip_height && | 125 src_img->width() == mip_width && src_img->height() == mip_height && |
| 126 src_width == src_img->width() && src_height == src_img->height() && | 126 static_cast<unsigned int>(src_width) == src_img->width() && |
| 127 dst_width == mip_width && dst_height == mip_height) { | 127 static_cast<unsigned int>(src_height) == src_img->height() && |
| 128 static_cast<unsigned int>(dst_width) == mip_width && |
| 129 static_cast<unsigned int>(dst_height) == mip_height) { |
| 128 void* data = NULL; | 130 void* data = NULL; |
| 129 if (!Lock(dest_mip, &data)) | 131 if (!Lock(dest_mip, &data)) |
| 130 return; | 132 return; |
| 131 | 133 |
| 132 uint8* mip_data = static_cast<uint8*>(data); | 134 uint8* mip_data = static_cast<uint8*>(data); |
| 133 unsigned int size = Bitmap::GetMipChainSize(mip_width, mip_height, | 135 unsigned int size = Bitmap::GetMipChainSize(mip_width, mip_height, |
| 134 format(), 1); | 136 format(), 1); |
| 135 memcpy(mip_data, src_img->image_data(), size); | 137 memcpy(mip_data, src_img->image_data(), size); |
| 136 this->Unlock(dest_mip); | 138 this->Unlock(dest_mip); |
| 137 | 139 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 243 } |
| 242 | 244 |
| 243 void TextureCUBE::DrawImage(Bitmap* src_img, | 245 void TextureCUBE::DrawImage(Bitmap* src_img, |
| 244 int src_x, int src_y, | 246 int src_x, int src_y, |
| 245 int src_width, int src_height, | 247 int src_width, int src_height, |
| 246 int dst_x, int dst_y, | 248 int dst_x, int dst_y, |
| 247 int dst_width, int dst_height, | 249 int dst_width, int dst_height, |
| 248 CubeFace dest_face, int dest_mip) { | 250 CubeFace dest_face, int dest_mip) { |
| 249 DCHECK(src_img->image_data()); | 251 DCHECK(src_img->image_data()); |
| 250 | 252 |
| 251 int mip_length = std::max(1, edge_length() >> dest_mip); | 253 unsigned int mip_length = std::max(1, edge_length() >> dest_mip); |
| 252 | 254 |
| 253 // Clip source and destination rectangles to | 255 // Clip source and destination rectangles to |
| 254 // source and destination bitmaps. | 256 // source and destination bitmaps. |
| 255 // if src or dest rectangle is out of boundary, | 257 // if src or dest rectangle is out of boundary, |
| 256 // do nothing and return true. | 258 // do nothing and return true. |
| 257 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y, | 259 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y, |
| 258 &src_width, &src_height, | 260 &src_width, &src_height, |
| 259 src_img->width(), src_img->height(), | 261 src_img->width(), src_img->height(), |
| 260 &dst_x, &dst_y, | 262 &dst_x, &dst_y, |
| 261 &dst_width, &dst_height, | 263 &dst_width, &dst_height, |
| 262 mip_length, mip_length)) | 264 mip_length, mip_length)) |
| 263 return; | 265 return; |
| 264 | 266 |
| 265 unsigned int components = 0; | 267 unsigned int components = 0; |
| 266 // check formats of source and dest images. | 268 // check formats of source and dest images. |
| 267 // format of source and dest should be the same. | 269 // format of source and dest should be the same. |
| 268 if (src_img->format() != format()) { | 270 if (src_img->format() != format()) { |
| 269 O3D_ERROR(service_locator()) << "DrawImage does not support " | 271 O3D_ERROR(service_locator()) << "DrawImage does not support " |
| 270 << "different formats."; | 272 << "different formats."; |
| 271 return; | 273 return; |
| 272 } | 274 } |
| 273 // if src and dest are in the same size and drawImage is copying | 275 // if src and dest are in the same size and drawImage is copying |
| 274 // the entire bitmap on dest image, just perform memcpy. | 276 // the entire bitmap on dest image, just perform memcpy. |
| 275 if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && | 277 if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && |
| 276 src_img->width() == mip_length && src_img->height() == mip_length && | 278 src_img->width() == mip_length && src_img->height() == mip_length && |
| 277 src_width == src_img->width() && src_height == src_img->height() && | 279 static_cast<unsigned int>(src_width) == src_img->width() && |
| 278 dst_width == mip_length && dst_height == mip_length) { | 280 static_cast<unsigned int>(src_height) == src_img->height() && |
| 281 static_cast<unsigned int>(dst_width) == mip_length && |
| 282 static_cast<unsigned int>(dst_height) == mip_length) { |
| 279 // get mip data by lock method. | 283 // get mip data by lock method. |
| 280 void* data = NULL; | 284 void* data = NULL; |
| 281 if (!Lock(dest_face, dest_mip, &data)) | 285 if (!Lock(dest_face, dest_mip, &data)) |
| 282 return; | 286 return; |
| 283 | 287 |
| 284 uint8* mip_data = static_cast<uint8*>(data); | 288 uint8* mip_data = static_cast<uint8*>(data); |
| 285 unsigned int size = Bitmap::GetMipChainSize(mip_length, mip_length, | 289 unsigned int size = Bitmap::GetMipChainSize(mip_length, mip_length, |
| 286 format(), 1); | 290 format(), 1); |
| 287 memcpy(mip_data, src_img->image_data(), size); | 291 memcpy(mip_data, src_img->image_data(), size); |
| 288 this->Unlock(dest_face, dest_mip); | 292 this->Unlock(dest_face, dest_mip); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 312 src_width, src_height, | 316 src_width, src_height, |
| 313 src_img->width(), src_img->height(), | 317 src_img->width(), src_img->height(), |
| 314 mip_data, dst_x, dst_y, | 318 mip_data, dst_x, dst_y, |
| 315 dst_width, dst_height, | 319 dst_width, dst_height, |
| 316 mip_length, mip_length, components); | 320 mip_length, mip_length, components); |
| 317 | 321 |
| 318 this->Unlock(dest_face, dest_mip); | 322 this->Unlock(dest_face, dest_mip); |
| 319 } | 323 } |
| 320 | 324 |
| 321 } // namespace o3d | 325 } // namespace o3d |
| OLD | NEW |