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()); |
24 | 26 |
25 SkBitmap bm; | 27 SkBitmap bm; |
26 wrap_texture(layer->texture(), | 28 wrap_texture(layer->texture(), |
27 !layer->isAtlased() ? layer->rect().width() : layer->texture()
->width(), | 29 !layer->isAtlased() ? layer->rect().width() : layer->texture()
->width(), |
28 !layer->isAtlased() ? layer->rect().height() : layer->texture()
->height(), | 30 !layer->isAtlased() ? layer->rect().height() : layer->texture()
->height(), |
29 &bm); | 31 &bm); |
30 | 32 |
31 if (layer->isAtlased()) { | 33 canvas->save(); |
32 const SkRect src = SkRect::Make(layer->rect()); | 34 canvas->setMatrix(SkMatrix::I()); |
33 const SkRect dst = SkRect::Make(layer->srcIR()); | 35 canvas->drawBitmapRectToRect(bm, &src, dst, layer->paint()); |
34 | 36 canvas->restore(); |
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 } | |
47 } | 37 } |
48 | 38 |
49 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and | 39 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and |
50 // also draws them with replaced layers. | 40 // also draws them with replaced layers. |
51 class ReplaceDraw : public SkRecords::Draw { | 41 class ReplaceDraw : public SkRecords::Draw { |
52 public: | 42 public: |
53 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, | 43 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, |
54 SkPicture const* const drawablePicts[], int drawableCount, | 44 SkPicture const* const drawablePicts[], int drawableCount, |
55 const SkPicture* topLevelPicture, | 45 const SkPicture* topLevelPicture, |
56 const SkPicture* picture, | 46 const SkPicture* picture, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 const SkMatrix& initialMatrix, | 194 const SkMatrix& initialMatrix, |
205 SkDrawPictureCallback* callback) { | 195 SkDrawPictureCallback* callback) { |
206 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 196 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
207 | 197 |
208 // TODO: drawablePicts? | 198 // TODO: drawablePicts? |
209 ReplaceDraw draw(canvas, layerCache, NULL, 0, | 199 ReplaceDraw draw(canvas, layerCache, NULL, 0, |
210 picture, picture, | 200 picture, picture, |
211 initialMatrix, callback, NULL, 0); | 201 initialMatrix, callback, NULL, 0); |
212 return draw.draw(); | 202 return draw.draw(); |
213 } | 203 } |
OLD | NEW |