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

Side by Side Diff: src/core/SkDevice.cpp

Issue 1261433009: Refugee from Dead Machine 11: Add SkCanvas::drawLitAtlas call Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 7 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 | « src/core/SkCanvas.cpp ('k') | src/core/SkLightingShader.h » ('j') | 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorFilter.h" 8 #include "SkColorFilter.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
11 #include "SkDrawFilter.h" 11 #include "SkDrawFilter.h"
12 #include "SkImage_Base.h" 12 #include "SkImage_Base.h"
13 #include "SkLightingShader.h"
13 #include "SkMetaData.h" 14 #include "SkMetaData.h"
14 #include "SkNinePatchIter.h" 15 #include "SkNinePatchIter.h"
15 #include "SkPatchUtils.h" 16 #include "SkPatchUtils.h"
16 #include "SkPathMeasure.h" 17 #include "SkPathMeasure.h"
17 #include "SkRasterClip.h" 18 #include "SkRasterClip.h"
18 #include "SkRSXform.h" 19 #include "SkRSXform.h"
19 #include "SkShader.h" 20 #include "SkShader.h"
20 #include "SkTextBlob.h" 21 #include "SkTextBlob.h"
21 #include "SkTextToPathIter.h" 22 #include "SkTextToPathIter.h"
22 23
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 pnt.setColorFilter(cf); 206 pnt.setColorFilter(cf);
206 } 207 }
207 208
208 path.rewind(); 209 path.rewind();
209 path.addPoly(quad, 4, true); 210 path.addPoly(quad, 4, true);
210 path.setConvexity(SkPath::kConvex_Convexity); 211 path.setConvexity(SkPath::kConvex_Convexity);
211 this->drawPath(draw, path, pnt, NULL, true); 212 this->drawPath(draw, path, pnt, NULL, true);
212 } 213 }
213 } 214 }
214 215
216 #include "SkGr.h"
217
218 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) {
219 GrTexture* tex = as_IB(image)->getTexture();
220 if (tex) {
221 GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpa que(), bm);
222 return true;
223 } else {
224 return as_IB(image)->getROPixels(bm);
225 }
226 }
227
228 void SkBaseDevice::drawLitAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[],
229 const SkRect diffTex[], const SkRect normTex[],
230 const SkColor colors[], int count, SkXfermode::M ode mode,
231 const SkPaint& paint,
232 const SkLight lights[], int numLights) {
233 SkPath path;
234 path.setIsVolatile(true);
235
236 SkBitmap bm;
237 if (!wrap_as_bm(atlas, &bm)) {
238 return;
239 }
240
241 SkLightingShader::Lights::Builder builder(lights, numLights);
242 SkAutoTUnref<const SkLightingShader::Lights> lights2(builder.finish());
243
244 for (int i = 0; i < count; ++i) {
245 SkASSERT(diffTex[i].width() == normTex[i].width() &&
246 diffTex[i].height() == normTex[i].height());
247
248 SkPoint quad[4];
249 xform[i].toQuad(diffTex[i].width(), diffTex[i].height(), quad);
250
251 SkMatrix diffLocalM;
252 diffLocalM.setRSXform(xform[i]);
253 diffLocalM.preTranslate(-diffTex[i].left(), -diffTex[i].top());
254
255 SkMatrix normLocalM;
256 normLocalM.setRSXform(xform[i]);
257 normLocalM.preTranslate(diffTex[i].left()-normTex[i].left(),
258 diffTex[i].top()-normTex[i].top());
259 normLocalM.preTranslate(-diffTex[i].left(), -diffTex[i].top());
260
261 SkPaint pnt(paint);
262
263 pnt.setShader(SkLightingShader::Create(bm, bm,
264 lights2,
265 xform[i], &diffLocalM, &normLocal M));
266
267 if (colors && colors[i] != SK_ColorWHITE) {
268 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color s[i], mode));
269 pnt.setColorFilter(cf);
270 }
271
272 path.rewind();
273 path.addPoly(quad, 4, true);
274 path.setConvexity(SkPath::kConvex_Convexity);
275 this->drawPath(draw, path, pnt, NULL, true);
276 }
277 }
278
215 //////////////////////////////////////////////////////////////////////////////// /////////////////// 279 //////////////////////////////////////////////////////////////////////////////// ///////////////////
216 280
217 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt es, int x, int y) { 281 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt es, int x, int y) {
218 #ifdef SK_DEBUG 282 #ifdef SK_DEBUG
219 SkASSERT(info.width() > 0 && info.height() > 0); 283 SkASSERT(info.width() > 0 && info.height() > 0);
220 SkASSERT(dstP); 284 SkASSERT(dstP);
221 SkASSERT(rowBytes >= info.minRowBytes()); 285 SkASSERT(rowBytes >= info.minRowBytes());
222 SkASSERT(x >= 0 && y >= 0); 286 SkASSERT(x >= 0 && y >= 0);
223 287
224 const SkImageInfo& srcInfo = this->imageInfo(); 288 const SkImageInfo& srcInfo = this->imageInfo();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() 472 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry()
409 || this->onShouldDisableLCD(paint)) { 473 || this->onShouldDisableLCD(paint)) {
410 474
411 flags &= ~SkPaint::kLCDRenderText_Flag; 475 flags &= ~SkPaint::kLCDRenderText_Flag;
412 flags |= SkPaint::kGenA8FromLCD_Flag; 476 flags |= SkPaint::kGenA8FromLCD_Flag;
413 } 477 }
414 478
415 return flags; 479 return flags;
416 } 480 }
417 481
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698