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

Unified Diff: core/cross/pack.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/cross/pack.h ('k') | core/cross/renderer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/cross/pack.cc
===================================================================
--- core/cross/pack.cc (revision 20557)
+++ core/cross/pack.cc (working copy)
@@ -135,14 +135,14 @@
// TODO: Add support for volume texture when we have code to load
// them
- Bitmap bitmap;
- if (!bitmap.LoadFromFile(filepath, file_type, generate_mipmaps)) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (!bitmap->LoadFromFile(filepath, file_type, generate_mipmaps)) {
O3D_ERROR(service_locator())
<< "Failed to load bitmap file \"" << uri << "\"";
return NULL;
}
- return CreateTextureFromBitmap(&bitmap, uri);
+ return CreateTextureFromBitmap(bitmap, uri);
}
// Creates a Texture object from a file in the current render context format.
@@ -198,7 +198,6 @@
return texture.Get();
}
-
// Creates a Texture object from RawData and allocates
// the necessary resources for it.
Texture* Pack::CreateTextureFromRawData(RawData *raw_data,
@@ -213,16 +212,55 @@
DLOG(INFO) << "CreateTextureFromRawData(uri='" << uri << "')";
- Bitmap bitmap;
- if (!bitmap.LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) {
O3D_ERROR(service_locator())
<< "Failed to load bitmap from raw data \"" << uri << "\"";
return NULL;
}
- return CreateTextureFromBitmap(&bitmap, uri);
+ return CreateTextureFromBitmap(bitmap, uri);
}
+// Create a bitmap object.
+Bitmap* Pack::CreateBitmap(int width, int height,
+ Texture::Format format) {
+ DCHECK(Bitmap::CheckImageDimensions(width, height));
+
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (bitmap.IsNull()) {
+ O3D_ERROR(service_locator())
+ << "Failed to create bitmap object.";
+ return NULL;
+ }
+ bitmap->Allocate(format, width, height, 1, false);
+ if (!bitmap->image_data()) {
+ O3D_ERROR(service_locator())
+ << "Failed to allocate memory for bitmap.";
+ return NULL;
+ }
+ RegisterObject(bitmap);
+ return bitmap.Get();
+}
+
+// Create a new bitmap object from rawdata.
+Bitmap* Pack::CreateBitmapFromRawData(RawData* raw_data) {
+ Bitmap::Ref bitmap(new Bitmap(service_locator()));
+ if (bitmap.IsNull()) {
+ O3D_ERROR(service_locator())
+ << "Failed to create bitmap object.";
+ return NULL;
+ }
+ if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN,
+ false)) {
+ O3D_ERROR(service_locator())
+ << "Failed to load bitmap from raw data.";
+ return NULL;
+ }
+ RegisterObject(bitmap);
+ return bitmap.Get();
+}
+
// Creates a Texture2D object and allocates the necessary resources for it.
Texture2D* Pack::CreateTexture2D(int width,
int height,
« no previous file with comments | « core/cross/pack.h ('k') | core/cross/renderer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698