summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/examples/demo
diff options
context:
space:
mode:
authornfullagar@chromium.org <nfullagar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-14 00:14:29 +0000
committernfullagar@chromium.org <nfullagar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-14 00:14:29 +0000
commit38c4e8d77f662c264fbc0770fe9ee204f1297028 (patch)
tree04ed3e497ae3aafade1b5555c54f0ac3dec984e4 /native_client_sdk/src/examples/demo
parent1083e92ecea415fce294376143fca8b11f73f90c (diff)
downloadchromium_src-38c4e8d77f662c264fbc0770fe9ee204f1297028.zip
chromium_src-38c4e8d77f662c264fbc0770fe9ee204f1297028.tar.gz
chromium_src-38c4e8d77f662c264fbc0770fe9ee204f1297028.tar.bz2
Change ppapi_simple to support pixel format selection.
Update examples to select specific format. BUG=272346 TEST=run examples, trybots R=noelallen@chromium.org Review URL: https://codereview.chromium.org/22824010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/examples/demo')
-rw-r--r--native_client_sdk/src/examples/demo/earth/earth.cc11
-rw-r--r--native_client_sdk/src/examples/demo/flock/flock.cc2
-rw-r--r--native_client_sdk/src/examples/demo/life/life.c39
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc2
-rw-r--r--native_client_sdk/src/examples/demo/voronoi/voronoi.cc13
5 files changed, 35 insertions, 32 deletions
diff --git a/native_client_sdk/src/examples/demo/earth/earth.cc b/native_client_sdk/src/examples/demo/earth/earth.cc
index 2a1c958..559cc79 100644
--- a/native_client_sdk/src/examples/demo/earth/earth.cc
+++ b/native_client_sdk/src/examples/demo/earth/earth.cc
@@ -60,7 +60,7 @@ inline double getseconds() {
return 0.0;
}
-// RGBA helper functions.
+// RGBA helper functions, used for extracting color from RGBA source image.
inline float ExtractR(uint32_t c) {
return static_cast<float>(c & 0xFF) * kOneOver255;
}
@@ -73,7 +73,8 @@ inline float ExtractB(uint32_t c) {
return static_cast<float>((c & 0xFF0000) >> 16) * kOneOver255;
}
-inline uint32_t MakeRGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a) {
+// BGRA helper function, for constructing a pixel for a BGRA buffer.
+inline uint32_t MakeBGRA(uint32_t b, uint32_t g, uint32_t r, uint32_t a) {
return (((a) << 24) | ((r) << 16) | ((g) << 8) | (b));
}
@@ -353,7 +354,7 @@ Planet::Planet() : base_tex_(NULL), night_tex_(NULL), num_threads_(0),
// By default, render from the dispatch thread.
workers_ = new ThreadPool(num_threads_);
PSEventSetFilter(PSE_ALL);
- ps_context_ = PSContext2DAllocate();
+ ps_context_ = PSContext2DAllocate(PP_IMAGEDATAFORMAT_BGRA_PREMUL);
}
Planet::~Planet() {
@@ -382,7 +383,7 @@ inline uint32_t* Planet::wGetAddr(int x, int y) {
void Planet::wRenderPixelSpan(int x0, int x1, int y) {
if (!base_tex_ || !night_tex_)
return;
- const int kColorBlack = MakeRGBA(0, 0, 0, 0xFF);
+ const int kColorBlack = MakeBGRA(0, 0, 0, 0xFF);
float width = ps_context_->width;
float height = ps_context_->height;
float min_dim = width < height ? width : height;
@@ -495,7 +496,7 @@ void Planet::wRenderPixelSpan(int x0, int x1, int y) {
unsigned int ig = Clamp255(pg * tg + ng * ipg);
unsigned int ib = Clamp255(pb * tb + nb * ipb);
- unsigned int color = MakeRGBA(ir, ig, ib, 0xFF);
+ unsigned int color = MakeBGRA(ib, ig, ir, 0xFF);
*pixels = color;
++pixels;
diff --git a/native_client_sdk/src/examples/demo/flock/flock.cc b/native_client_sdk/src/examples/demo/flock/flock.cc
index 94707a0..9e1a639 100644
--- a/native_client_sdk/src/examples/demo/flock/flock.cc
+++ b/native_client_sdk/src/examples/demo/flock/flock.cc
@@ -116,7 +116,7 @@ int example_main(int argc, char *argv[]) {
g_goose_sprite = new Sprite(buffer, pp::Size(fmt.width, fmt.height), 0);
- PSContext2D_t* ctx = PSContext2DAllocate();
+ PSContext2D_t* ctx = PSContext2DAllocate(PP_IMAGEDATAFORMAT_BGRA_PREMUL);
ResetFlock(ctx, 50);
while (1) {
PSEvent* event;
diff --git a/native_client_sdk/src/examples/demo/life/life.c b/native_client_sdk/src/examples/demo/life/life.c
index ef107be..06b020d 100644
--- a/native_client_sdk/src/examples/demo/life/life.c
+++ b/native_client_sdk/src/examples/demo/life/life.c
@@ -42,7 +42,8 @@ struct {
const unsigned int kInitialRandSeed = 0xC0DE533D;
-#define MakeRGBA(r, g, b, a) \
+/* BGRA helper macro, for constructing a pixel for a BGRA buffer. */
+#define MakeBGRA(b, g, r, a) \
(((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
@@ -53,24 +54,24 @@ const unsigned int kInitialRandSeed = 0xC0DE533D;
* a binary alive or dead.
*/
const uint32_t kNeighborColors[] = {
- MakeRGBA(0x00, 0x00, 0x00, 0xff),
- MakeRGBA(0x00, 0x40, 0x00, 0xff),
- MakeRGBA(0x00, 0x60, 0x00, 0xff),
- MakeRGBA(0x00, 0x80, 0x00, 0xff),
- MakeRGBA(0x00, 0xA0, 0x00, 0xff),
- MakeRGBA(0x00, 0xC0, 0x00, 0xff),
- MakeRGBA(0x00, 0xE0, 0x00, 0xff),
- MakeRGBA(0x00, 0x00, 0x00, 0xff),
- MakeRGBA(0x00, 0x40, 0x00, 0xff),
- MakeRGBA(0x00, 0x60, 0x00, 0xff),
- MakeRGBA(0x00, 0x80, 0x00, 0xff),
- MakeRGBA(0x00, 0xA0, 0x00, 0xff),
- MakeRGBA(0x00, 0xC0, 0x00, 0xff),
- MakeRGBA(0x00, 0xE0, 0x00, 0xff),
- MakeRGBA(0x00, 0xFF, 0x00, 0xff),
- MakeRGBA(0x00, 0xFF, 0x00, 0xff),
- MakeRGBA(0x00, 0xFF, 0x00, 0xff),
- MakeRGBA(0x00, 0xFF, 0x00, 0xff),
+ MakeBGRA(0x00, 0x00, 0x00, 0xff),
+ MakeBGRA(0x00, 0x40, 0x00, 0xff),
+ MakeBGRA(0x00, 0x60, 0x00, 0xff),
+ MakeBGRA(0x00, 0x80, 0x00, 0xff),
+ MakeBGRA(0x00, 0xA0, 0x00, 0xff),
+ MakeBGRA(0x00, 0xC0, 0x00, 0xff),
+ MakeBGRA(0x00, 0xE0, 0x00, 0xff),
+ MakeBGRA(0x00, 0x00, 0x00, 0xff),
+ MakeBGRA(0x00, 0x40, 0x00, 0xff),
+ MakeBGRA(0x00, 0x60, 0x00, 0xff),
+ MakeBGRA(0x00, 0x80, 0x00, 0xff),
+ MakeBGRA(0x00, 0xA0, 0x00, 0xff),
+ MakeBGRA(0x00, 0xC0, 0x00, 0xff),
+ MakeBGRA(0x00, 0xE0, 0x00, 0xff),
+ MakeBGRA(0x00, 0xFF, 0x00, 0xff),
+ MakeBGRA(0x00, 0xFF, 0x00, 0xff),
+ MakeBGRA(0x00, 0xFF, 0x00, 0xff),
+ MakeBGRA(0x00, 0xFF, 0x00, 0xff),
};
/*
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
index 9b1f472..59ae061 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
+++ b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
@@ -75,7 +75,7 @@ int example_main(int argc, char* argv[]) {
PSEventSetFilter(PSE_ALL);
- PSContext2D_t* ctx = PSContext2DAllocate();
+ PSContext2D_t* ctx = PSContext2DAllocate(PP_IMAGEDATAFORMAT_BGRA_PREMUL);
bool running = true;
while (running) {
PSEvent* event;
diff --git a/native_client_sdk/src/examples/demo/voronoi/voronoi.cc b/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
index 7cadb1a..99c2cbb 100644
--- a/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
+++ b/native_client_sdk/src/examples/demo/voronoi/voronoi.cc
@@ -73,7 +73,8 @@ inline double getseconds() {
return 0.0;
}
-inline uint32_t MakeRGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a) {
+// BGRA helper function, for constructing a pixel for a BGRA buffer.
+inline uint32_t MakeBGRA(uint32_t b, uint32_t g, uint32_t r, uint32_t a) {
return (((a) << 24) | ((r) << 16) | ((g) << 8) | (b));
}
} // namespace
@@ -162,7 +163,7 @@ void Voronoi::Reset() {
const float v = (frand() * 2.0f - 1.0f) * speed;
velocities_[i].Set(u, v);
// 'unique' color (well... unique enough for our purposes)
- colors_[i] = MakeRGBA(rand255(), rand255(), rand255(), 255);
+ colors_[i] = MakeBGRA(rand255(), rand255(), rand255(), 255);
}
}
@@ -173,7 +174,7 @@ Voronoi::Voronoi() : num_regions_(kDefaultNumRegions), num_threads_(0),
// By default, render from the dispatch thread.
workers_ = new ThreadPool(num_threads_);
PSEventSetFilter(PSE_ALL);
- ps_context_ = PSContext2DAllocate();
+ ps_context_ = PSContext2DAllocate(PP_IMAGEDATAFORMAT_BGRA_PREMUL);
}
Voronoi::~Voronoi() {
@@ -243,7 +244,7 @@ bool Voronoi::wTestRect(int* m, int x, int y, int w, int h) {
// If multithreading, this function is only called by the worker threads.
inline void Voronoi::wFillSpan(uint32_t* pixels, uint32_t color, int width) {
if (!draw_interiors_) {
- const uint32_t gray = MakeRGBA(128, 128, 128, 255);
+ const uint32_t gray = MakeBGRA(128, 128, 128, 255);
color = gray;
}
for (int i = 0; i < width; i += 4) {
@@ -394,8 +395,8 @@ void Voronoi::RenderDot(float x, float y, uint32_t color1, uint32_t color2) {
// Superimposes dots on the positions.
void Voronoi::SuperimposePositions() {
- const uint32_t white = MakeRGBA(255, 255, 255, 255);
- const uint32_t gray = MakeRGBA(192, 192, 192, 255);
+ const uint32_t white = MakeBGRA(255, 255, 255, 255);
+ const uint32_t gray = MakeBGRA(192, 192, 192, 255);
for (int i = 0; i < point_count_; i++) {
RenderDot(
screen_positions_[i].x, screen_positions_[i].y, white, gray);