forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid depending on STB in //flutter/impeller/image. (flutter#47)
- Loading branch information
1 parent
a781e2f
commit 555faba
Showing
365 changed files
with
133 additions
and
78,302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "impeller/image/backends/skia/compressed_image_skia.h" | ||
|
||
#include <memory> | ||
|
||
#include "impeller/base/validation.h" | ||
#include "third_party/skia/include/core/SkData.h" | ||
#include "third_party/skia/include/core/SkImageGenerator.h" | ||
#include "third_party/skia/include/core/SkPixmap.h" | ||
|
||
namespace impeller { | ||
|
||
CompressedImageSkia::CompressedImageSkia( | ||
std::shared_ptr<const fml::Mapping> allocation) | ||
: CompressedImage(std::move(allocation)) {} | ||
|
||
CompressedImageSkia::~CompressedImageSkia() = default; | ||
|
||
// |CompressedImage| | ||
DecompressedImage CompressedImageSkia::Decode() const { | ||
if (!IsValid()) { | ||
return {}; | ||
} | ||
if (source_->GetSize() == 0u) { | ||
return {}; | ||
} | ||
|
||
auto src = new std::shared_ptr<const fml::Mapping>(source_); | ||
auto sk_data = SkData::MakeWithProc( | ||
source_->GetMapping(), source_->GetSize(), | ||
[](const void* ptr, void* context) { | ||
delete reinterpret_cast<decltype(src)>(context); | ||
}, | ||
src); | ||
|
||
auto generator = SkImageGenerator::MakeFromEncoded(sk_data); | ||
if (!generator) { | ||
return {}; | ||
} | ||
|
||
auto info = SkImageInfo::MakeN32Premul(generator->getInfo().dimensions()); | ||
|
||
auto bitmap = std::make_shared<SkBitmap>(); | ||
if (!bitmap->tryAllocPixels(info)) { | ||
VALIDATION_LOG << "Could not allocate arena for decompressing image."; | ||
return {}; | ||
} | ||
|
||
if (!generator->getPixels(bitmap->pixmap())) { | ||
VALIDATION_LOG << "Could not decompress image into arena."; | ||
return {}; | ||
} | ||
|
||
auto mapping = std::make_shared<fml::NonOwnedMapping>( | ||
reinterpret_cast<const uint8_t*>(bitmap->pixmap().addr()), // data | ||
bitmap->pixmap().rowBytes() * bitmap->pixmap().height(), // size | ||
[bitmap](const uint8_t* data, size_t size) mutable { | ||
bitmap.reset(); | ||
} // proc | ||
); | ||
|
||
return { | ||
{bitmap->pixmap().dimensions().fWidth, | ||
bitmap->pixmap().dimensions().fHeight}, // size | ||
DecompressedImage::Format::kRGBA, // format | ||
mapping // allocation | ||
}; | ||
} | ||
|
||
} // namespace impeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#include "flutter/fml/macros.h" | ||
#include "impeller/image/compressed_image.h" | ||
|
||
namespace impeller { | ||
|
||
class CompressedImageSkia final : public CompressedImage { | ||
public: | ||
CompressedImageSkia(std::shared_ptr<const fml::Mapping> allocation); | ||
|
||
~CompressedImageSkia() override; | ||
|
||
// |CompressedImage| | ||
DecompressedImage Decode() const override; | ||
|
||
private: | ||
FML_DISALLOW_COPY_AND_ASSIGN(CompressedImageSkia); | ||
}; | ||
|
||
} // namespace impeller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.