comparison Applications/Platforms/WebAssembly/WebAssemblyCairoViewport.cpp @ 1612:228a41233540

fix software rendering if empty target canvas
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Oct 2020 18:27:06 +0100
parents 5887a4f8594b
children 9ac2a65d4172
comparison
equal deleted inserted replaced
1611:787db80a5a1b 1612:228a41233540
75 p += 4; 75 p += 4;
76 q += 4; 76 q += 4;
77 } 77 }
78 } 78 }
79 79
80 // Execute JavaScript commands to blit the image buffer onto the 80 if (width != 0 &&
81 // 2D drawing context of the HTML5 canvas 81 height != 0)
82 EM_ASM({ 82 {
83 const data = new Uint8ClampedArray(Module.HEAP8.buffer, $1, 4 * $2 * $3); 83 // Execute JavaScript commands to blit the image buffer onto the
84 const img = new ImageData(data, $2, $3); 84 // 2D drawing context of the HTML5 canvas
85 const ctx = document.getElementById(UTF8ToString($0)).getContext('2d'); 85 EM_ASM({
86 ctx.putImageData(img, 0, 0); 86 const data = new Uint8ClampedArray(Module.HEAP8.buffer, $1, 4 * $2 * $3);
87 }, 87 const img = new ImageData(data, $2, $3);
88 GetCanvasId().c_str(), // $0 88 const ctx = document.getElementById(UTF8ToString($0)).getContext('2d');
89 javascript_->GetBuffer(), // $1 89 ctx.putImageData(img, 0, 0);
90 javascript_->GetWidth(), // $2 90 },
91 javascript_->GetHeight()); // $3 91 GetCanvasId().c_str(), // $0
92 javascript_->GetBuffer(), // $1
93 javascript_->GetWidth(), // $2
94 javascript_->GetHeight()); // $3
95 }
92 } 96 }
93 97
94 98
95 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvasId, 99 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvasId,
96 bool enableEmscriptenMouseEvents) : 100 bool enableEmscriptenMouseEvents) :