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

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

Issue 1418483006: SkRemote: some images, many TODOs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: hal Created 5 years, 1 month 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 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkAnnotation.h" 8 #include "SkAnnotation.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkDrawLooper.h" 11 #include "SkDrawLooper.h"
12 #include "SkImage.h"
12 #include "SkImageFilter.h" 13 #include "SkImageFilter.h"
13 #include "SkMaskFilter.h" 14 #include "SkMaskFilter.h"
15 #include "SkNinePatchIter.h"
14 #include "SkPath.h" 16 #include "SkPath.h"
15 #include "SkPathEffect.h" 17 #include "SkPathEffect.h"
16 #include "SkRasterizer.h" 18 #include "SkRasterizer.h"
17 #include "SkRect.h" 19 #include "SkRect.h"
18 #include "SkRemote.h" 20 #include "SkRemote.h"
19 #include "SkShader.h" 21 #include "SkShader.h"
20 #include "SkTHash.h" 22 #include "SkTHash.h"
21 23
22 namespace SkRemote { 24 namespace SkRemote {
23 25
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 Encoder::CommonIDs fIDs; 155 Encoder::CommonIDs fIDs;
154 }; 156 };
155 157
156 template <typename T> 158 template <typename T>
157 AutoID id(const T& val) { return AutoID(fEncoder, val); } 159 AutoID id(const T& val) { return AutoID(fEncoder, val); }
158 160
159 AutoCommonIDs commonIDs(const SkPaint& paint) { return AutoCommonIDs(fEn coder, paint); } 161 AutoCommonIDs commonIDs(const SkPaint& paint) { return AutoCommonIDs(fEn coder, paint); }
160 162
161 void willSave() override { fEncoder-> save(); } 163 void willSave() override { fEncoder-> save(); }
162 void didRestore() override { fEncoder->restore(); } 164 void didRestore() override { fEncoder->restore(); }
165 SaveLayerStrategy willSaveLayer(const SkRect* bounds,
166 const SkPaint* paint,
167 SaveFlags flags) override {
168 // TODO
169 return kNoLayer_SaveLayerStrategy;
170 }
163 171
164 void didConcat(const SkMatrix&) override { this->didSetMatrix(this->g etTotalMatrix()); } 172 void didConcat(const SkMatrix&) override { this->didSetMatrix(this->g etTotalMatrix()); }
165 void didSetMatrix(const SkMatrix& matrix) override { 173 void didSetMatrix(const SkMatrix& matrix) override {
166 fEncoder->setMatrix(this->id(matrix)); 174 fEncoder->setMatrix(this->id(matrix));
167 } 175 }
168 176
169 void onDrawOval(const SkRect& oval, const SkPaint& paint) override { 177 void onDrawOval(const SkRect& oval, const SkPaint& paint) override {
170 SkPath path; 178 SkPath path;
171 path.addOval(oval); 179 path.addOval(oval);
172 this->onDrawPath(path, paint); 180 this->onDrawPath(path, paint);
(...skipping 30 matching lines...) Expand all
203 fEncoder->strokePath(p, common, this->id(Stroke::CreateFrom(pain t))); 211 fEncoder->strokePath(p, common, this->id(Stroke::CreateFrom(pain t)));
204 } 212 }
205 } 213 }
206 214
207 void onDrawPaint(const SkPaint& paint) override { 215 void onDrawPaint(const SkPaint& paint) override {
208 SkPath path; 216 SkPath path;
209 path.setFillType(SkPath::kInverseWinding_FillType); // Either inver se FillType is fine. 217 path.setFillType(SkPath::kInverseWinding_FillType); // Either inver se FillType is fine.
210 this->onDrawPath(path, paint); 218 this->onDrawPath(path, paint);
211 } 219 }
212 220
221 void onDrawPoints(PointMode mode,
222 size_t count,
223 const SkPoint pts[],
224 const SkPaint& paint) override {
225 // TODO
226 }
227
228 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) overri de {
229 // TODO
230 this->INHERITED::onDrawDrawable(drawable, matrix);
231 }
232
233 void onDrawPicture(const SkPicture* pic,
234 const SkMatrix* matrix,
235 const SkPaint* paint) override {
236 // TODO
237 this->INHERITED::onDrawPicture(pic, matrix, paint);
238 }
239
240 void onDrawVertices(VertexMode vmode,
241 int vertexCount,
242 const SkPoint vertices[],
243 const SkPoint texs[],
244 const SkColor colors[],
245 SkXfermode* xmode,
246 const uint16_t indices[],
247 int indexCount,
248 const SkPaint& paint) override {
249 // TODO
250 }
251
252 void onDrawPatch(const SkPoint cubics[12],
253 const SkColor colors[4],
254 const SkPoint texCoords[4],
255 SkXfermode* xmode,
256 const SkPaint& paint) override {
257 // TODO
258 }
259
260 void onDrawAtlas(const SkImage* atlas,
261 const SkRSXform xform[],
262 const SkRect tex[],
263 const SkColor colors[],
264 int count,
265 SkXfermode::Mode mode,
266 const SkRect* cull,
267 const SkPaint* paint) override {
268 // TODO
269 }
270
271 void onDrawBitmap(const SkBitmap& bitmap,
272 SkScalar left,
273 SkScalar top,
274 const SkPaint* paint) override {
275 auto src = SkRect::MakeWH(bitmap.width(), bitmap.height()),
276 dst = src.makeOffset(left, top);
277 this->onDrawBitmapRect(bitmap, &src, dst, paint, kStrict_SrcRectCons traint);
278 }
279
280 void onDrawBitmapRect(const SkBitmap& bitmap,
281 const SkRect* src,
282 const SkRect& dst,
283 const SkPaint* paint,
284 SrcRectConstraint constraint) override {
285 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap));
286 this->onDrawImageRect(image, src, dst, paint, constraint);
287 }
288
289 void onDrawImage(const SkImage* image,
290 SkScalar left,
291 SkScalar top,
292 const SkPaint* paint) override {
293 if (!image) {
294 return;
295 }
296 auto src = SkRect::MakeWH(image->width(), image->height()),
297 dst = src.makeOffset(left, top);
298 this->onDrawImageRect(image, &src, dst, paint, kStrict_SrcRectConstr aint);
299 }
300
301 void onDrawImageRect(const SkImage* image,
302 const SkRect* src,
303 const SkRect& dst,
304 const SkPaint* paint,
305 SrcRectConstraint constraint) override {
306 // TODO: this is all a (likely buggy) hack to get images drawing qui ckly.
307 if (!image) {
308 return;
309 }
310
311 auto bounds = SkRect::MakeWH(image->width(), image->height());
312 if (!src) {
313 src = &bounds;
314 }
315 auto matrix = SkMatrix::MakeRectToRect(*src, dst, SkMatrix::kFill_Sc aleToFit);
316
317 SkAutoTUnref<SkImage> subset;
318 if (src) {
319 if (!bounds.intersect(*src)) {
320 return;
321 }
322 subset.reset(image->newSubset(bounds.roundOut()));
323 image = subset;
324 }
325
326 auto paintWithShader = paint ? *paint : SkPaint();
327 SkAutoTUnref<SkShader> shader(
328 image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_Til eMode, &matrix));
329 paintWithShader.setShader(shader);
330
331 this->onDrawRect(dst, paintWithShader);
332 }
333
334 void onDrawBitmapNine(const SkBitmap& bitmap,
335 const SkIRect& center,
336 const SkRect& dst,
337 const SkPaint* paint) override {
338 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap));
339 this->onDrawImageNine(image, center, dst, paint);
340 }
341
342 void onDrawImageNine(const SkImage* image,
343 const SkIRect& center,
344 const SkRect& dst,
345 const SkPaint* paint) override {
346 SkNinePatchIter iter(image->width(), image->height(), center, dst);
347 SkRect s,d;
348 while (iter.next(&s, &d)) {
349 this->onDrawImageRect(image, &s, d, paint, kStrict_SrcRectConstr aint);
350 }
351 }
352
213 void onDrawText(const void* text, size_t byteLength, 353 void onDrawText(const void* text, size_t byteLength,
214 SkScalar x, SkScalar y, const SkPaint& paint) override { 354 SkScalar x, SkScalar y, const SkPaint& paint) override {
215 // Text-as-paths is a temporary hack. 355 // Text-as-paths is a temporary hack.
216 // TODO: send SkTextBlobs and SkTypefaces 356 // TODO: send SkTextBlobs and SkTypefaces
217 SkPath path; 357 SkPath path;
218 paint.getTextPath(text, byteLength, x, y, &path); 358 paint.getTextPath(text, byteLength, x, y, &path);
219 this->onDrawPath(path, paint); 359 this->onDrawPath(path, paint);
220 } 360 }
221 361
222 void onDrawPosText(const void* text, size_t byteLength, 362 void onDrawPosText(const void* text, size_t byteLength,
223 const SkPoint pos[], const SkPaint& paint) override { 363 const SkPoint pos[], const SkPaint& paint) override {
224 // Text-as-paths is a temporary hack. 364 // Text-as-paths is a temporary hack.
225 // TODO: send SkTextBlobs and SkTypefaces 365 // TODO: send SkTextBlobs and SkTypefaces
226 SkPath path; 366 SkPath path;
227 paint.getPosTextPath(text, byteLength, pos, &path); 367 paint.getPosTextPath(text, byteLength, pos, &path);
228 this->onDrawPath(path, paint); 368 this->onDrawPath(path, paint);
229 } 369 }
230 370
231 void onDrawPosTextH(const void* text, size_t byteLength, 371 void onDrawPosTextH(const void* text, size_t byteLength,
232 const SkScalar xpos[], SkScalar constY, const SkPain t& paint) override { 372 const SkScalar xpos[], SkScalar constY, const SkPain t& paint) override {
233 size_t length = paint.countText(text, byteLength); 373 size_t length = paint.countText(text, byteLength);
234 SkAutoTArray<SkPoint> pos(length); 374 SkAutoTArray<SkPoint> pos(length);
235 for(size_t i = 0; i < length; ++i) { 375 for(size_t i = 0; i < length; ++i) {
236 pos[i].set(xpos[i], constY); 376 pos[i].set(xpos[i], constY);
237 } 377 }
238 this->onDrawPosText(text, byteLength, &pos[0], paint); 378 this->onDrawPosText(text, byteLength, &pos[0], paint);
239 } 379 }
240 380
381 // All clip calls need to call their parent method or we'll not get any quick rejects.
241 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { 382 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override {
383 this->INHERITED::onClipRect(rect, op, edgeStyle);
242 SkPath path; 384 SkPath path;
243 path.addRect(rect); 385 path.addRect(rect);
244 this->onClipPath(path, op, edgeStyle); 386 this->onClipPath(path, op, edgeStyle);
245 } 387 }
246 388
247 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle ed geStyle) override { 389 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle ed geStyle) override {
390 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
248 SkPath path; 391 SkPath path;
249 path.addRRect(rrect); 392 path.addRRect(rrect);
250 this->onClipPath(path, op, edgeStyle); 393 this->onClipPath(path, op, edgeStyle);
251 } 394 }
252 395
253 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override { 396 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeS tyle) override {
397 this->INHERITED::onClipPath(path, op, edgeStyle);
254 fEncoder->clipPath(this->id(path), op, edgeStyle == kSoft_ClipEdgeSt yle); 398 fEncoder->clipPath(this->id(path), op, edgeStyle == kSoft_ClipEdgeSt yle);
255 } 399 }
256 400
401 void onClipRegion(const SkRegion& region, SkRegion::Op op) override {
402 this->INHERITED::onClipRegion(region, op);
403 // TODO
404 }
405
257 Encoder* fEncoder; 406 Encoder* fEncoder;
407 typedef SkCanvas INHERITED;
258 }; 408 };
259 409
260 SkCanvas* NewCanvas(Encoder* encoder) { return new Canvas(encoder); } 410 SkCanvas* NewCanvas(Encoder* encoder) { return new Canvas(encoder); }
261 411
262 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 412 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
263 413
264 class Decoder final : public Encoder { 414 class Decoder final : public Encoder {
265 public: 415 public:
266 explicit Decoder(SkCanvas* canvas) : fCanvas(canvas) {} 416 explicit Decoder(SkCanvas* canvas) : fCanvas(canvas) {}
267 417
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper; 691 RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
542 RefKeyMap<SkImageFilter, Type::kImageFilter> fImageFilter; 692 RefKeyMap<SkImageFilter, Type::kImageFilter> fImageFilter;
543 RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation; 693 RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation;
544 694
545 Encoder* fWrapped; 695 Encoder* fWrapped;
546 }; 696 };
547 697
548 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); } 698 Encoder* NewCachingEncoder(Encoder* wrapped) { return new CachingEncoder(wra pped); }
549 699
550 } // namespace SkRemote 700 } // namespace SkRemote
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