Skip to content

Commit

Permalink
Improve takeScreenshot performance in ie driver.
Browse files Browse the repository at this point in the history
IsSameColor method could take a lot of time, especially for pages with solid background (like login or search forms, where only several elements exists on the page). This becomes even worse if IEDriverServer runs several sessions in parallel. This happens beacause of GetPixel method calls winapi each time it is called. So we get rid of it and use already captured bytes to check screenshot.

Signed-off-by: Jim Evans <james.h.evans.jr@gmail.com>
  • Loading branch information
rovner authored and jimevans committed Mar 24, 2018
1 parent f5aafa3 commit 5cce5cf
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions cpp/iedriver/CommandHandlers/ScreenshotCommandHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
Expand Down Expand Up @@ -126,12 +126,34 @@ void ScreenshotCommandHandler::CaptureWindow(HWND window_handle,
}

bool ScreenshotCommandHandler::IsSameColour() {
COLORREF firstPixelColour = this->image_->GetPixel(0, 0);

for (int i = 0; i < this->image_->GetWidth(); i++) {
for (int j = 0; j < this->image_->GetHeight(); j++) {
if (firstPixelColour != this->image_->GetPixel(i, j)) {
return false;
int bytes_per_pixel = this->image_->GetBPP() / 8;
if (bytes_per_pixel >= 3) {
BYTE* root_pixel_pointer = reinterpret_cast<BYTE*>(this->image_->GetBits());
int pitch = this->image_->GetPitch();
int first_pixel_red = *(root_pixel_pointer);
int first_pixel_green = *(root_pixel_pointer + 1);
int first_pixel_blue = *(root_pixel_pointer + 2);

for (int i = 0; i < this->image_->GetWidth(); ++i) {
for (int j = 0; j < this->image_->GetHeight(); ++j) {
int current_pixel_offset = (pitch * j) + (bytes_per_pixel * i);
int current_pixel_red = *(root_pixel_pointer + current_pixel_offset);
int current_pixel_green = *(root_pixel_pointer + current_pixel_offset + 1);
int current_pixel_blue = *(root_pixel_pointer + current_pixel_offset + 2);
if (first_pixel_red != current_pixel_red ||
first_pixel_green != current_pixel_green ||
first_pixel_blue != current_pixel_blue) {
return false;
}
}
}
} else {
COLORREF firstPixelColour = this->image_->GetPixel(0, 0);
for (int i = 0; i < this->image_->GetWidth(); ++i) {
for (int j = 0; j < this->image_->GetHeight(); ++j) {
if (this->image_->GetPixel(i, j)) {
return false;
}
}
}
}
Expand Down

0 comments on commit 5cce5cf

Please sign in to comment.