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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * 5 *
6 * Use of this source code is governed by a BSD-style license that can be 6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file. 7 * found in the LICENSE file.
8 * 8 *
9 */ 9 */
10 #include <v8.h> 10 #include <v8.h>
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color), 151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color),
152 SkColorGetB(color)); 152 SkColorGetB(color));
153 153
154 info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf)); 154 info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf));
155 } 155 }
156 156
157 void JsContext::SetStyle(Local<String> name, Local<Value> value, 157 void JsContext::SetStyle(Local<String> name, Local<Value> value,
158 const PropertyCallbackInfo<void>& info, 158 const PropertyCallbackInfo<void>& info,
159 SkPaint& style) { 159 SkPaint& style) {
160 Local<String> s = value->ToString(); 160 Local<String> s = value->ToString();
161 if (s->Length() != 7) { 161 if (s->Length() != 7 && s->Length() != 9) {
162 info.GetIsolate()->ThrowException( 162 info.GetIsolate()->ThrowException(
163 v8::String::NewFromUtf8( 163 v8::String::NewFromUtf8(
164 info.GetIsolate(), "Invalid fill style format.")); 164 info.GetIsolate(),
165 "Invalid fill style format length."));
165 return; 166 return;
166 } 167 }
167 char buf[8]; 168 char buf[10];
168 s->WriteUtf8(buf, sizeof(buf)); 169 s->WriteUtf8(buf, sizeof(buf));
169 170
170 if (buf[0] != '#') { 171 if (buf[0] != '#') {
171 info.GetIsolate()->ThrowException( 172 info.GetIsolate()->ThrowException(
172 v8::String::NewFromUtf8( 173 v8::String::NewFromUtf8(
173 info.GetIsolate(), "Invalid fill style format.")); 174 info.GetIsolate(), "Invalid fill style format."));
174 return; 175 return;
175 } 176 }
176 177
178 // Colors can be RRGGBBAA, but SkColor uses ARGB.
177 long color = strtol(buf+1, NULL, 16); 179 long color = strtol(buf+1, NULL, 16);
178 style.setColor(SkColorSetA(SkColor(color), SK_AlphaOPAQUE)); 180 uint32_t alpha = SK_AlphaOPAQUE;
181 if (s->Length() == 9) {
182 alpha = color & 0xFF;
183 color >>= 8;
184 }
185 style.setColor(SkColorSetA(SkColor(color), alpha));
179 } 186 }
180 187
181 void JsContext::GetFillStyle(Local<String> name, 188 void JsContext::GetFillStyle(Local<String> name,
182 const PropertyCallbackInfo<Value>& info) { 189 const PropertyCallbackInfo<Value>& info) {
183 JsContext* jsContext = Unwrap(info.This()); 190 JsContext* jsContext = Unwrap(info.This());
184 GetStyle(name, info, jsContext->fFillStyle); 191 GetStyle(name, info, jsContext->fFillStyle);
185 } 192 }
186 193
187 void JsContext::GetStrokeStyle(Local<String> name, 194 void JsContext::GetStrokeStyle(Local<String> name,
188 const PropertyCallbackInfo<Value>& info) { 195 const PropertyCallbackInfo<Value>& info) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 374
368 // It is a function; cast it to a Function. 375 // It is a function; cast it to a Function.
369 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val); 376 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val);
370 377
371 // Store the function in a Persistent handle, since we also want that to 378 // Store the function in a Persistent handle, since we also want that to
372 // remain after this call returns. 379 // remain after this call returns.
373 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun); 380 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun);
374 381
375 return true; 382 return true;
376 } 383 }
OLDNEW
« 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