Remove texture image. (flutter/engine#3434)
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
source_set("flow") {
|
||||
sources = [
|
||||
"bitmap_image.cc",
|
||||
"bitmap_image.h",
|
||||
"compositor_context.cc",
|
||||
"compositor_context.h",
|
||||
"instrumentation.cc",
|
||||
@@ -41,7 +39,6 @@ source_set("flow") {
|
||||
"raster_cache.h",
|
||||
"scene_update_context.cc",
|
||||
"scene_update_context.h",
|
||||
"texture_image.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
@@ -57,7 +54,6 @@ source_set("flow") {
|
||||
sources += [
|
||||
"layers/child_scene_layer.cc",
|
||||
"layers/child_scene_layer.h",
|
||||
"texture_image_none.cc",
|
||||
]
|
||||
public_deps = [
|
||||
"//apps/mozart/lib/skia",
|
||||
@@ -68,7 +64,6 @@ source_set("flow") {
|
||||
"gl_connection.cc",
|
||||
"gl_connection.h",
|
||||
"open_gl.h",
|
||||
"texture_image_gles2.cc",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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 "flutter/flow/bitmap_image.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
sk_sp<SkImage> BitmapImageCreate(SkImageGenerator& generator) {
|
||||
return SkImage::MakeFromGenerator(&generator);
|
||||
}
|
||||
|
||||
} // namespace flow
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FLOW_BITMAP_IMAGE_H_
|
||||
#define FLUTTER_FLOW_BITMAP_IMAGE_H_
|
||||
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageGenerator.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
sk_sp<SkImage> BitmapImageCreate(SkImageGenerator& generator);
|
||||
|
||||
} // namespace flow
|
||||
|
||||
#endif // FLUTTER_FLOW_BITMAP_IMAGE_H_
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FLOW_TEXTURE_IMAGE_H_
|
||||
#define FLUTTER_FLOW_TEXTURE_IMAGE_H_
|
||||
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageGenerator.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
sk_sp<SkImage> TextureImageCreate(GrContext* context,
|
||||
SkImageGenerator& generator);
|
||||
|
||||
} // namespace flow
|
||||
|
||||
#endif // FLUTTER_FLOW_TEXTURE_IMAGE_H_
|
||||
@@ -1,232 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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 "flutter/flow/texture_image.h"
|
||||
|
||||
#include "flutter/flow/open_gl.h"
|
||||
#include "flutter/glue/trace_event.h"
|
||||
#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
enum class TextureImageFormat {
|
||||
Grey,
|
||||
GreyAlpha,
|
||||
RGB,
|
||||
RGBA,
|
||||
};
|
||||
|
||||
enum class TextureImageDataFormat {
|
||||
UnsignedByte,
|
||||
UnsignedShort565,
|
||||
};
|
||||
|
||||
static inline GLint ToGLFormat(TextureImageFormat format) {
|
||||
switch (format) {
|
||||
case TextureImageFormat::RGBA:
|
||||
return GL_RGBA;
|
||||
case TextureImageFormat::RGB:
|
||||
return GL_RGB;
|
||||
case TextureImageFormat::Grey:
|
||||
return GL_LUMINANCE;
|
||||
case TextureImageFormat::GreyAlpha:
|
||||
return GL_LUMINANCE_ALPHA;
|
||||
}
|
||||
return GL_NONE;
|
||||
}
|
||||
|
||||
static inline GLint ToGLDataFormat(TextureImageDataFormat dataFormat) {
|
||||
switch (dataFormat) {
|
||||
case TextureImageDataFormat::UnsignedByte:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case TextureImageDataFormat::UnsignedShort565:
|
||||
return GL_UNSIGNED_SHORT_5_6_5;
|
||||
}
|
||||
return GL_NONE;
|
||||
}
|
||||
|
||||
static inline GrPixelConfig ToGrPixelConfig(TextureImageDataFormat dataFormat) {
|
||||
switch (dataFormat) {
|
||||
case TextureImageDataFormat::UnsignedByte:
|
||||
return kRGBA_8888_GrPixelConfig;
|
||||
case TextureImageDataFormat::UnsignedShort565:
|
||||
return kRGB_565_GrPixelConfig;
|
||||
}
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
static inline SkColorType ToSkColorType(TextureImageFormat format) {
|
||||
switch (format) {
|
||||
case TextureImageFormat::RGBA:
|
||||
return SkColorType::kRGBA_8888_SkColorType;
|
||||
case TextureImageFormat::RGB:
|
||||
case TextureImageFormat::Grey:
|
||||
case TextureImageFormat::GreyAlpha:
|
||||
// Add more specializations for greyscale images.
|
||||
return SkColorType::kRGB_565_SkColorType;
|
||||
}
|
||||
return kRGB_565_SkColorType;
|
||||
}
|
||||
|
||||
static sk_sp<SkImage> TextureImageCreate(GrContext* context,
|
||||
TextureImageFormat format,
|
||||
const SkISize& size,
|
||||
TextureImageDataFormat dataFormat,
|
||||
const uint8_t* data) {
|
||||
TRACE_EVENT2("flutter", __func__, "width", size.width(), "height",
|
||||
size.height());
|
||||
|
||||
if (!context)
|
||||
return nullptr;
|
||||
|
||||
GLuint handle = GL_NONE;
|
||||
|
||||
// Generate the texture handle.
|
||||
glGenTextures(1, &handle);
|
||||
|
||||
// Bind the texture.
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
|
||||
// Specify default texture properties.
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Update unpack alignment based on format.
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,
|
||||
dataFormat == TextureImageDataFormat::UnsignedByte ? 4 : 2);
|
||||
|
||||
GLint gl_format = ToGLFormat(format);
|
||||
|
||||
// Upload the texture.
|
||||
glTexImage2D(GL_TEXTURE_2D, // target
|
||||
0, // level
|
||||
gl_format, // internal format
|
||||
size.fWidth, // width
|
||||
size.fHeight, // height
|
||||
0, // border
|
||||
gl_format, // format
|
||||
ToGLDataFormat(dataFormat), // format
|
||||
data);
|
||||
|
||||
// Clear the binding. We are done.
|
||||
glBindTexture(GL_TEXTURE_2D, GL_NONE);
|
||||
|
||||
// Flush the texture before it can be bound by another thread.
|
||||
glFlush();
|
||||
|
||||
GrGLTextureInfo texInfo;
|
||||
texInfo.fTarget = GL_TEXTURE_2D;
|
||||
texInfo.fID = handle;
|
||||
|
||||
// Create an SkImage handle from the texture.
|
||||
GrBackendTextureDesc desc;
|
||||
|
||||
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
|
||||
desc.fFlags = kNone_GrBackendTextureFlag;
|
||||
desc.fWidth = size.fWidth;
|
||||
desc.fHeight = size.fHeight;
|
||||
desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&texInfo);
|
||||
|
||||
desc.fConfig = ToGrPixelConfig(dataFormat);
|
||||
|
||||
if (auto image = SkImage::MakeFromAdoptedTexture(context, desc)) {
|
||||
// Texture handle was successfully adopted by the SkImage.
|
||||
return image;
|
||||
}
|
||||
|
||||
// We could not create an SkImage from the texture. Since it could not be
|
||||
// adopted, delete the handle and return null.
|
||||
glDeleteTextures(1, &handle);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static sk_sp<SkImage> TextureImageCreate(GrContext* context,
|
||||
const SkBitmap& bitmap) {
|
||||
if (context == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (bitmap.drawsNothing()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextureImageDataFormat dataFormat = TextureImageDataFormat::UnsignedByte;
|
||||
TextureImageFormat imageFormat = TextureImageFormat::RGBA;
|
||||
|
||||
switch (bitmap.colorType()) {
|
||||
case kRGB_565_SkColorType:
|
||||
dataFormat = TextureImageDataFormat::UnsignedShort565;
|
||||
imageFormat = TextureImageFormat::RGB;
|
||||
break;
|
||||
case kRGBA_8888_SkColorType:
|
||||
dataFormat = TextureImageDataFormat::UnsignedByte;
|
||||
imageFormat = TextureImageFormat::RGBA;
|
||||
break;
|
||||
default:
|
||||
// Add more as supported.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return TextureImageCreate(
|
||||
context, // context
|
||||
imageFormat, // image format
|
||||
SkISize::Make(bitmap.width(), bitmap.height()), // size
|
||||
dataFormat, // data format
|
||||
reinterpret_cast<const uint8_t*>(bitmap.getPixels()) // data
|
||||
);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> TextureImageCreate(GrContext* context,
|
||||
SkImageGenerator& generator) {
|
||||
if (context == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const SkImageInfo& info = generator.getInfo();
|
||||
|
||||
if (info.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextureImageFormat imageFormat = TextureImageFormat::RGBA;
|
||||
bool preferOpaque = SkAlphaTypeIsOpaque(info.alphaType());
|
||||
|
||||
if (preferOpaque) {
|
||||
imageFormat = TextureImageFormat::RGB;
|
||||
}
|
||||
|
||||
auto preferredImageInfo =
|
||||
SkImageInfo::Make(info.bounds().width(), // width
|
||||
info.bounds().height(), // height
|
||||
ToSkColorType(imageFormat), // color type
|
||||
preferOpaque ? SkAlphaType::kOpaque_SkAlphaType
|
||||
: SkAlphaType::kPremul_SkAlphaType);
|
||||
|
||||
SkBitmap bitmap;
|
||||
|
||||
{
|
||||
TRACE_EVENT1("flutter", "DecodePrimaryPreferrence", "Type",
|
||||
preferOpaque ? "RGB565" : "RGBA8888");
|
||||
// Try our preferred config.
|
||||
if (generator.tryGenerateBitmap(&bitmap, preferredImageInfo, nullptr)) {
|
||||
// Our got our preferred bitmap.
|
||||
return TextureImageCreate(context, bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
TRACE_EVENT0("flutter", "DecodeRecommended");
|
||||
// Try the guessed config.
|
||||
if (generator.tryGenerateBitmap(&bitmap, generator.getInfo(), nullptr)) {
|
||||
return TextureImageCreate(context, bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace flow
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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 "flutter/flow/texture_image.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
sk_sp<SkImage> TextureImageCreate(GrContext* context,
|
||||
SkImageGenerator& generator) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace flow
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "flutter/lib/ui/painting/image_decoding.h"
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/flow/bitmap_image.h"
|
||||
#include "flutter/flow/texture_image.h"
|
||||
#include "flutter/glue/trace_event.h"
|
||||
#include "flutter/lib/ui/painting/image.h"
|
||||
#include "flutter/lib/ui/painting/resource_context.h"
|
||||
@@ -24,45 +22,28 @@ using tonic::ToDart;
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
void DeleteReleaseProc(const void* ptr, void* context) {
|
||||
delete static_cast<std::vector<uint8_t>*>(context);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> DecodeImage(std::vector<uint8_t> buffer) {
|
||||
sk_sp<SkImage> DecodeImage(sk_sp<SkData> buffer) {
|
||||
TRACE_EVENT0("blink", "DecodeImage");
|
||||
|
||||
if (buffer.empty())
|
||||
return nullptr;
|
||||
|
||||
sk_sp<SkData> sk_data = SkData::MakeWithoutCopy(buffer.data(), buffer.size());
|
||||
|
||||
if (sk_data == nullptr)
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<SkImageGenerator> generator(
|
||||
SkImageGenerator::NewFromEncoded(sk_data.get()));
|
||||
|
||||
if (generator == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// First, try to create a texture image from the generator.
|
||||
GrContext* context = ResourceContext::Get();
|
||||
if (sk_sp<SkImage> image = flow::TextureImageCreate(context, *generator))
|
||||
return image;
|
||||
|
||||
// Then, as a fallback, try to create a regular Skia managed image. These
|
||||
// don't require a context ready.
|
||||
std::vector<uint8_t>* data_buffer =
|
||||
new std::vector<uint8_t>(std::move(buffer));
|
||||
if (data_buffer == nullptr)
|
||||
return nullptr;
|
||||
sk_data = SkData::MakeWithProc(data_buffer->data(), data_buffer->size(),
|
||||
DeleteReleaseProc, data_buffer);
|
||||
if (sk_data == nullptr) {
|
||||
delete data_buffer;
|
||||
if (buffer == nullptr || buffer->isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return SkImage::MakeFromEncoded(sk_data);
|
||||
|
||||
auto raster_image = SkImage::MakeFromEncoded(std::move(buffer));
|
||||
|
||||
if (raster_image == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (auto context = ResourceContext::Get()) {
|
||||
auto colorspace = SkColorSpace::MakeSRGB();
|
||||
if (auto texture_image =
|
||||
raster_image->makeTextureImage(context, colorspace.get())) {
|
||||
return texture_image;
|
||||
}
|
||||
}
|
||||
|
||||
return raster_image;
|
||||
}
|
||||
|
||||
void InvokeImageCallback(sk_sp<SkImage> image,
|
||||
@@ -82,7 +63,7 @@ void InvokeImageCallback(sk_sp<SkImage> image,
|
||||
|
||||
void DecodeImageAndInvokeImageCallback(
|
||||
std::unique_ptr<DartPersistentValue> callback,
|
||||
std::vector<uint8_t> buffer) {
|
||||
sk_sp<SkData> buffer) {
|
||||
sk_sp<SkImage> image = DecodeImage(std::move(buffer));
|
||||
Threads::UI()->PostTask(
|
||||
ftl::MakeCopyable([ callback = std::move(callback), image ]() mutable {
|
||||
@@ -106,8 +87,7 @@ void DecodeImageFromList(Dart_NativeArguments args) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(list.data());
|
||||
std::vector<uint8_t> buffer(bytes, bytes + list.num_elements());
|
||||
auto buffer = SkData::MakeWithCopy(list.data(), list.num_elements());
|
||||
|
||||
Threads::IO()->PostTask(ftl::MakeCopyable([
|
||||
callback = std::make_unique<DartPersistentValue>(
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/vsync_waiter_fallback.h"
|
||||
#include "lib/ftl/functional/make_copyable.h"
|
||||
#include "third_party/skia/include/gpu/GrContextOptions.h"
|
||||
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
|
||||
|
||||
namespace shell {
|
||||
@@ -164,9 +165,18 @@ void PlatformView::SetupResourceContextOnIOThreadPerform(
|
||||
return;
|
||||
}
|
||||
|
||||
GrContextOptions options;
|
||||
// There is currently a bug with doing GPU YUV to RGB conversions on the IO
|
||||
// thread. The necessary work isn't being flushed or synchronized with the
|
||||
// other threads correctly, so the textures end up blank. For now, suppress
|
||||
// that feature, which will cause texture uploads to do CPU YUV conversion.
|
||||
options.fDisableGpuYUVConversion = true;
|
||||
|
||||
blink::ResourceContext::Set(GrContext::Create(
|
||||
GrBackend::kOpenGL_GrBackend,
|
||||
reinterpret_cast<GrBackendContext>(GrGLCreateNativeInterface())));
|
||||
reinterpret_cast<GrBackendContext>(GrGLCreateNativeInterface()),
|
||||
options));
|
||||
|
||||
latch->Signal();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user