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

Side by Side Diff: core/cross/texture.cc

Issue 150058: expose bitmap in js. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « core/cross/texture.h ('k') | core/win/d3d9/renderer_d3d9.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 ClientInfoManager* client_info_manager = 83 ClientInfoManager* client_info_manager =
84 service_locator()->GetService<ClientInfoManager>(); 84 service_locator()->GetService<ClientInfoManager>();
85 client_info_manager->AdjustTextureMemoryUsed( 85 client_info_manager->AdjustTextureMemoryUsed(
86 -static_cast<int>(Bitmap::GetMipChainSize(width(), 86 -static_cast<int>(Bitmap::GetMipChainSize(width(),
87 height(), 87 height(),
88 format(), 88 format(),
89 levels()))); 89 levels())));
90 } 90 }
91 91
92 void Texture2D::DrawImage(Bitmap* src_img,
93 int src_x, int src_y,
94 int src_width, int src_height,
95 int dst_x, int dst_y,
96 int dst_width, int dst_height, int dest_mip) {
97 DCHECK(src_img->image_data());
98
99 int mip_width = std::max(1, width() >> dest_mip);
100 int mip_height = std::max(1, height() >> dest_mip);
101
102 // Clip source and destination rectangles to
103 // source and destination bitmaps.
104 // if src or dest rectangle is out of boundary,
105 // do nothing and return.
106 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y,
107 &src_width, &src_height,
108 src_img->width(), src_img->height(),
109 &dst_x, &dst_y,
110 &dst_width, &dst_height,
111 mip_width, mip_height))
112 return;
113
114 unsigned int components = 0;
115 // check formats of source and dest images.
116 // format of source and dest should be the same.
117 if (src_img->format() != format()) {
118 O3D_ERROR(service_locator()) << "DrawImage does not support "
119 << "different formats.";
120 return;
121 }
122 // if src and dest are in the same size and drawImage is copying
123 // the entire bitmap on dest image, just perform memcpy.
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 &&
126 src_width == src_img->width() && src_height == src_img->height() &&
127 dst_width == mip_width && dst_height == mip_height) {
128 void* data = NULL;
129 if (!Lock(dest_mip, &data))
130 return;
131
132 uint8* mip_data = static_cast<uint8*>(data);
133 unsigned int size = Bitmap::GetMipChainSize(mip_width, mip_height,
134 format(), 1);
135 memcpy(mip_data, src_img->image_data(), size);
136 this->Unlock(dest_mip);
137
138 return;
139 }
140 if (src_img->format() == Texture::XRGB8 ||
141 src_img->format() == Texture::ARGB8) {
142 components = 4;
143 } else {
144 O3D_ERROR(service_locator()) << "DrawImage does not support format: "
145 << src_img->format() << " unless src and "
146 << "dest images are in the same size and "
147 << "copying the entire bitmap";
148 return;
149 }
150
151 void* data = NULL;
152 if (!Lock(dest_mip, &data))
153 return;
154
155 uint8* src_img_data = src_img->image_data();
156 uint8* mip_data = static_cast<uint8*>(data);
157
158 Bitmap::BilinearInterpolateScale(src_img_data, src_x, src_y,
159 src_width, src_height,
160 src_img->width(), src_img->height(),
161 mip_data, dst_x, dst_y,
162 dst_width, dst_height,
163 mip_width, mip_height, components);
164
165 this->Unlock(dest_mip);
166 }
167
92 ObjectBase::Ref Texture2D::Create(ServiceLocator* service_locator) { 168 ObjectBase::Ref Texture2D::Create(ServiceLocator* service_locator) {
93 return ObjectBase::Ref(); 169 return ObjectBase::Ref();
94 } 170 }
95 171
96 Texture2DLockHelper::Texture2DLockHelper(Texture2D* texture, int level) 172 Texture2DLockHelper::Texture2DLockHelper(Texture2D* texture, int level)
97 : texture_(texture), 173 : texture_(texture),
98 level_(level), 174 level_(level),
99 data_(NULL), 175 data_(NULL),
100 locked_(false) { 176 locked_(false) {
101 } 177 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 -static_cast<int>(Bitmap::GetMipChainSize(edge_length(), 233 -static_cast<int>(Bitmap::GetMipChainSize(edge_length(),
158 edge_length(), 234 edge_length(),
159 format(), 235 format(),
160 levels()) * 6)); 236 levels()) * 6));
161 } 237 }
162 238
163 ObjectBase::Ref TextureCUBE::Create(ServiceLocator* service_locator) { 239 ObjectBase::Ref TextureCUBE::Create(ServiceLocator* service_locator) {
164 return ObjectBase::Ref(); 240 return ObjectBase::Ref();
165 } 241 }
166 242
243 void TextureCUBE::DrawImage(Bitmap* src_img,
244 int src_x, int src_y,
245 int src_width, int src_height,
246 int dst_x, int dst_y,
247 int dst_width, int dst_height,
248 CubeFace dest_face, int dest_mip) {
249 DCHECK(src_img->image_data());
250
251 int mip_length = std::max(1, edge_length() >> dest_mip);
252
253 // Clip source and destination rectangles to
254 // source and destination bitmaps.
255 // if src or dest rectangle is out of boundary,
256 // do nothing and return true.
257 if (!Bitmap::AdjustDrawImageBoundary(&src_x, &src_y,
258 &src_width, &src_height,
259 src_img->width(), src_img->height(),
260 &dst_x, &dst_y,
261 &dst_width, &dst_height,
262 mip_length, mip_length))
263 return;
264
265 unsigned int components = 0;
266 // check formats of source and dest images.
267 // format of source and dest should be the same.
268 if (src_img->format() != format()) {
269 O3D_ERROR(service_locator()) << "DrawImage does not support "
270 << "different formats.";
271 return;
272 }
273 // if src and dest are in the same size and drawImage is copying
274 // the entire bitmap on dest image, just perform memcpy.
275 if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 &&
276 src_img->width() == mip_length && src_img->height() == mip_length &&
277 src_width == src_img->width() && src_height == src_img->height() &&
278 dst_width == mip_length && dst_height == mip_length) {
279 // get mip data by lock method.
280 void* data = NULL;
281 if (!Lock(dest_face, dest_mip, &data))
282 return;
283
284 uint8* mip_data = static_cast<uint8*>(data);
285 unsigned int size = Bitmap::GetMipChainSize(mip_length, mip_length,
286 format(), 1);
287 memcpy(mip_data, src_img->image_data(), size);
288 this->Unlock(dest_face, dest_mip);
289
290 return;
291 }
292 if (src_img->format() == Texture::XRGB8 ||
293 src_img->format() == Texture::ARGB8) {
294 components = 4;
295 } else {
296 O3D_ERROR(service_locator()) << "DrawImage does not support format: "
297 << src_img->format() << " unless src and "
298 << "dest images are in the same size and "
299 << "copying the entire bitmap";
300 return;
301 }
302
303 void* data = NULL;
304 if (!Lock(dest_face, dest_mip, &data)) {
305 return;
306 }
307
308 uint8* src_img_data = src_img->image_data();
309 uint8* mip_data = static_cast<uint8*>(data);
310
311 Bitmap::BilinearInterpolateScale(src_img_data, src_x, src_y,
312 src_width, src_height,
313 src_img->width(), src_img->height(),
314 mip_data, dst_x, dst_y,
315 dst_width, dst_height,
316 mip_length, mip_length, components);
317
318 this->Unlock(dest_face, dest_mip);
319 }
320
167 } // namespace o3d 321 } // namespace o3d
OLDNEW
« no previous file with comments | « core/cross/texture.h ('k') | core/win/d3d9/renderer_d3d9.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698