OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrContext.h" | 8 #include "GrContext.h" |
9 #include "GrLayerCache.h" | 9 #include "GrLayerCache.h" |
10 #include "GrRecordReplaceDraw.h" | 10 #include "GrRecordReplaceDraw.h" |
11 #include "SkCanvasPriv.h" | 11 #include "SkCanvasPriv.h" |
12 #include "SkGrPixelRef.h" | 12 #include "SkGrPixelRef.h" |
13 #include "SkImage.h" | 13 #include "SkImage.h" |
14 #include "SkRecordDraw.h" | 14 #include "SkRecordDraw.h" |
15 #include "SkRecords.h" | 15 #include "SkRecords.h" |
16 | 16 |
17 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit
map* result) { | 17 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit
map* result) { |
18 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 18 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
19 result->setInfo(info); | 19 result->setInfo(info); |
20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
21 } | 21 } |
22 | 22 |
23 static inline void draw_replacement_bitmap(GrCachedLayer* layer, SkCanvas* canva
s) { | 23 static inline void draw_replacement_bitmap(GrCachedLayer* layer, SkCanvas* canva
s) { |
24 const SkRect src = SkRect::Make(layer->rect()); | |
25 const SkRect dst = SkRect::Make(layer->bound()); | |
26 | 24 |
27 SkBitmap bm; | 25 SkBitmap bm; |
28 wrap_texture(layer->texture(), | 26 wrap_texture(layer->texture(), |
29 !layer->isAtlased() ? layer->rect().width() : layer->texture()
->width(), | 27 !layer->isAtlased() ? layer->rect().width() : layer->texture()
->width(), |
30 !layer->isAtlased() ? layer->rect().height() : layer->texture()
->height(), | 28 !layer->isAtlased() ? layer->rect().height() : layer->texture()
->height(), |
31 &bm); | 29 &bm); |
32 | 30 |
33 canvas->save(); | 31 if (layer->isAtlased()) { |
34 canvas->setMatrix(SkMatrix::I()); | 32 const SkRect src = SkRect::Make(layer->rect()); |
35 canvas->drawBitmapRectToRect(bm, &src, dst, layer->paint()); | 33 const SkRect dst = SkRect::Make(layer->srcIR()); |
36 canvas->restore(); | 34 |
| 35 SkASSERT(layer->offset().isZero()); |
| 36 |
| 37 canvas->save(); |
| 38 canvas->setMatrix(SkMatrix::I()); |
| 39 canvas->drawBitmapRectToRect(bm, &src, dst, layer->paint()); |
| 40 canvas->restore(); |
| 41 } else { |
| 42 canvas->drawSprite(bm, |
| 43 layer->srcIR().fLeft + layer->offset().fX, |
| 44 layer->srcIR().fTop + layer->offset().fY, |
| 45 layer->paint()); |
| 46 } |
37 } | 47 } |
38 | 48 |
39 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and | 49 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and |
40 // also draws them with replaced layers. | 50 // also draws them with replaced layers. |
41 class ReplaceDraw : public SkRecords::Draw { | 51 class ReplaceDraw : public SkRecords::Draw { |
42 public: | 52 public: |
43 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, | 53 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, |
44 SkPicture const* const drawablePicts[], int drawableCount, | 54 SkPicture const* const drawablePicts[], int drawableCount, |
45 const SkPicture* topLevelPicture, | 55 const SkPicture* topLevelPicture, |
46 const SkPicture* picture, | 56 const SkPicture* picture, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 const SkMatrix& initialMatrix, | 204 const SkMatrix& initialMatrix, |
195 SkDrawPictureCallback* callback) { | 205 SkDrawPictureCallback* callback) { |
196 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 206 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
197 | 207 |
198 // TODO: drawablePicts? | 208 // TODO: drawablePicts? |
199 ReplaceDraw draw(canvas, layerCache, NULL, 0, | 209 ReplaceDraw draw(canvas, layerCache, NULL, 0, |
200 picture, picture, | 210 picture, picture, |
201 initialMatrix, callback, NULL, 0); | 211 initialMatrix, callback, NULL, 0); |
202 return draw.draw(); | 212 return draw.draw(); |
203 } | 213 } |
OLD | NEW |