Last active
October 24, 2019 09:49
-
-
Save coolwanglu/09446e94352c37b7acd4ab2e5e20eef6 to your computer and use it in GitHub Desktop.
ChromeVFX Prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void receive_request(const FunctionCallbackInfo<Value>& args) { | |
unsigned int priority; | |
double msg; | |
boost::interprocess::message_queue::size_type recvd_size; | |
message_queue_request_->receive(&msg, sizeof(msg), recvd_size, priority); | |
auto* isolate = args.GetIsolate(); | |
args.GetReturnValue().Set(Number::New(isolate, msg)); | |
} | |
void send_response(const FunctionCallbackInfo<Value>& args) { | |
int msg = args[0].As<Int32>()->Value(); | |
message_queue_response_->send(&msg, sizeof(msg), 0); | |
} | |
void save_screenshot(const FunctionCallbackInfo<Value>& args) { | |
Local<Object> buffer_obj = args[0]->ToObject(); | |
const char* png_data = node::Buffer::Data(buffer_obj); | |
const size_t png_data_size = node::Buffer::Length(buffer_obj); | |
if (png_data_size > mapped_region_->get_size()) { | |
std::cout << "WARNING: png data too large " << png_data_size << std::endl; | |
} else { | |
std::memcpy(mapped_region_->get_address(), png_data, png_data_size); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool EffectsImpl::render(double time, Image* renderImage) { | |
message_queue_request_->send(&time, sizeof(double), 0); | |
int image_size; | |
unsigned int priority; | |
boost::interprocess::message_queue::size_type recvd_size; | |
message_queue_response_->receive(&image_size, sizeof(image_size), recvd_size, priority); | |
if (image_size > mapped_region_->get_size()) { return false; } | |
png_image image; | |
if (!read_png(mapped_region_->get_address(), image_size, &image, &png_buffer_)) { return false; } | |
if (image.width != renderImage->width() || image.height != renderImage->height() || png_buffer_.size() != renderImage->byteCount()) { return false; } | |
std::memcpy(renderImage->pixels(), png_buffer_.data(), png_buffer_.size()); | |
png_image_free(&image); | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(true) { | |
var render_time = ipc.receive_request(); | |
await page.evaluate(render_time => { | |
webvfx.render(render_time); | |
}, render_time); | |
const screenshot = await page.screenshot({ | |
type: 'png', | |
omitBackground: 'true', | |
encoding: 'binary', | |
}); | |
ipc.save_screenshot(screenshot); | |
ipc.send_response(screenshot.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment