summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 21:35:25 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 21:35:25 +0000
commit932c43a5aec158b6bbd8ad57b4a3c5fd1d584cce (patch)
treebc7761398291ff85538e5973b99ce444811ea772 /content
parentc77684ffa9516e7f44e458fa61aa4e1f5ab17d47 (diff)
downloadchromium_src-932c43a5aec158b6bbd8ad57b4a3c5fd1d584cce.zip
chromium_src-932c43a5aec158b6bbd8ad57b4a3c5fd1d584cce.tar.gz
chromium_src-932c43a5aec158b6bbd8ad57b4a3c5fd1d584cce.tar.bz2
Add a switch to invert web contents (non-accel only).
The switch will just be used during development of this feature. The idea is for this to be turned automatically for Windows users who enable an inverted (white-on-black) color scheme - see bug for detail. This first patch only handles the non-accelerated graphics path; a subsequent change will handle the accelerated path. BUG=112944 TEST=manually test with --invert-web-contents switch Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=120928 Review URL: http://codereview.chromium.org/9353012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121541 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/render_view_host.cc5
-rw-r--r--content/common/view_messages.h5
-rw-r--r--content/public/common/content_switches.cc4
-rw-r--r--content/public/common/content_switches.h1
-rw-r--r--content/renderer/render_widget.cc49
-rw-r--r--content/renderer/render_widget.h7
6 files changed, 70 insertions, 1 deletions
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index 24e09f5..6d610b0 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -45,6 +45,7 @@
#include "content/public/browser/user_metrics.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_constants.h"
+#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "net/base/net_util.h"
@@ -209,6 +210,10 @@ bool RenderViewHost::CreateRenderView(const string16& frame_name,
// Let our delegate know that we created a RenderView.
delegate_->RenderViewCreated(this);
+ // Invert the color scheme if a flag was set.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInvertWebContent))
+ Send(new ViewMsg_InvertWebContent(routing_id(), true));
+
FOR_EACH_OBSERVER(
content::RenderViewHostObserver, observers_, RenderViewHostInitialized());
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 9d90eb1..d247651 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -2016,3 +2016,8 @@ IPC_MESSAGE_ROUTED0(ViewHostMsg_UnlockMouse)
IPC_MESSAGE_ROUTED2(ViewHostMsg_DomOperationResponse,
std::string /* json_string */,
int /* automation_id */)
+
+// Enable or disable inverting of web content pixels, for users who prefer
+// white-on-black.
+IPC_MESSAGE_ROUTED1(ViewMsg_InvertWebContent,
+ bool /* invert */)
diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc
index 6baf3c7..0bec7fa 100644
--- a/content/public/common/content_switches.cc
+++ b/content/public/common/content_switches.cc
@@ -373,6 +373,10 @@ const char kInProcessPlugins[] = "in-process-plugins";
// Runs WebGL inside the renderer process.
const char kInProcessWebGL[] = "in-process-webgl";
+// Invert web content pixels, for users who prefer white-on-black.
+// (Temporary, just during development and testing of this feature.)
+const char kInvertWebContent[] = "invert-web-content";
+
// Specifies the flags passed to JS engine
const char kJavaScriptFlags[] = "js-flags";
diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h
index 6802555..f271ebd 100644
--- a/content/public/common/content_switches.h
+++ b/content/public/common/content_switches.h
@@ -117,6 +117,7 @@ CONTENT_EXPORT extern const char kIgnoreGpuBlacklist[];
extern const char kInProcessGPU[];
extern const char kInProcessPlugins[];
CONTENT_EXPORT extern const char kInProcessWebGL[];
+CONTENT_EXPORT extern const char kInvertWebContent[];
CONTENT_EXPORT extern const char kJavaScriptFlags[];
extern const char kLoadPlugin[];
CONTENT_EXPORT extern const char kLoggingLevel[];
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index bbc4ecc..99b3731 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -24,6 +24,7 @@
#include "ipc/ipc_sync_message.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkShader.h"
+#include "third_party/skia/include/effects/SkTableColorFilter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
@@ -98,7 +99,8 @@ RenderWidget::RenderWidget(WebKit::WebPopupType popup_type)
is_accelerated_compositing_active_(false),
animation_update_pending_(false),
animation_task_posted_(false),
- invalidation_task_posted_(false) {
+ invalidation_task_posted_(false),
+ invert_(false) {
RenderProcess::current()->AddRefProcess();
DCHECK(RenderThread::Get());
has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
@@ -217,6 +219,7 @@ bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
+ IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -587,6 +590,16 @@ void RenderWidget::PaintRect(const gfx::Rect& rect,
canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
static_cast<SkScalar>(-canvas_origin.y()));
+ if (invert_) {
+ // Draw everything to a temporary bitmap and then apply an
+ // inverting color map to the result. This is balanced by an extra
+ // call to canvas->restore(), below.
+ DCHECK(invert_paint_.get());
+ SkRect bounds;
+ bounds.set(rect.x(), rect.y(), rect.right(), rect.bottom());
+ canvas->saveLayer(&bounds, invert_paint_.get());
+ }
+
// If there is a custom background, tile it.
if (!background_.empty()) {
SkPaint paint;
@@ -647,6 +660,9 @@ void RenderWidget::PaintRect(const gfx::Rect& rect,
skia::GetTopDevice(*canvas)->accessBitmap(false);
}
+ if (invert_)
+ canvas->restore();
+
PaintDebugBorder(rect, canvas);
canvas->restore();
}
@@ -1389,6 +1405,37 @@ void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
webwidget_->setTextDirection(direction);
}
+void RenderWidget::OnInvertWebContent(bool invert) {
+ if (invert_ == invert)
+ return;
+
+ invert_ = invert;
+
+ if (invert_ && !invert_paint_.get()) {
+ // Gamma-aware color inversion: each source pixel value x is normally
+ // displayed on a computer monitor with a gamma correction x^gamma,
+ // where gamma is typically in the range 1.8...2.2. By approximating
+ // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
+ uint8_t table[256];
+ for (unsigned int i = 0; i < 256; i++) {
+ double value = i / 255.0;
+ value = sqrt(1 - (value * value));
+ table[i] = static_cast<uint8_t>(255 * value);
+ }
+
+ // Create a Skia Paint with this inverting color map.
+ invert_paint_.reset(new SkPaint());
+ invert_paint_->setStyle(SkPaint::kFill_Style);
+ invert_paint_->setColor(SK_ColorBLACK);
+ SkColorFilter* filter = SkTableColorFilter::CreateARGB(
+ NULL, table, table, table);
+ invert_paint_->setColorFilter(filter);
+ filter->unref();
+ }
+
+ OnMsgRepaint(size_);
+}
+
webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
const gfx::Rect& paint_bounds,
TransportDIB** dib,
diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h
index c1f53cd..d1968e0 100644
--- a/content/renderer/render_widget.h
+++ b/content/renderer/render_widget.h
@@ -233,6 +233,7 @@ class CONTENT_EXPORT RenderWidget
void OnMsgRepaint(const gfx::Size& size_to_paint);
void OnSetTextDirection(WebKit::WebTextDirection direction);
void OnGetFPS();
+ void OnInvertWebContent(bool invert);
// Override points to notify derived classes that a paint has happened.
// WillInitiatePaint happens when we're about to generate a new bitmap and
@@ -495,6 +496,12 @@ class CONTENT_EXPORT RenderWidget
// case NULL is added to the queue.
std::deque<ViewHostMsg_UpdateRect*> updates_pending_swap_;
+ // Set to true if we should invert all pixels.
+ bool invert_;
+
+ // The Skia paint object for inverting.
+ scoped_ptr<SkPaint> invert_paint_;
+
DISALLOW_COPY_AND_ASSIGN(RenderWidget);
};