Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Unified Diff: experimental/SkV8Example/JsContext.cpp

Issue 136553006: Add handling alpha values in RRGGBBAA formatted styles. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typo Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/JsContext.cpp
diff --git a/experimental/SkV8Example/JsContext.cpp b/experimental/SkV8Example/JsContext.cpp
index 5778172f27338c962f56482919fd1d54ba143f29..047147dc82785b3e44f96d3eb645612be4b8bb7e 100644
--- a/experimental/SkV8Example/JsContext.cpp
+++ b/experimental/SkV8Example/JsContext.cpp
@@ -158,13 +158,14 @@ void JsContext::SetStyle(Local<String> name, Local<Value> value,
const PropertyCallbackInfo<void>& info,
SkPaint& style) {
Local<String> s = value->ToString();
- if (s->Length() != 7) {
+ if (s->Length() != 7 && s->Length() != 9) {
info.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
- info.GetIsolate(), "Invalid fill style format."));
+ info.GetIsolate(),
+ "Invalid fill style format length."));
return;
}
- char buf[8];
+ char buf[10];
s->WriteUtf8(buf, sizeof(buf));
if (buf[0] != '#') {
@@ -174,8 +175,14 @@ void JsContext::SetStyle(Local<String> name, Local<Value> value,
return;
}
+ // Colors can be RRGGBBAA, but SkColor uses ARGB.
long color = strtol(buf+1, NULL, 16);
- style.setColor(SkColorSetA(SkColor(color), SK_AlphaOPAQUE));
+ uint32_t alpha = SK_AlphaOPAQUE;
+ if (s->Length() == 9) {
+ alpha = color & 0xFF;
+ color >>= 8;
+ }
+ style.setColor(SkColorSetA(SkColor(color), alpha));
}
void JsContext::GetFillStyle(Local<String> name,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698