OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sky/engine/config.h" | |
6 #include "sky/engine/core/loader/NewImageLoader.h" | |
7 #include "sky/engine/platform/image-decoders/ImageDecoder.h" | |
8 #include "sky/engine/platform/SharedBuffer.h" | |
9 | |
10 namespace blink { | |
11 | |
12 void NewImageLoader::Load(const KURL& src) { | |
13 fetcher_ = adoptPtr(new MojoFetcher(this, src)); | |
abarth-chromium
2015/05/29 23:04:10
What happens if someone calls |Load| a second time
jackson
2015/05/29 23:35:43
OK, I changed it to not null the client
| |
14 } | |
15 | |
16 void NewImageLoader::OnReceivedResponse(mojo::URLResponsePtr response) { | |
17 if (response->status_code != 200) { | |
18 client_->notifyLoadFinished(SkBitmap()); | |
19 client_ = nullptr; | |
20 return; | |
21 } | |
22 buffer_ = SharedBuffer::create(); | |
23 drainer_ = | |
24 adoptPtr(new mojo::common::DataPipeDrainer(this, response->body.Pass())); | |
25 } | |
26 | |
27 void NewImageLoader::OnDataAvailable(const void* data, size_t num_bytes) { | |
28 buffer_->append(static_cast<const char*>(data), num_bytes); | |
29 } | |
30 | |
31 void NewImageLoader::OnDataComplete() { | |
32 OwnPtr<ImageDecoder> decoder = | |
33 ImageDecoder::create(*buffer_.get(), ImageSource::AlphaPremultiplied, | |
34 ImageSource::GammaAndColorProfileIgnored); | |
35 decoder->setData(buffer_.get(), true); | |
36 if (decoder->failed()) { | |
37 client_->notifyLoadFinished(SkBitmap()); | |
38 } else { | |
39 ImageFrame* frame = decoder->frameBufferAtIndex(0); | |
abarth-chromium
2015/05/29 23:04:10
Is it possible for an image to have zero frames?
jackson
2015/05/29 23:35:43
Looks like maybe. I'll add a guard
| |
40 SkBitmap bitmap = frame->getSkBitmap(); | |
41 client_->notifyLoadFinished(bitmap); | |
42 } | |
43 client_ = nullptr; | |
44 } | |
45 } | |
abarth-chromium
2015/05/29 23:04:10
} // namespace blink
jackson
2015/05/29 23:35:43
Acknowledged.
| |
OLD | NEW |