| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 m_context->setRegionTrackingMode(isCertainlyOpaque ? GraphicsContext::Region
TrackingOpaque : GraphicsContext::RegionTrackingDisabled); | 60 m_context->setRegionTrackingMode(isCertainlyOpaque ? GraphicsContext::Region
TrackingOpaque : GraphicsContext::RegionTrackingDisabled); |
| 61 m_context->setCertainlyOpaque(isCertainlyOpaque); | 61 m_context->setCertainlyOpaque(isCertainlyOpaque); |
| 62 return m_context.get(); | 62 return m_context.get(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 PassRefPtr<GraphicsContextSnapshot> GraphicsContextRecorder::stop() | 65 PassRefPtr<GraphicsContextSnapshot> GraphicsContextRecorder::stop() |
| 66 { | 66 { |
| 67 m_context.clear(); | 67 m_context.clear(); |
| 68 m_picture = adoptRef(m_recorder->endRecording()); | 68 m_picture = adoptRef(m_recorder->endRecording()); |
| 69 m_recorder.clear(); | 69 m_recorder.clear(); |
| 70 return adoptRef(new GraphicsContextSnapshot(m_picture.release(), m_isCertain
lyOpaque)); | 70 return adoptRef(new GraphicsContextSnapshot(m_picture.release())); |
| 71 } | 71 } |
| 72 | 72 |
| 73 GraphicsContextSnapshot::GraphicsContextSnapshot(PassRefPtr<SkPicture> picture,
bool isCertainlyOpaque) | 73 GraphicsContextSnapshot::GraphicsContextSnapshot(PassRefPtr<SkPicture> picture) |
| 74 : m_picture(picture) | 74 : m_picture(picture) |
| 75 , m_isCertainlyOpaque(isCertainlyOpaque) | |
| 76 { | 75 { |
| 77 } | 76 } |
| 78 | 77 |
| 79 | |
| 80 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) | 78 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) |
| 81 { | 79 { |
| 82 RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>(
data), length); | 80 RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>(
data), length); |
| 83 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(*buffer, ImageSourc
e::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored); | 81 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(*buffer, ImageSourc
e::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored); |
| 84 if (!imageDecoder) | 82 if (!imageDecoder) |
| 85 return false; | 83 return false; |
| 86 imageDecoder->setData(buffer.get(), true); | 84 imageDecoder->setData(buffer.get(), true); |
| 87 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 85 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
| 88 if (!frame) | 86 if (!frame) |
| 89 return true; | 87 return true; |
| 90 *result = frame->getSkBitmap(); | 88 *result = frame->getSkBitmap(); |
| 91 return true; | 89 return true; |
| 92 } | 90 } |
| 93 | 91 |
| 94 PassRefPtr<GraphicsContextSnapshot> GraphicsContextSnapshot::load(const char* da
ta, size_t size) | 92 PassRefPtr<GraphicsContextSnapshot> GraphicsContextSnapshot::load(const char* da
ta, size_t size) |
| 95 { | 93 { |
| 96 SkMemoryStream stream(data, size); | 94 SkMemoryStream stream(data, size); |
| 97 RefPtr<SkPicture> picture = adoptRef(SkPicture::CreateFromStream(&stream, de
codeBitmap)); | 95 RefPtr<SkPicture> picture = adoptRef(SkPicture::CreateFromStream(&stream, de
codeBitmap)); |
| 98 if (!picture) | 96 if (!picture) |
| 99 return nullptr; | 97 return nullptr; |
| 100 return adoptRef(new GraphicsContextSnapshot(picture, false)); | 98 return adoptRef(new GraphicsContextSnapshot(picture)); |
| 101 } | 99 } |
| 102 | 100 |
| 103 PassOwnPtr<Vector<char> > GraphicsContextSnapshot::replay(unsigned fromStep, uns
igned toStep, double scale) const | 101 PassOwnPtr<Vector<char> > GraphicsContextSnapshot::replay(unsigned fromStep, uns
igned toStep, double scale) const |
| 104 { | 102 { |
| 105 int width = ceil(scale * m_picture->width()); | 103 int width = ceil(scale * m_picture->width()); |
| 106 int height = ceil(scale * m_picture->height()); | 104 int height = ceil(scale * m_picture->height()); |
| 107 SkBitmap bitmap; | 105 SkBitmap bitmap; |
| 108 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); | 106 bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); |
| 109 { | 107 { |
| 110 ReplayingCanvas canvas(bitmap, fromStep, toStep); | 108 ReplayingCanvas canvas(bitmap, fromStep, toStep); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 143 } |
| 146 | 144 |
| 147 PassRefPtr<JSONArray> GraphicsContextSnapshot::snapshotCommandLog() const | 145 PassRefPtr<JSONArray> GraphicsContextSnapshot::snapshotCommandLog() const |
| 148 { | 146 { |
| 149 LoggingCanvas canvas(m_picture->width(), m_picture->height()); | 147 LoggingCanvas canvas(m_picture->width(), m_picture->height()); |
| 150 m_picture->draw(&canvas); | 148 m_picture->draw(&canvas); |
| 151 return canvas.log(); | 149 return canvas.log(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 } | 152 } |
| OLD | NEW |