diff --git a/display-p3/README.md b/display-p3/README.md deleted file mode 100644 index 3a70153d3..000000000 --- a/display-p3/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# display-p3 ImageView Sample - -A sample to view Display P3 images on Android devices. If Android OS and device -both support display P3 mode, two versions of the image will be displayed: - -- Display P3 view on the left hand side -- sRGB view on the right hand side - -## Pre-requisites - -- [Android Oreo](https://developer.android.com/about/versions/oreo/index.html) - (API level >= 26) device that supports wide color gamut mode (Implemented on - Android Oreo with Display P3 color space) -- Android Studio 3.5.2+ -- Android [NDK-r20+](https://developer.android.com/ndk/downloads/index.html) - -## Getting Started - -1. Enable "Natural" mode for "Color" configuration: Settings > Display > Colors -1. [Download Android Studio](https://developer.android.com/studio/index.html) -1. [Download Android NDK-r15+](https://developer.android.com/ndk/downloads/index.html) -1. [Download source code](http://www.github.com/googlesamples/android-ndk) -1. Launch Android Studio. -1. "File"-->"New" --> "Import Project", select display-p3/build.gradle -1. "Run" --> "Run 'app'" - -## Screenshots - -![screenshot](screenshot.png) - -## Description - -This sample creates -[Display P3](https://developer.android.com/about/versions/oreo/android-8.0.html#cm) -EGLContext\_, then creates 2 textures for each PNG file under "assets" folder, -and on Android devices support Display P3: - -- the first is in Display P3 image mode, -- the second is in sRGB mode. The sRGB texture is created by transforming the - original Display P3 image into CIExyz 1931 color space, clamping colors in - sRGB color space, then transforming it back to Display P3 color space to - display. - -For Android Devices that does NOT support display P3, both textures will be in -sRGB (identical view) - -The Display P3 mode is turned on when application requests a window surface of -type `EGL_GL_COLORSPACE_DISPLAY_P3_EXT`: - -```java - std::vector attributes; - attributes.push_back(EGL_GL_COLORSPACE_KHR); - attributes.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_EXT); - attributes.push_back(EGL_NONE); - engine->surface_ = eglCreateWindowSurface( - engine->display_, config, engine->app->window, attributes.data()); - -``` - -Android 10+ supports EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, the sample -detects the extension and enables it instead of -EGL_GL_COLORSPACE_DISPLAY_P3_EXT. The difference between the two is on how to -handle OETF/EOTF ( gamma like thing): - -- EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT tells hardware to bypass - OETF/EOTF transfer functions -- EGL_GL_COLORSPACE_DISPLAY_P3_EXT enables transfer functions when writing to - framebuffers. Note that the implementation on Android 8 and Android 9 for - EGL_GL_COLORSPACE_DISPLAY_P3_EXT may varies on your test devices, if you see - the color washing out or too dark, you could change the code to alter - OETF/EOTF functionality and texture's setting to get a correct setting fit - your system. - -All images under the assets folder are *assumed* to be already encoded in -Display P3 color space: - -- gamma value : 2.2 -- Display P3 color space with D65 as white reference point - -To add new images, simply drop the new file into this folder. Please note that -all decompressing is performed on CPU at the start up time: it takes time when -there are lot of image files. - -Some of the images are from -[codelogic's wide-gamut-tests](https://github.com/codelogic/wide-gamut-tests) -repo. On Display P3 capable devices, details inside red and green areas are -noticeably different, blue area is almost the same, just as expected. - -Changing display mode: - -- Tap on image to show/hide (Display P3 mode or sRGB mode) -- Swipe up/down to rotate through image files - -More About Wide Color Gamut - -- [Color Management in Android Oreo](https://developer.android.com/about/versions/oreo/android-8.0.html#cm) -- [Understanding Color (talk at Google I/O 2017)](https://www.youtube.com/watch?v=r8NeG0wmFXM) -- [Enhancing Graphics with Wide Color Content](https://developer.android.com/training/wide-color-gamut/index.html) - -## Version History - -| Version | Date | Note | -| --------- | -------- | -------------------------------- | -| 1.0 | 07/2017 | Initial Version | -| --------- | -------- | -------------------------------- | -| 1.1 | 12/2019 | Added P3_PASSTHROUGH_EXT | - -## Support - -If you've found an error in these samples, please -[file an issue](https://github.com/googlesamples/android-ndk/issues/new). - -Patches are encouraged, and may be submitted by -[forking this project](https://github.com/googlesamples/android-ndk/fork) and -submitting a pull request through GitHub. Please see -[CONTRIBUTING.md](../CONTRIBUTING.md) for more details. - -- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk) -- [Android Tools Feedbacks](http://tools.android.com/feedback) - -## License - -Copyright 2017 Google, Inc. - -Licensed to the Apache Software Foundation (ASF) under one or more contributor -license agreements. See the NOTICE file distributed with this work for -additional information regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed -under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. diff --git a/display-p3/image-view/build.gradle b/display-p3/image-view/build.gradle deleted file mode 100644 index 8d01ca5a5..000000000 --- a/display-p3/image-view/build.gradle +++ /dev/null @@ -1,49 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.example.widecolor' - defaultConfig { - applicationId = 'com.example.widecolor' - // p3_passthrough_ext starts from Android-29 - // it could be lowered to Android-26, from which p3_ext started - // TODO: Make the sample degrade gracefully on older API levels, reduce to 24 or 21. - minSdkVersion 29 - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static', '-DANDROID_PLATFORM=android-29' - } - } - } - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} - -// TODO: Vendor this into the tree. -// download third_party libs: mathfu, stb -List TARGET_DIR = [projectDir.toString() + '/../third_party/mathfu', - projectDir.toString() + '/../third_party/stb'] -List> GIT_PARAMETERS = - [['clone', '--recursive', 'https://github.com/google/mathfu.git', 'mathfu'], - ['clone', '--recursive', 'https://github.com/nothings/stb.git', 'stb']] -List WORKING_DIR = [projectDir.toString() + '/../third_party', - projectDir.toString() + '/../third_party'] -for (int i = 0; i < TARGET_DIR.size(); i++) { - if (!file(TARGET_DIR[i].toString()).exists()) { - if(!file(WORKING_DIR[i].toString()).exists()) - file(WORKING_DIR[i].toString()).mkdir() - exec { - workingDir(file(WORKING_DIR[i].toString())) - executable "git" - args GIT_PARAMETERS[i] - } - } -} - -dependencies { - implementation libs.appcompat -} diff --git a/display-p3/image-view/src/main/AndroidManifest.xml b/display-p3/image-view/src/main/AndroidManifest.xml deleted file mode 100644 index 4567d7b0b..000000000 --- a/display-p3/image-view/src/main/AndroidManifest.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/display-p3/image-view/src/main/assets/Color04.png b/display-p3/image-view/src/main/assets/Color04.png deleted file mode 100644 index b9ba0dd5d..000000000 Binary files a/display-p3/image-view/src/main/assets/Color04.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/Color_Space-920x400.png b/display-p3/image-view/src/main/assets/Color_Space-920x400.png deleted file mode 100644 index 447009661..000000000 Binary files a/display-p3/image-view/src/main/assets/Color_Space-920x400.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/P3-sRGB-blue.png b/display-p3/image-view/src/main/assets/P3-sRGB-blue.png deleted file mode 100644 index ae0c8e6ff..000000000 Binary files a/display-p3/image-view/src/main/assets/P3-sRGB-blue.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/P3-sRGB-color-bars.png b/display-p3/image-view/src/main/assets/P3-sRGB-color-bars.png deleted file mode 100644 index d6687d726..000000000 Binary files a/display-p3/image-view/src/main/assets/P3-sRGB-color-bars.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/P3-sRGB-color-ring.png b/display-p3/image-view/src/main/assets/P3-sRGB-color-ring.png deleted file mode 100644 index bc3918642..000000000 Binary files a/display-p3/image-view/src/main/assets/P3-sRGB-color-ring.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/P3-sRGB-green.png b/display-p3/image-view/src/main/assets/P3-sRGB-green.png deleted file mode 100644 index f6b91784b..000000000 Binary files a/display-p3/image-view/src/main/assets/P3-sRGB-green.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/P3-sRGB-red.png b/display-p3/image-view/src/main/assets/P3-sRGB-red.png deleted file mode 100644 index e841dccf8..000000000 Binary files a/display-p3/image-view/src/main/assets/P3-sRGB-red.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/Webkit-logo-P3.png b/display-p3/image-view/src/main/assets/Webkit-logo-P3.png deleted file mode 100644 index 55bad7f81..000000000 Binary files a/display-p3/image-view/src/main/assets/Webkit-logo-P3.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/gradient.png b/display-p3/image-view/src/main/assets/gradient.png deleted file mode 100644 index 2d2de61c7..000000000 Binary files a/display-p3/image-view/src/main/assets/gradient.png and /dev/null differ diff --git a/display-p3/image-view/src/main/assets/jwcolourtestcard1024.png b/display-p3/image-view/src/main/assets/jwcolourtestcard1024.png deleted file mode 100644 index 92c84ba0d..000000000 Binary files a/display-p3/image-view/src/main/assets/jwcolourtestcard1024.png and /dev/null differ diff --git a/display-p3/image-view/src/main/cpp/AndroidMain.cpp b/display-p3/image-view/src/main/cpp/AndroidMain.cpp deleted file mode 100644 index cc7d437db..000000000 --- a/display-p3/image-view/src/main/cpp/AndroidMain.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "ImageViewEngine.h" - -/** - * Process the next main command. - */ -static void engine_handle_cmd(struct android_app* app, int32_t cmd) { - ImageViewEngine* engine = (ImageViewEngine*)app->userData; - switch (cmd) { - case APP_CMD_SAVE_STATE: - break; - case APP_CMD_INIT_WINDOW: - // The window is being shown, get it ready. - if (app->window != NULL) { - engine->InitializeDisplay(); - engine->DrawFrame(); - engine->EnableAnimation(true); - } - break; - case APP_CMD_TERM_WINDOW: - // The window is being hidden or closed, clean it up. - engine->TerminateDisplay(); - break; - case APP_CMD_GAINED_FOCUS: - // When our app gains focus, we start monitoring the accelerometer. - if (engine->accelerometerSensor != NULL) { - ASensorEventQueue_enableSensor(engine->sensorEventQueue, - engine->accelerometerSensor); - // We'd like to get 60 events per second (in us). - ASensorEventQueue_setEventRate(engine->sensorEventQueue, - engine->accelerometerSensor, - (1000L / 60) * 1000); - engine->EnableAnimation(true); - } - break; - case APP_CMD_LOST_FOCUS: - // When our app loses focus, we stop monitoring the accelerometer. - // This is to avoid consuming battery while not being used. - if (engine->accelerometerSensor != NULL) { - ASensorEventQueue_disableSensor(engine->sensorEventQueue, - engine->accelerometerSensor); - } - // Also stop animating_. - engine->EnableAnimation(false); - engine->DrawFrame(); - break; - } -} - -/* - * Process the next input event. - */ -static int32_t engine_handle_input(struct android_app* app, - AInputEvent* event) { - ImageViewEngine* engine = (ImageViewEngine*)app->userData; - - if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { - engine->ProcessInputEvent(event); - - return 1; - } - return 0; -} - -/** - * This is the main entry point of a native application that is using - * android_native_app_glue. It runs in its own thread, with its own - * event loop for receiving input events and doing other things. - */ -void android_main(struct android_app* state) { - ImageViewEngine engine(state); - - state->userData = &engine; - state->onAppCmd = engine_handle_cmd; - state->onInputEvent = engine_handle_input; - - // Prepare to monitor accelerometer - engine.sensorManager = - ASensorManager_getInstanceForPackage("com.example.widecolor"); - engine.accelerometerSensor = ASensorManager_getDefaultSensor( - engine.sensorManager, ASENSOR_TYPE_ACCELEROMETER); - engine.sensorEventQueue = ASensorManager_createEventQueue( - engine.sensorManager, state->looper, LOOPER_ID_USER, NULL, NULL); - - while (!state->destroyRequested) { - // If not animating_, we will block forever waiting for events. - // If animating_, we loop until all events are read, then continue - // to draw the next frame of animation. - struct android_poll_source* source = nullptr; - int ident = ALooper_pollOnce(engine.GetAnimationStatus() ? 0 : -1, nullptr, - nullptr, (void**)&source); - ASSERT(ident != ALOOPER_POLL_ERROR, "ALooper_pollOnce returned and error"); - // Process this event. - if (source != NULL) { - source->process(state, source); - } - - // If a sensor has data, process it now. - if (ident == LOOPER_ID_USER) { - if (engine.accelerometerSensor != NULL) { - ASensorEvent event; - while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event, - 1) > 0) { - } - } - } - - if (engine.GetAnimationStatus()) { - engine.DrawFrame(); - } - } - - engine.TerminateDisplay(); -} diff --git a/display-p3/image-view/src/main/cpp/AppTexture.cpp b/display-p3/image-view/src/main/cpp/AppTexture.cpp deleted file mode 100644 index 47c502fd2..000000000 --- a/display-p3/image-view/src/main/cpp/AppTexture.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "AssetUtil.h" -#include "ImageViewEngine.h" - -/* - * DeleteTextures() - * Release all textures created in engine - */ -void ImageViewEngine::DeleteTextures(void) { - for (auto& tex : textures_) { - delete tex; - } - textures_.resize(0); -} - -/* - * CreateTextures() - * Create 2 textures in current display_ color space ( P3 or sRGB) - * If it is P3 space, image is transformed through sRGB so colors - * outside sRGB gamut are removed. - */ -bool ImageViewEngine::CreateTextures(void) { - std::vector files; - AssetEnumerateFileType(app_->activity->assetManager, ".png", files); - if (files.empty()) { - return false; - } - DeleteTextures(); - - for (auto& f : files) { - AssetTexture* tex = new AssetTexture(f); - ASSERT(tex, "OUT OF MEMORY"); - tex->ColorSpace(dispColorSpace_); - bool status = tex->CreateGLTextures(app_->activity->assetManager); - ASSERT(status, "Failed to create Texture for %s", f.c_str()); - textures_.push_back(tex); - } - - return true; -} diff --git a/display-p3/image-view/src/main/cpp/AssetTexture.cpp b/display-p3/image-view/src/main/cpp/AssetTexture.cpp deleted file mode 100644 index b8891a083..000000000 --- a/display-p3/image-view/src/main/cpp/AssetTexture.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#define STB_IMAGE_IMPLEMENTATION -#define STBI_ONLY_PNG -#include "AssetTexture.h" - -#include - -#include "AssetUtil.h" -#include "ColorSpaceTransform.h" -#include "ImageViewEngine.h" -#include "simple_png.h" - -#define INVALID_TEXTURE_ID 0xFFFFFFFF -AssetTexture::AssetTexture(const std::string& name) - : name_(name), - p3Id_(INVALID_TEXTURE_ID), - sRGBId_(INVALID_TEXTURE_ID), - valid_(false), - dispColorSpace_(DISPLAY_COLORSPACE::INVALID) {} - -AssetTexture::~AssetTexture() { - if (valid_) { - glDeleteTextures(1, &p3Id_); - glDeleteTextures(1, &sRGBId_); - valid_ = false; - p3Id_ = INVALID_TEXTURE_ID; - sRGBId_ = INVALID_TEXTURE_ID; - } -} - -void AssetTexture::ColorSpace(enum DISPLAY_COLORSPACE space) { - ASSERT(space != DISPLAY_COLORSPACE::INVALID, "invalid dispColorSpace_"); - // should release all of the previous valid textures... - dispColorSpace_ = space; -} -DISPLAY_COLORSPACE AssetTexture::ColorSpace(void) { return dispColorSpace_; } - -bool AssetTexture::IsValid(void) { return valid_; } - -GLuint AssetTexture::P3TexId() { - ASSERT(valid_, "Texture has not created"); - return p3Id_; -} - -GLuint AssetTexture::SRGBATexId() { - ASSERT(valid_, "texture has not been created"); - return sRGBId_; -} - -/* - * CreateGLTexture() - * Create textures with regard to current display_ color space. - * For P3 image, one texture is created with original image; the second - * texture is created from: - * original image --> sRGB color Space --> display_ color space - * during the process, colors outside sRGB are clamped. - */ -bool AssetTexture::CreateGLTextures(AAssetManager* mgr) { - ASSERT(mgr, "Asset Manager is not valid"); - ASSERT(dispColorSpace_ != DISPLAY_COLORSPACE::INVALID, - "eglContext_ color space not set"); - if (valid_) { - glDeleteTextures(1, &p3Id_); - glDeleteTextures(1, &sRGBId_); - valid_ = false; - p3Id_ = INVALID_TEXTURE_ID; - sRGBId_ = INVALID_TEXTURE_ID; - } - - glGenTextures(1, &p3Id_); - glBindTexture(GL_TEXTURE_2D, p3Id_); - - std::vector fileData; - AssetReadFile(mgr, name_, fileData); - - uint32_t imgWidth, imgHeight, n; - uint8_t* imageData = stbi_load_from_memory( - fileData.data(), fileData.size(), reinterpret_cast(&imgWidth), - reinterpret_cast(&imgHeight), reinterpret_cast(&n), 4); - uint8_t* imgBits = imageData; - std::vector staging; - if (dispColorSpace_ == DISPLAY_COLORSPACE::SRGB) { - staging.resize(imgWidth * imgHeight * 4 * sizeof(uint8_t)); - IMAGE_FORMAT src{ - .buf_ = imageData, - .width_ = imgWidth, - .height_ = imgHeight, - .gamma_ = DEFAULT_P3_IMAGE_GAMMA, - .npm_ = GetTransformNPM(NPM_TYPE::P3_D65), - }; - - IMAGE_FORMAT dst{ - .buf_ = staging.data(), - .width_ = imgWidth, - .height_ = imgHeight, - .gamma_ = DEFAULT_DISPLAY_GAMMA, - .npm_ = GetTransformNPM(NPM_TYPE::SRGB_D65_INV), - }; - TransformColorSpace(dst, src); - imgBits = staging.data(); - } - - // Our texture content is EOTF encoded, but depends on display P3 mode, app - // chooses to use or bypass EOTF & OETF hardware functionality. See detailed - // comments in WideColorCtx.cpp If OETF/EOTF needs bypassed on Android P and - // before, set flag for the texture to be in RGBA to fake GPU to bypass - // OETF/EOTF ( gamma alike thing ). - GLint textureInternalFormat = GL_SRGB8_ALPHA8; - if (dispColorSpace_ == DISPLAY_COLORSPACE::P3_PASSTHROUGH) { - textureInternalFormat = GL_RGBA; - } - glTexImage2D(GL_TEXTURE_2D, 0, // mip level - textureInternalFormat, imgWidth, imgHeight, - 0, // border color - GL_RGBA, GL_UNSIGNED_BYTE, imgBits); - - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - // Generate sRGB view texture - glGenTextures(1, &sRGBId_); - glBindTexture(GL_TEXTURE_2D, sRGBId_); - if (dispColorSpace_ == DISPLAY_COLORSPACE::P3 || - dispColorSpace_ == DISPLAY_COLORSPACE::P3_PASSTHROUGH) { - IMAGE_FORMAT src{ - .buf_ = imageData, - .width_ = imgWidth, - .height_ = imgHeight, - .gamma_ = DEFAULT_P3_IMAGE_GAMMA, - .npm_ = GetTransformNPM(NPM_TYPE::P3_D65), - }; - std::vector srgbImg(imgWidth * imgHeight * 4 * sizeof(uint8_t)); - IMAGE_FORMAT dst{ - .buf_ = srgbImg.data(), - .width_ = imgWidth, - .height_ = imgHeight, - .gamma_ = 0.0f, // intermediate image stays in linear space - .npm_ = GetTransformNPM(NPM_TYPE::SRGB_D65_INV), - }; - TransformColorSpace(dst, src); - - // sRGB back to P3 so we could display_ it correctly on P3 device mode - staging.resize(imgWidth * imgHeight * 4 * sizeof(uint8_t)); - IMAGE_FORMAT tmp = src; - src = dst; // intermediate gamma is 0.0f - dst = tmp; // original src's gamma is preserved - src.npm_ = GetTransformNPM(NPM_TYPE::SRGB_D65); - dst.buf_ = staging.data(); - dst.npm_ = GetTransformNPM(NPM_TYPE::P3_D65_INV); - dst.gamma_ = DEFAULT_DISPLAY_GAMMA, - - TransformColorSpace(dst, src); - imgBits = staging.data(); - } - glTexImage2D(GL_TEXTURE_2D, 0, // mip level - textureInternalFormat, // GL_SRGB8_ALPHA8 for p3_ext mode, - // GL_RGBA for p3_passthrough_ext - imgWidth, imgHeight, - 0, // border color - GL_RGBA, GL_UNSIGNED_BYTE, imgBits); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - glBindTexture(GL_TEXTURE_2D, 0); - stbi_image_free(imageData); - valid_ = true; - - return true; -} - -std::string& AssetTexture::Name(void) { return name_; } diff --git a/display-p3/image-view/src/main/cpp/AssetTexture.h b/display-p3/image-view/src/main/cpp/AssetTexture.h deleted file mode 100644 index 44e40ae49..000000000 --- a/display-p3/image-view/src/main/cpp/AssetTexture.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __ASSET_TEXTURE_H__ -#define __ASSET_TEXTURE_H__ -#include -#include - -#include - -#include "common.h" - -class AssetTexture { - private: - std::string name_; - GLuint p3Id_; - GLuint sRGBId_; - bool valid_; - enum DISPLAY_COLORSPACE dispColorSpace_; - - public: - explicit AssetTexture(const std::string& name); - ~AssetTexture(); - void ColorSpace(enum DISPLAY_COLORSPACE clrSpace); - DISPLAY_COLORSPACE ColorSpace(void); - bool CreateGLTextures(AAssetManager* mgr); - bool IsValid(void); - GLuint P3TexId(void); - GLuint SRGBATexId(void); - std::string& Name(void); -}; - -#endif // __ASSET_TEXTURE_H__ diff --git a/display-p3/image-view/src/main/cpp/AssetUtil.cpp b/display-p3/image-view/src/main/cpp/AssetUtil.cpp deleted file mode 100644 index a7cf4833d..000000000 --- a/display-p3/image-view/src/main/cpp/AssetUtil.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "AssetUtil.h" - -#include - -#include "android_debug.h" - -#define IS_LOW_CHAR(c) ((c) >= 'a' && (c) <= 'z') -#define TO_UPPER_CHAR(c) (c + 'A' - 'a') -void StringToUpper(std::string& str) { - for (auto& ch : str) { - if (IS_LOW_CHAR(ch)) ch = TO_UPPER_CHAR(ch); - } -} -bool AssetEnumerateFileType(AAssetManager* assetManager, const char* type, - std::vector& files) { - if (!assetManager || !type || !*type) return false; - - std::string fileType(type); - if (fileType[0] != '.') { - fileType.insert(0, 1, '.'); - } - StringToUpper(fileType); - - AAssetDir* dir = AAssetManager_openDir(assetManager, ""); - - const char* name; - while ((name = AAssetDir_getNextFileName(dir))) { - std::string assetName(name); - if (assetName.length() <= fileType.length()) continue; - std::string assetType = assetName.substr( - assetName.length() - fileType.length(), fileType.length()); - StringToUpper(assetType); - - if (assetType == fileType) { - files.push_back(assetName); - } - } - LOGI("Found %d PNG Files", static_cast(files.size())); - - AAssetDir_close(dir); - return true; -} - -bool AssetReadFile(AAssetManager* assetManager, std::string& assetName, - std::vector& buf) { - if (!assetName.length()) return false; - AAsset* assetDescriptor = - AAssetManager_open(assetManager, assetName.c_str(), AASSET_MODE_BUFFER); - ASSERT(assetDescriptor, "%s does not exist in %s", assetName.c_str(), - __FUNCTION__); - size_t fileLength = AAsset_getLength(assetDescriptor); - - buf.resize(fileLength); - int64_t readSize = AAsset_read(assetDescriptor, buf.data(), buf.size()); - - AAsset_close(assetDescriptor); - return (readSize == buf.size()); -} diff --git a/display-p3/image-view/src/main/cpp/AssetUtil.h b/display-p3/image-view/src/main/cpp/AssetUtil.h deleted file mode 100644 index 24b5cc258..000000000 --- a/display-p3/image-view/src/main/cpp/AssetUtil.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef __ASSET__UTIL_H__ -#define __ASSET__UTIL_H__ - -#include - -#include -#include - -bool AssetEnumerateFileType(AAssetManager* assetManager, const char* type, - std::vector& files); -bool AssetReadFile(AAssetManager* assetManager, std::string& name, - std::vector& buf); - -#endif // __ASSET__UTIL_H__ diff --git a/display-p3/image-view/src/main/cpp/CMakeLists.txt b/display-p3/image-view/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 459bdc916..000000000 --- a/display-p3/image-view/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# -# Copyright (C) The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -cmake_minimum_required(VERSION 3.22.1) - -get_filename_component(THIRD_PARTY_LIB_DIR - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party - ABSOLUTE) - -# now build app's shared lib -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Werror -Wall -Wno-unused-function") - -add_library(native-activity SHARED - ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c - AssetUtil.cpp - AndroidMain.cpp - WideColorCtx.cpp - ShaderProgram.cpp - AppTexture.cpp - AssetTexture.cpp - ImageViewEngine.cpp - gldebug.cpp - ColorSpaceTransform.cpp - InputEventHandler.cpp) - -target_include_directories(native-activity PRIVATE - ${ANDROID_NDK}/sources/android/native_app_glue - ${THIRD_PARTY_LIB_DIR} - ${THIRD_PARTY_LIB_DIR}/mathfu/include - ${THIRD_PARTY_LIB_DIR}/mathfu/dependencies/vectorial/include) - -# add lib dependencies -target_link_libraries(native-activity - android - log - EGL - GLESv3) diff --git a/display-p3/image-view/src/main/cpp/ColorSpaceTransform.cpp b/display-p3/image-view/src/main/cpp/ColorSpaceTransform.cpp deleted file mode 100644 index 9d6982714..000000000 --- a/display-p3/image-view/src/main/cpp/ColorSpaceTransform.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "ColorSpaceTransform.h" - -#include -#include -#include - -#include "android_debug.h" - -#define EPSILON 0.000001f -#define HAS_GAMMA(x) (std::abs(x) > EPSILON && std::abs((x)-1.0f) > EPSILON) -#define CLIP_COLOR(color, max) ((color > max) ? max : ((color > 0) ? color : 0)) - -/* - * CreateGammaEncodeTable(): - * sRGB = - * 12.92 * LinearRGB 0 < LinearRGB < 0.0031308 - * 1.055 * power(LinearRGB, gamma)-0.055 0.0031308 <= LinarRGB <= 1.0f - */ -static void CreateGammaEncodeTable(float gamma, std::vector& table) { - ASSERT(gamma < 1.0f, "Wrong Gamma (%f) for encoding", gamma); - uint32_t maxPixeli = (1 << 8) - 1; - float maxPixelf = static_cast(maxPixeli); - - uint32_t maxLinearVal = static_cast(0.0031308f * maxPixeli); - - table.resize(0); - for (uint32_t idx = 0; idx < maxLinearVal; idx++) { - double val = idx * 12.92 + .5f; - table.push_back(static_cast(val)); - } - - for (uint32_t idx = maxLinearVal; idx <= maxPixeli; idx++) { - double val = (1.055f * pow(idx / maxPixelf, gamma) - 0.055f); - val = val * maxPixeli + 0.5f; - table.push_back(static_cast(CLIP_COLOR(val, maxPixelf))); - } -} -/* - * CreateGammaDecodeTable() - * Retrieve linear RGB data - * Linear = sRGB / 12.92 0 <= sRGB < 0.04045 - * pow((sRGB + 0.055)/1.055, gamma) - */ -static void CreateGammaDecodeTable(float gamma, std::vector& table) { - ASSERT(gamma > 1.0, "Wrong Gamma(%f) for decoding", gamma); - uint32_t maxPixeli = (1 << 8) - 1; - float maxPixelf = static_cast(maxPixeli); - - uint32_t maxLinearVal = static_cast(0.04045 * maxPixeli); - for (uint32_t idx = 0; idx < maxLinearVal; idx++) { - double val = idx / 12.92 + .5f; - table.push_back(static_cast(val)); - } - - for (uint32_t idx = maxLinearVal; idx <= maxPixeli; idx++) { - double val; - val = (idx / maxPixelf + 0.055f) / 1.055f; - val = pow(val, gamma) * maxPixeli + 0.5f; - table.push_back(static_cast(CLIP_COLOR(val, maxPixelf))); - } -} - -/* - * ApplyGamma() - * Perform gamma lookup for RGBA8888 format - */ -static bool ApplyGamma(void* dst, void* src, uint32_t w, uint32_t h, - std::vector& gammaTable) { - if (!src || !dst || gammaTable.empty()) { - LOGE("Invalid Input to %s, dst(%p),src(%p)", __FUNCTION__, dst, src); - return false; - } - uint8_t* imgSrc = static_cast(src); - uint8_t* imgDst = static_cast(dst); - for (uint32_t r = 0; r < w; r++) { - for (uint32_t c = 0; c < h; c++) { - *imgDst++ = gammaTable[*imgSrc++]; - *imgDst++ = gammaTable[*imgSrc++]; - *imgDst++ = gammaTable[*imgSrc++]; - *imgDst++ = *imgSrc++; - } - } - return true; -} - -/* - * GammaDecode(IMAGE_FORMAT& src): - * Decode gamma for src image - * src.gamma: the gamma used encoding the src image - * Ouput: - * src.buf_: gamma decoded image with gamma value of 1.0f/src.gamma - */ -static bool GammaDecode(IMAGE_FORMAT& src) { - if (!HAS_GAMMA(src.gamma_)) { - LOGE("No gamma value to source gamma"); - return true; - } - std::vector gammaTable; - CreateGammaDecodeTable(1.0f / src.gamma_, gammaTable); - - return ApplyGamma(src.buf_, src.buf_, src.width_, src.height_, gammaTable); -} - -static bool GammaDecode(IMAGE_FORMAT& dst, IMAGE_FORMAT& src) { - if (!HAS_GAMMA(src.gamma_)) { - LOGE("No gamma value to source gamma"); - return true; - } - std::vector gammaTable; - CreateGammaDecodeTable(1.0f / src.gamma_, gammaTable); - - return ApplyGamma(dst.buf_, src.buf_, src.width_, src.height_, gammaTable); -} - -/* - * GammaEncode(IMAGE_FORMAT& format dst) - * Gamma encode image with the gamma value of dst.gamma_ - */ -static bool GammaEncode(IMAGE_FORMAT& dst) { - if (!HAS_GAMMA(dst.gamma_)) { - LOGE("No gamma value to dst gamma"); - return true; - } - std::vector gammaTable; - CreateGammaEncodeTable(dst.gamma_, gammaTable); - - return ApplyGamma(dst.buf_, dst.buf_, dst.width_, dst.height_, gammaTable); -} - -/* - * ApplyTransform8888() - * dst = matrix * src - * and clamp the result to 0 -- 255 - */ -static bool TransformR8G8B8A8(uint8_t* dst, uint8_t* src, uint32_t width, - uint32_t height, mathfu::mat3& transMatrix) { - ASSERT(src && dst, "Wrong image store to %s", __FUNCTION__); - - int32_t m00, m01, m02, m10, m11, m12, m20, m21, m22; - m00 = static_cast(transMatrix(0, 0) * 1024 + 0.5f), - m01 = static_cast(transMatrix(0, 1) * 1024 + 0.5f); - m02 = static_cast(transMatrix(0, 2) * 1024 + 0.5f); - m10 = static_cast(transMatrix(1, 0) * 1024 + 0.5f); - m11 = static_cast(transMatrix(1, 1) * 1024 + 0.5f); - m12 = static_cast(transMatrix(1, 2) * 1024 + 0.5f); - m20 = static_cast(transMatrix(2, 0) * 1024 + 0.5f); - m21 = static_cast(transMatrix(2, 1) * 1024 + 0.5f); - m22 = static_cast(transMatrix(2, 2) * 1024 + 0.5f); - for (uint32_t row = 0; row < height; row++) { - for (uint32_t col = 0; col < width; col++) { - int32_t r, g, b; - r = (m00 * src[0] + m01 * src[1] + m02 * src[2] + 512) >> 10; - g = (m10 * src[0] + m11 * src[1] + m12 * src[2] + 512) >> 10; - b = (m20 * src[0] + m21 * src[1] + m22 * src[2] + 512) >> 10; - *dst++ = static_cast(CLIP_COLOR(r, 255)); - *dst++ = static_cast(CLIP_COLOR(g, 255)); - *dst++ = static_cast(CLIP_COLOR(b, 255)); - - src += 3; // update src pointer - *dst++ = *src++; // copy alpha - } - } - return true; -} - -/* - * Interface Function: - * Convert Color Spaces - */ -bool TransformColorSpace(IMAGE_FORMAT& dst, IMAGE_FORMAT& src) { - if (!src.npm_ || !dst.npm_ || !dst.buf_ || !src.buf_) { - LOGE("=====Error: Invalid Parameters to TransformColorSpace()"); - return false; - } - - uint8_t* dstBits = static_cast(dst.buf_); - uint8_t* srcBits = static_cast(src.buf_); - - if (HAS_GAMMA(src.gamma_)) { - GammaDecode(dst, src); - srcBits = dstBits; - } - - mathfu::mat3 matrix = *dst.npm_ * (*src.npm_); - TransformR8G8B8A8(dstBits, srcBits, src.width_, src.height_, matrix); - - if (HAS_GAMMA(dst.gamma_)) { - GammaEncode(dst); - } - - return true; -} - -/* - * Default NPMs with white reference points as D65 - * The array sequence should match enum NPM_TYPE definition - enum NPM_TYPE { - SRGB_D65 = 0, - SRGB_D65_INV, - P3_D65, - P3_D65_INV, - TYPE_COUNT - }; - */ -static mathfu::mat3 defaultNPMs[] = { - /* SRGB --> XYZ, White reference point D65 - * Digital Video and HDTV - * Algorithms and Interfaces - * Charles Poynton - */ - mathfu::mat3(0.4123908281f, 0.2126390338f, 0.0193308201f, 0.3575843275f, - 0.7151686549f, 0.1191947237f, 0.1804807931f, 0.0721923113f, - 0.9505321383f), - // XYZ --> SRGB white reference point D65 - mathfu::mat3(3.2409696579f, -0.9692436457f, 0.0556300320f, -1.5373830795f, - 1.8759675026f, -0.2039768547f, -0.4986107349f, 0.0415550880f, - 1.0569714308f), - /* P3 --> XYZ, white reference point D65 - * SMTP EG 432-1:2010, p23 - */ - mathfu::mat3(0.4865709245f, 0.2289745510f, 0.0000000000f, 0.2656676769f, - 0.6917385459f, 0.0451133996f, 0.1982172877f, 0.0792869106f, - 1.0439443588f), - /* - * CIE XYZ --> Display P3, white reference point D65. Source - * SMTP EG 432-1:2010, p24 - */ - mathfu::mat3(2.4934973717f, -0.8294889927f, 0.0358458459f, -0.9313836098f, - 1.7626641989f, -0.0761724263f, -0.4027108550f, 0.0236246940f, - 0.9568846226f), -}; -const mathfu::mat3* GetTransformNPM(NPM_TYPE type) { - ASSERT(type < NPM_TYPE::TYPE_COUNT, "NPM_TYPE (%d) out of bounds", type); - return &defaultNPMs[type]; -} diff --git a/display-p3/image-view/src/main/cpp/ColorSpaceTransform.h b/display-p3/image-view/src/main/cpp/ColorSpaceTransform.h deleted file mode 100644 index 214161347..000000000 --- a/display-p3/image-view/src/main/cpp/ColorSpaceTransform.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __COLOR_TRANSFORM_H__ -#define __COLOR_TRANSFORM_H__ - -#include - -#include - -struct IMAGE_FORMAT { - void* buf_; // packed image pointer - uint32_t width_, height_; - float gamma_; - const mathfu::mat3* npm_; -}; - -#define DEFAULT_DISPLAY_GAMMA (1.0f / 2.2f) -#define DEFAULT_P3_IMAGE_GAMMA (1.0f / 2.2f) - -/* - * TransformColorSpace(IMAGE_FORMAT& dst, IMAGE_FORMAT& src) - * Transforms image between DCI-P3 and sRGB space - * Dst.buf_ = dst.npm * src.npm * de-gamma(src.buf_) - * dst.buf_ = en-gamma(dst.buf_) - * dst.buf_: - * transformed image buf pointer; user must allocate enough space for the - * image src.buf_: source of the image bits to transform. Both src and dst must - * be in: R8G8B8A8 4 channels packed format - */ -bool TransformColorSpace(IMAGE_FORMAT& dst, IMAGE_FORMAT& src); - -/* - * GetTransformNPM - */ -enum NPM_TYPE { SRGB_D65 = 0, SRGB_D65_INV, P3_D65, P3_D65_INV, TYPE_COUNT }; -const mathfu::mat3* GetTransformNPM(NPM_TYPE type); - -#endif // __COLOR_TRANSFORM_H__ diff --git a/display-p3/image-view/src/main/cpp/ImageViewEngine.cpp b/display-p3/image-view/src/main/cpp/ImageViewEngine.cpp deleted file mode 100644 index 6e8fc81bd..000000000 --- a/display-p3/image-view/src/main/cpp/ImageViewEngine.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "ImageViewEngine.h" - -#include - -/* - * Create Rendering Context - */ -bool ImageViewEngine::InitializeDisplay(void) { - EnableWelcomeUI(); - - bool status = CreateWideColorCtx(); - ASSERT(status, "CreateWideColorContext() failed"); - - status = program_.createProgram(); - ASSERT(status, "CreateShaderProgram Failed"); - - status = CreateTextures(); - ASSERT(status, "LoadTextures() Failed") - - // Other GL States - glDisable(GL_DEPTH_TEST); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glViewport(0, 0, renderTargetWidth_, renderTargetHeight_); - - EnableRenderUI(); - return true; -} - -bool ImageViewEngine::GetAnimationStatus(void) { return animating_; } -void ImageViewEngine::EnableAnimation(bool enable) { animating_ = enable; } - -/* - * Draw quad(s) to view texture - */ -void ImageViewEngine::DrawFrame(void) { - if (display_ == NULL) { - return; - } - - const GLfloat leftQuadVertices[] = {-1.f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, - -1.0f, 1.0f, 0.0f, 0.0f}; - const GLfloat rightQuadVertices[] = {0.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f}; - - // Just fill the screen with a color. - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - glUseProgram(program_.getProgram()); - - glVertexAttribPointer(program_.getAttribLocation(), 2, GL_FLOAT, GL_FALSE, - sizeof(GLfloat) * 4, leftQuadVertices); - glEnableVertexAttribArray(program_.getAttribLocation()); - - glVertexAttribPointer(program_.getAttribLocationTex(), 2, GL_FLOAT, GL_FALSE, - sizeof(GLfloat) * 4, leftQuadVertices + 2); - glEnableVertexAttribArray(program_.getAttribLocationTex()); - int32_t texIdx = textureIdx_; - if (renderModeBits_ & RENDERING_P3) { - glActiveTexture(GL_TEXTURE0 + 0); - glBindTexture(GL_TEXTURE_2D, textures_[texIdx]->P3TexId()); - glUniform1i(program_.getSamplerLoc(), 0); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - } - if (renderModeBits_ & RENDERING_SRGB) { - glVertexAttribPointer(program_.getAttribLocation(), 2, GL_FLOAT, GL_FALSE, - sizeof(GLfloat) * 4, rightQuadVertices); - glVertexAttribPointer(program_.getAttribLocationTex(), 2, GL_FLOAT, - GL_FALSE, sizeof(GLfloat) * 4, rightQuadVertices + 2); - glActiveTexture(GL_TEXTURE0 + 1); - glBindTexture(GL_TEXTURE_2D, textures_[texIdx]->SRGBATexId()); - glUniform1i(program_.getSamplerLoc(), 1); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - } - - eglSwapBuffers(display_, surface_); -} - -/** - * Tear down the EGL context currently associated with the display. - */ -void ImageViewEngine::TerminateDisplay(void) { - animating_ = 0; - - if (display_ == EGL_NO_DISPLAY) return; - - DestroyWideColorCtx(); - - glDeleteProgram(program_.getProgram()); - DeleteTextures(); -} - -/* - * Initialize the application engine - */ -ImageViewEngine::ImageViewEngine(struct android_app* app) - : app_(app), animating_(0), textureIdx_(0) { - textures_.resize(0); - renderModeBits_ = RENDERING_P3 | RENDERING_SRGB; - eglContext_ = EGL_NO_CONTEXT; - surface_ = EGL_NO_SURFACE; - display_ = EGL_NO_DISPLAY; -} diff --git a/display-p3/image-view/src/main/cpp/ImageViewEngine.h b/display-p3/image-view/src/main/cpp/ImageViewEngine.h deleted file mode 100644 index 746ea9ccf..000000000 --- a/display-p3/image-view/src/main/cpp/ImageViewEngine.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __APP_ENGINE_H__ -#define __APP_ENGINE_H__ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "AssetTexture.h" -#include "ShaderProgram.h" -#include "android_debug.h" -#include "common.h" -#include "gldebug.h" - -class ImageViewEngine { - public: - ImageViewEngine(struct android_app* app); - - bool InitializeDisplay(void); - void TerminateDisplay(void); - - // Touch/swipe event handler - bool ProcessInputEvent(const AInputEvent* event); - - void DrawFrame(void); - bool GetAnimationStatus(void); - void EnableAnimation(bool enable); - - ASensorManager* sensorManager; - const ASensor* accelerometerSensor; - ASensorEventQueue* sensorEventQueue; - - private: - struct android_app* app_; - - int animating_; - EGLDisplay display_; - EGLSurface surface_; - DISPLAY_COLORSPACE dispColorSpace_; - DISPLAY_FORMAT dispFormat_; - - EGLContext eglContext_; - int32_t renderTargetWidth_; - int32_t renderTargetHeight_; - - ShaderProgram program_; - - // Image file texture store - std::vector textures_; - std::atomic textureIdx_; - - enum WIDECOLOR_MODE { - P3_PASSTHROUGH_R8G8B8A8_REV, - P3_PASSTHROUGH_R10G10B10A2_REV, - P3_PASSTHROUGH_FP16, - P3_R8G8B8A8_REV, - P3_R10G10B10A2_REV, - P3_FP16, - SRGBA_R8G8B8A8_REV, - MODE_COUNT - }; - bool CreateWideColorCtx(void); - bool CreateWideColorCtx(WIDECOLOR_MODE mode); - void DestroyWideColorCtx(void); - - bool CreateTextures(void); - void DeleteTextures(void); - - uint32_t renderModeBits_; - - // Input event data - mathfu::vec2 touchStartPos_; - uint64_t startTime_; - void ResetUserEventCache(void); - void ProcessTapEvent(int x, int y); - - // 2 TextView UI management - void EnableWelcomeUI(void); - void EnableRenderUI(void); - void UpdateUI(void); -}; - -#endif // __APP_ENGINE_H__ diff --git a/display-p3/image-view/src/main/cpp/InputEventHandler.cpp b/display-p3/image-view/src/main/cpp/InputEventHandler.cpp deleted file mode 100644 index d14aef339..000000000 --- a/display-p3/image-view/src/main/cpp/InputEventHandler.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include - -#include "ImageViewEngine.h" -#include "mathfu/glsl_mappings.h" -#include "mathfu/matrix.h" - -const uint64_t kSwipeThreshold = static_cast(1000000000); -const uint32_t kMinDistance = 100; -const uint32_t kMaxTapDistance = 10; -const uint32_t kMaxTapTime = static_cast(125000000); - -void ImageViewEngine::ResetUserEventCache(void) { - touchStartPos_ = mathfu::vec2(0.0f, 0.0f); - startTime_ = static_cast(0); -} - -void ImageViewEngine::ProcessTapEvent(int x, int y) { - // Get current display_ size: the phone is in landscape mode ( in - // AndroidManifest.xml ) - int halfWidth = renderTargetWidth_ / 2; - - if (x > halfWidth - 10 && x < halfWidth + 10) return; - - uint32_t mask = 1 << (x / halfWidth); - - renderModeBits_ = (renderModeBits_ & mask) ? (renderModeBits_ & ~mask) - : (renderModeBits_ | mask); - UpdateUI(); -} - -bool ImageViewEngine::ProcessInputEvent(const AInputEvent* event) { - if (AMotionEvent_getPointerCount(event) > 1) { - ResetUserEventCache(); - LOGE("more than one pointer action"); - return true; - } - - int32_t action = AMotionEvent_getAction(event); - if (action == AMOTION_EVENT_ACTION_CANCEL) { - ResetUserEventCache(); - return true; - } - - if (action == AMOTION_EVENT_ACTION_DOWN) { - touchStartPos_.x = AMotionEvent_getX(event, 0); - touchStartPos_.y = AMotionEvent_getY(event, 0); - startTime_ = AMotionEvent_getEventTime(event); - return true; - } else if (action == AMOTION_EVENT_ACTION_UP) { - uint64_t endTime = AMotionEvent_getEventTime(event); - if (endTime - startTime_ > kSwipeThreshold) { - return true; - } - - mathfu::vec2 v2; - v2.x = AMotionEvent_getX(event, 0); - v2.y = AMotionEvent_getY(event, 0); - - v2 = v2 - touchStartPos_; - if (endTime - startTime_ < kMaxTapTime && v2.Length() < kMaxTapDistance) { - LOGI("Detected a tap event, (%f, %f)", touchStartPos_.x, - touchStartPos_.y); - ProcessTapEvent(static_cast(touchStartPos_.x), - static_cast(touchStartPos_.y)); - return true; - } - - if (v2.Length() < kMinDistance) { - LOGI("---- too short to be considered a swipe"); - return true; - } - - if (std::abs(v2.x) > std::abs(v2.y)) { - ResetUserEventCache(); - return true; - } - - int offset = 1; - if (v2.y > 0) { - // swiping down, decrease the index... - offset = -1; - } - - uint32_t idx = textureIdx_; - idx += offset + textures_.size(); - textureIdx_ = idx % textures_.size(); - - UpdateUI(); - } - - return true; -} - -void ImageViewEngine::EnableWelcomeUI(void) { - JNIEnv* jni; - app_->activity->vm->AttachCurrentThread(&jni, NULL); - - // Default class retrieval - jclass clazz = jni->GetObjectClass(app_->activity->clazz); - jmethodID methodID = jni->GetMethodID(clazz, "EnableUI", "(I)V"); - jni->CallVoidMethod(app_->activity->clazz, methodID, renderModeBits_); - - app_->activity->vm->DetachCurrentThread(); -} - -void ImageViewEngine::EnableRenderUI(void) { - JNIEnv* jni; - app_->activity->vm->AttachCurrentThread(&jni, NULL); - - // Default class retrieval - jclass clazz = jni->GetObjectClass(app_->activity->clazz); - jmethodID methodID = - jni->GetMethodID(clazz, "EnableRenderUI", "(Ljava/lang/String;)V"); - - jstring file = jni->NewStringUTF(textures_[textureIdx_]->Name().c_str()); - jni->CallVoidMethod(app_->activity->clazz, methodID, file); - jni->DeleteLocalRef(file); - - app_->activity->vm->DetachCurrentThread(); -} -void ImageViewEngine::UpdateUI(void) { - JNIEnv* jni; - app_->activity->vm->AttachCurrentThread(&jni, NULL); - - // Default class retrieval - jclass clazz = jni->GetObjectClass(app_->activity->clazz); - jmethodID methodID = - jni->GetMethodID(clazz, "UpdateUI", "(ILjava/lang/String;)V"); - jstring file = jni->NewStringUTF(textures_[textureIdx_]->Name().c_str()); - jni->CallVoidMethod(app_->activity->clazz, methodID, renderModeBits_, file); - jni->DeleteLocalRef(file); - - app_->activity->vm->DetachCurrentThread(); -} diff --git a/display-p3/image-view/src/main/cpp/ShaderProgram.cpp b/display-p3/image-view/src/main/cpp/ShaderProgram.cpp deleted file mode 100644 index 62b9c20e7..000000000 --- a/display-p3/image-view/src/main/cpp/ShaderProgram.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "ShaderProgram.h" - -#include - -#include "android_debug.h" -#include "gldebug.h" - -static const char gVertexShader[] = - "#version 300 es \n" - "layout (location = 0) in vec4 vPosition;\n" - "layout (location = 1) in vec2 vTexture;\n" - "out vec2 vertex_tex; \n" - "void main() { \n" - " gl_Position = vPosition;\n" - " vertex_tex = vTexture; \n" - "}\n"; - -static const char gFragmentShader[] = - "#version 300 es \n" - "precision mediump float;\n" - "in vec2 vertex_tex; \n" - "uniform sampler2D samplerObj; \n" - "layout(location = 0) out vec4 oColor; \n" - "void main() { \n" - " oColor = texture(samplerObj, vertex_tex); \n" - "} \n"; - -GLuint loadShader(GLenum shaderType, const char* pSource) { - GLuint shader = glCreateShader(shaderType); - if (shader) { - glShaderSource(shader, 1, &pSource, NULL); - glCompileShader(shader); - GLint compiled = 0; - glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if (!compiled) { - GLint infoLen = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); - if (infoLen) { - std::vector buf(infoLen); - if (buf.capacity() > 0) { - glGetShaderInfoLog(shader, infoLen, NULL, buf.data()); - LOGE("Could not compile shader %d:\n%s\n", shaderType, buf.data()); - } - glDeleteShader(shader); - shader = 0; - } - } - } - return shader; -} - -GLuint ShaderProgram::createProgram(void) { - return createProgram(gVertexShader, gFragmentShader); -} -GLuint ShaderProgram::createProgram(const char* pVertexSource, - const char* pFragmentSource) { - GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource); - if (!vertexShader) { - return 0; - } - - GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource); - if (!pixelShader) { - return 0; - } - - gProgram_ = glCreateProgram(); - if (gProgram_) { - glAttachShader(gProgram_, vertexShader); - glAttachShader(gProgram_, pixelShader); - glLinkProgram(gProgram_); - GLint linkStatus = GL_FALSE; - glGetProgramiv(gProgram_, GL_LINK_STATUS, &linkStatus); - if (linkStatus != GL_TRUE) { - GLint bufLength = 0; - glGetProgramiv(gProgram_, GL_INFO_LOG_LENGTH, &bufLength); - if (bufLength) { - std::vector buf(bufLength); - if (buf.capacity() > 0) { - glGetProgramInfoLog(gProgram_, bufLength, NULL, buf.data()); - LOGE("Could not link program:\n%s\n", buf.data()); - } - } - glDeleteProgram(gProgram_); - gProgram_ = 0; - ASSERT(false, "Link Program failed"); - } else { - gvPositionHandle_ = glGetAttribLocation(gProgram_, "vPosition"); - gvTxtHandle_ = glGetAttribLocation(gProgram_, "vTexture"); - } - } - - return gProgram_; -} - -GLint ShaderProgram::getSamplerLoc(void) { - ASSERT(gProgram_, "Shader is not created"); - return glGetUniformLocation(gProgram_, "samplerObj"); -} diff --git a/display-p3/image-view/src/main/cpp/ShaderProgram.h b/display-p3/image-view/src/main/cpp/ShaderProgram.h deleted file mode 100644 index dc6ead675..000000000 --- a/display-p3/image-view/src/main/cpp/ShaderProgram.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef __SHADER_PROGRAM_H__ -#define __SHADER_PROGRAM_H__ - -#include - -class ShaderProgram { - public: - ShaderProgram(){}; - GLuint createProgram(void); - GLuint createProgram(const char* pVertexSource, const char* pFragmentSource); - GLuint getAttribLocation() const { return gvPositionHandle_; } - GLuint getAttribLocationTex() const { return gvTxtHandle_; } - GLuint getProgram() const { return gProgram_; } - GLint getSamplerLoc(void); - - private: - GLuint gProgram_; - GLuint gvPositionHandle_; - GLuint gvTxtHandle_; -}; - -#endif // __SHADER_PROGRAM_H__ diff --git a/display-p3/image-view/src/main/cpp/WideColorCtx.cpp b/display-p3/image-view/src/main/cpp/WideColorCtx.cpp deleted file mode 100644 index 6635d7142..000000000 --- a/display-p3/image-view/src/main/cpp/WideColorCtx.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "ImageViewEngine.h" -#include "android_debug.h" - -struct APP_WIDECOLOR_MODE_CFG { - DISPLAY_COLORSPACE space_; - DISPLAY_FORMAT fmt_; -}; -struct GL_WIDECOLOR_MODE_CFG { - EGLint space_; - EGLint r_, g_, b_, a_; -}; - -static const APP_WIDECOLOR_MODE_CFG appWideColorCfg[] = { - {DISPLAY_COLORSPACE::P3_PASSTHROUGH, DISPLAY_FORMAT::R8G8B8A8_REV}, - {DISPLAY_COLORSPACE::P3_PASSTHROUGH, DISPLAY_FORMAT::R10G10B10_A2_REV}, - {DISPLAY_COLORSPACE::P3_PASSTHROUGH, DISPLAY_FORMAT::RGBA_FP16}, - {DISPLAY_COLORSPACE::P3, DISPLAY_FORMAT::R8G8B8A8_REV}, - {DISPLAY_COLORSPACE::P3, DISPLAY_FORMAT::R10G10B10_A2_REV}, - {DISPLAY_COLORSPACE::P3, DISPLAY_FORMAT::RGBA_FP16}, - {DISPLAY_COLORSPACE::SRGB, DISPLAY_FORMAT::R8G8B8A8_REV}, -}; -static GL_WIDECOLOR_MODE_CFG glWideColorCfg[] = { - {EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, 8, 8, 8, 8}, - {EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, 10, 10, 10, 2}, - {EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, 16, 16, 16, 16}, - {EGL_GL_COLORSPACE_DISPLAY_P3_EXT, 8, 8, 8, 8}, - {EGL_GL_COLORSPACE_DISPLAY_P3_EXT, 10, 10, 10, 2}, - {EGL_GL_COLORSPACE_DISPLAY_P3_EXT, 16, 16, 16, 16}, - {EGL_GL_COLORSPACE_SRGB_KHR, 8, 8, 8, 8}, -}; - -static bool CheckRequiredEGLExt(EGLDisplay disp, - std::vector& exts) { - std::string eglExt(eglQueryString(disp, EGL_EXTENSIONS)); - for (auto& ext : exts) { - std::string::size_type extPos = eglExt.find(ext); - if (extPos == std::string::npos) { - return false; - } - } - return true; -} - -/* - * Initialize an EGL eglContext_ for the current display_. - * - * Supported Format: - * 8888: EGL_COLOR_COMPONENT_TYPE_EXT EGL_COLOR_COMPONENT_TYPE_FIXED_EXT - * 101010102:EGL_COLOR_COMPONENT_TYPE_EXT EGL_COLOR_COMPONENT_TYPE_FIXED_EXT - * 16161616: EGL_COLOR_COMPONENT_TYPE_EXT EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT - * - */ -bool ImageViewEngine::CreateWideColorCtx(WIDECOLOR_MODE mode) { - EGLBoolean status; - - std::vector attributes{ - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, - EGL_OPENGL_ES3_BIT, EGL_BLUE_SIZE, glWideColorCfg[mode].b_, - EGL_GREEN_SIZE, glWideColorCfg[mode].g_, EGL_RED_SIZE, - glWideColorCfg[mode].r_, EGL_ALPHA_SIZE, glWideColorCfg[mode].a_, - }; - - // for RGBA888, still set to EGL_COLOR_COMPONENT_TYPE_FIXED_EXT - if (mode == WIDECOLOR_MODE::P3_FP16) { - attributes.push_back(EGL_COLOR_COMPONENT_TYPE_EXT); - attributes.push_back(EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT); - } else { - attributes.push_back(EGL_COLOR_COMPONENT_TYPE_EXT); - attributes.push_back(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT); - } - attributes.push_back(EGL_NONE); - - // request just one matching config and use it - EGLint cfgCount = 1; - EGLConfig config; - status = eglChooseConfig(display_, attributes.data(), &config, cfgCount, - &cfgCount); - if (!status || cfgCount != 1) { - // if not support, report to caller so caller could choose another one - LOGI("==== Chosen Config type(%d) is not supported", mode); - return false; - } - - // Create GL3 Context - attributes.resize(0); - attributes.push_back(EGL_CONTEXT_CLIENT_VERSION); - attributes.push_back(3); - attributes.push_back(EGL_NONE); - eglContext_ = - eglCreateContext(display_, config, EGL_NO_CONTEXT, attributes.data()); - if (eglContext_ == EGL_NO_CONTEXT) { - return false; - } - - EGLint format; - eglGetConfigAttrib(display_, config, EGL_NATIVE_VISUAL_ID, &format); - int32_t res = ANativeWindow_setBuffersGeometry(app_->window, 0, 0, format); - if (res < 0) { - eglDestroyContext(display_, eglContext_); - eglContext_ = EGL_NO_CONTEXT; - return false; - } - - // Create Surface, which will turn on Display P3 wide gamut mode - attributes.resize(0); - attributes.push_back(EGL_GL_COLORSPACE_KHR); - attributes.push_back(glWideColorCfg[mode].space_); - attributes.push_back(EGL_NONE); - surface_ = - eglCreateWindowSurface(display_, config, app_->window, attributes.data()); - if (surface_ == EGL_NO_SURFACE) { - LOGI("====Surface for mode (%d) is not supported", mode); - eglDestroyContext(display_, eglContext_); - eglContext_ = EGL_NO_CONTEXT; - return false; - } - status = eglMakeCurrent(display_, surface_, surface_, eglContext_); - ASSERT(status, "eglMakeCurrent() Failed"); - - dispColorSpace_ = appWideColorCfg[mode].space_; - dispFormat_ = appWideColorCfg[mode].fmt_; - - eglQuerySurface(display_, surface_, EGL_WIDTH, &renderTargetWidth_); - eglQuerySurface(display_, surface_, EGL_HEIGHT, &renderTargetHeight_); - - return true; -} - -bool ImageViewEngine::CreateWideColorCtx(void) { - EGLint major, minor; - display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglInitialize(display_, &major, &minor); - - /* - * check for GL_EXT_gl_colorspace_display_p3_passthrough supportability: - * implemented from Android 10+. - * In this sample, the texture passing to GPU is already OETF applied. - * - * When p3_passthrough_ext is enabled: - * - OETF hardware is disabled when writing framebuffer - * - the texture content is OETF encoded - * - but sampler's EOTF should be disabled - * So sample sets texture to be RGBA ( to by pass sampler's EOTF hardware ) - * When p3_ext is enabled: - * - OETF hardware (when output from hardware blender) is enabled - * - the texture content is OETF encoded - * - sampler's EOTF should be enabled to avoid OETF twice - * So sample sets texture to be SRGB8_ALPHA8 to enable sampler's EOTF - */ - std::vector passthruExt{ - "EGL_KHR_gl_colorspace", "GL_EXT_gl_colorspace_display_p3_passthrough"}; - - /* - * Display-P3 needs EGL_EXT_gl_colorspace_display_p3 extension - * which needs EGL 1.4. If not available, Display P3 is not supported - * in that case, create legacy RGBA8888 eglContext_. - */ - std::vector p3Exts{"EGL_KHR_gl_colorspace", - "EGL_EXT_gl_colorspace_display_p3"}; - - // Default is P3 wide color gamut modes - WIDECOLOR_MODE modes[] = { - P3_R8G8B8A8_REV, - P3_R10G10B10A2_REV, - P3_FP16, - SRGBA_R8G8B8A8_REV, - }; - - if (CheckRequiredEGLExt(display_, passthruExt)) { - modes[0] = P3_PASSTHROUGH_R8G8B8A8_REV; - modes[1] = P3_PASSTHROUGH_R10G10B10A2_REV; - modes[2] = P3_PASSTHROUGH_FP16; - } else if (!CheckRequiredEGLExt(display_, p3Exts)) { - LOGW( - "====Warning: Display P3 is not supported," - "creating legacy mode GL Context"); - return CreateWideColorCtx(SRGBA_R8G8B8A8_REV); - } - - // create the wide color gamut context - for (auto mode : modes) { - if (CreateWideColorCtx(mode)) return true; - } - return false; -} - -void ImageViewEngine::DestroyWideColorCtx() { - if (display_ == EGL_NO_DISPLAY) { - return; - } - - eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - if (eglContext_ != EGL_NO_CONTEXT) { - eglDestroyContext(display_, eglContext_); - } - if (surface_ != EGL_NO_SURFACE) { - eglDestroySurface(display_, surface_); - } - eglTerminate(display_); - - display_ = EGL_NO_DISPLAY; - eglContext_ = EGL_NO_CONTEXT; - surface_ = EGL_NO_SURFACE; - dispColorSpace_ = DISPLAY_COLORSPACE::INVALID; - dispFormat_ = DISPLAY_FORMAT::INVALID_FORMAT; -} diff --git a/display-p3/image-view/src/main/cpp/android_debug.h b/display-p3/image-view/src/main/cpp/android_debug.h deleted file mode 100644 index 8114d5c0a..000000000 --- a/display-p3/image-view/src/main/cpp/android_debug.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef __SAMPLE_ANDROID_DEBUG_H__ -#define __SAMPLE_ANDROID_DEBUG_H__ -#include - -#if 1 -#ifndef MODULE_NAME -#define MODULE_NAME "OpenGL-Wide-Color" -#endif - -#define LOGV(...) \ - __android_log_print(ANDROID_LOG_VERBOSE, MODULE_NAME, __VA_ARGS__) -#define LOGD(...) \ - __android_log_print(ANDROID_LOG_DEBUG, MODULE_NAME, __VA_ARGS__) -#define LOGI(...) \ - __android_log_print(ANDROID_LOG_INFO, MODULE_NAME, __VA_ARGS__) -#define LOGW(...) \ - __android_log_print(ANDROID_LOG_WARN, MODULE_NAME, __VA_ARGS__) -#define LOGE(...) \ - __android_log_print(ANDROID_LOG_ERROR, MODULE_NAME, __VA_ARGS__) -#define LOGF(...) \ - __android_log_print(ANDROID_LOG_FATAL, MODULE_NAME, __VA_ARGS__) - -#define ASSERT(cond, ...) \ - if (!(cond)) { \ - __android_log_assert(#cond, MODULE_NAME, __VA_ARGS__); \ - } -#else - -#define LOGV(...) -#define LOGD(...) -#define LOGI(...) -#define LOGW(...) -#define LOGE(...) -#define LOGF(...) -#define ASSERT(cond, ...) - -#endif - -#endif // __SAMPLE_ANDROID_DEBUG_H__ diff --git a/display-p3/image-view/src/main/cpp/common.h b/display-p3/image-view/src/main/cpp/common.h deleted file mode 100644 index 6502e9054..000000000 --- a/display-p3/image-view/src/main/cpp/common.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#include -#include -#include -#include - -/* - * App Context Format - */ -enum DISPLAY_COLORSPACE { - P3_PASSTHROUGH, - P3, - SRGB, - COUNT, - INVALID = COUNT, -}; - -enum DISPLAY_FORMAT { - R10G10B10_A2_REV, - R8G8B8A8_REV, - RGBA_FP16, - FORMAT_COUNT, - INVALID_FORMAT = FORMAT_COUNT -}; - -// Rendering Mode BitMask -#define RENDERING_P3 0x01 -#define RENDERING_SRGB 0x02 - -#define DEFAULT_DISPLAY_GAMMA (1.0f / 2.2f) -#define DEFAULT_P3_IMAGE_GAMMA (1.0f / 2.2f) - -// EGL Bits -#ifndef EGL_OPENGL_ES3_BITS -#define EGL_OPENGL_ES3_BIT 0x00000040 -#endif -#ifndef EGL_GL_COLORSPACE_DISPLAY_P3_EXT -#define EGL_GL_COLORSPACE_DISPLAY_P3_EXT 0x3363 -#endif - -#endif // __COMMON_H__ diff --git a/display-p3/image-view/src/main/cpp/gldebug.cpp b/display-p3/image-view/src/main/cpp/gldebug.cpp deleted file mode 100644 index f797bcbd4..000000000 --- a/display-p3/image-view/src/main/cpp/gldebug.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "gldebug.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include "android_debug.h" - -/* - * eglConfig ( swapchain ) capability - */ -void PrintEglConfig(void) { - EGLint numConfigs; - EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - - eglInitialize(display, 0, 0); - eglGetConfigs(display, nullptr, 0, &numConfigs); - std::vector supportedConfigs(numConfigs); - eglGetConfigs(display, supportedConfigs.data(), numConfigs, &numConfigs); - assert(numConfigs); - for (auto cfg : supportedConfigs) { - PrintEglConfig(display, cfg); - } -} - -#define UKNOWN_TAG "UNKNOW_TAG" -#define MAKE_PAIR(val) std::make_pair(val, #val) -template -const char* GetPairStr(T key, std::vector>& store) { - typedef typename std::vector>::iterator iterator; - for (iterator it = store.begin(); it != store.end(); ++it) { - if (it->first == key) { - return it->second; - } - } - LOGW("(%#08x) : UNKNOWN_TAG for %s", key, typeid(store[0].first).name()); - return UKNOWN_TAG; -} - -using UINT32_PAIR = std::pair; -std::vector eglSurfaceTypeInfo{ - MAKE_PAIR(EGL_PBUFFER_BIT), - MAKE_PAIR(EGL_PIXMAP_BIT), - MAKE_PAIR(EGL_WINDOW_BIT), - MAKE_PAIR(EGL_VG_COLORSPACE_LINEAR_BIT), - MAKE_PAIR(EGL_VG_ALPHA_FORMAT_PRE_BIT), - MAKE_PAIR(EGL_MULTISAMPLE_RESOLVE_BOX_BIT), - MAKE_PAIR(EGL_SWAP_BEHAVIOR_PRESERVED_BIT)}; -const char* GetEGLSurfaceTypeStr(uint32_t mask) { - return GetPairStr(mask, eglSurfaceTypeInfo); -} - -void PrintEglConfig(EGLDisplay display, EGLConfig cfg) { - EGLint r, g, b, d, a, s; - eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r); - eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g); - eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b); - eglGetConfigAttrib(display, cfg, EGL_ALPHA_SIZE, &a); - eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d); - eglGetConfigAttrib(display, cfg, EGL_SURFACE_TYPE, &s); - LOGI("(%d, %d, %d, %d) and (%d) (%08x)", r, g, b, a, d, s); - for (auto& pair : eglSurfaceTypeInfo) { - if (pair.first & s) { - LOGI("SURFACE_TYPE: %s", GetEGLSurfaceTypeStr(pair.first)); - } - } -} - -/* - * OpenGL Implementation Info - */ -std::vector OpenGLInfo{ - MAKE_PAIR(GL_VENDOR), MAKE_PAIR(GL_RENDERER), - MAKE_PAIR(GL_VERSION), MAKE_PAIR(GL_SHADING_LANGUAGE_VERSION), - MAKE_PAIR(GL_EXTENSIONS), -}; -void PrintGLInfo(void) { - for (auto name : OpenGLInfo) { - LOGI("OpenGL %s: %s", name.second, glGetString(name.first)); - } -} - -static std::vector EGLInfo{ - MAKE_PAIR(EGL_CLIENT_APIS), - MAKE_PAIR(EGL_VENDOR), - MAKE_PAIR(EGL_VERSION), - MAKE_PAIR(EGL_EXTENSIONS), -}; -void PrintEGLInfo(EGLDisplay disp) { - for (auto name : EGLInfo) { - LOGI("OpenGL %s: %s", name.second, eglQueryString(disp, name.first)); - } -} - -std::vector glErrorInfo{ - MAKE_PAIR(GL_NO_ERROR), MAKE_PAIR(GL_INVALID_ENUM), - MAKE_PAIR(GL_INVALID_VALUE), MAKE_PAIR(GL_INVALID_OPERATION), - MAKE_PAIR(GL_OUT_OF_MEMORY), -}; -const char* GetGLErrorStr(uint32_t errorCode) { - return GetPairStr(errorCode, glErrorInfo); -} - -/* - * Matrix helping functions - */ -void PrintMatrix(mathfu::mat3& matrix) { - char buf[64] = { - 0, - }; - int index; - for (int r = 0; r < matrix.kRows; r++) { - index = 0; - index += snprintf(&buf[index], 64 - index, "Matrix: "); - for (int c = 0; c < matrix.kColumns; c++) - index += snprintf(&buf[index], 64 - index, "%f ", matrix(r, c)); - - LOGI("%s", buf); - } -} diff --git a/display-p3/image-view/src/main/cpp/gldebug.h b/display-p3/image-view/src/main/cpp/gldebug.h deleted file mode 100644 index 420c228f2..000000000 --- a/display-p3/image-view/src/main/cpp/gldebug.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __ANDROID_GL_DEBUG_H__ -#define __ANDROID_GL_DEBUG_H__ - -#include -#include -#include - -#include "android_debug.h" -#include "mathfu/glsl_mappings.h" -void PrintEGLInfo(EGLDisplay disp); -void PrintEglConfig(void); -void PrintEglConfig(EGLDisplay display, EGLConfig cfg); -const char* GetGLErrorStr(uint32_t errorCode); -void PrintGLInfo(void); - -inline void CheckGlError(const char* op) { - for (GLint error = glGetError(); error; error = glGetError()) { - LOGI("===== after %s() glError (%#x): %s\n", op, error, - GetGLErrorStr(error)); - } -} - -void PrintMatrix(mathfu::mat3& matrix); - -#endif // ANDROID_GL_DEBUG diff --git a/display-p3/image-view/src/main/cpp/simple_png.cpp b/display-p3/image-view/src/main/cpp/simple_png.cpp deleted file mode 100644 index e4ef0ce65..000000000 --- a/display-p3/image-view/src/main/cpp/simple_png.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "simple_png.h" - -#include - -#include "common.h" - -union littleEndianUint32 { - uint8_t bytes[4]; - uint32_t value; -}; -// value, store, offset -#define READ_INT_SWAP(v, s, o) \ - do { \ - v.bytes[3] = s[o + 0]; \ - v.bytes[2] = s[o + 1]; \ - v.bytes[1] = s[o + 2]; \ - v.bytes[0] = s[o + 3]; \ - } while (0) - -// Little endian chunk name -#define PNG_CHUNCK(c1, c2, c3, c4) \ - (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4)) - -/* - * Parse PNG file header, refer to: - * https://www.w3.org/TR/PNG/#11Chunks - */ -PNGHeader::PNGHeader(std::string& name, uint8_t* buf, uint64_t len) - : name_(name), - buf_(buf), - length_(len), - offset_(0), - hasChrm_(false), - valid_(false) { - ASSERT(buf_, "PNG header is not initialized"); - NPM_ = mathfu::mat3::Identity(); - - // always have a gamma, either from PNG file or our default value - gamma_ = DEFAULT_IMAGE_GAMMA; - uint8_t sig[] = {137, 80, 78, 71, 13, 10, 26, 10}; - - if (memcmp(buf_, sig, sizeof(sig))) { - LOGE("==== PNG file %s corrupted", name_.c_str()); - return; - } - offset_ += static_cast(sizeof(sig)); - - bool has_sRGB = false; - bool has_iCCP = false; - LOGV("=== Parsing File: %s", name_.c_str()); - while (offset_ < length_) { - littleEndianUint32 len, type; - - /* - * Read the len word ( 4 bytes ), it is only for data field - no self, not - * for type not for CRC - */ - READ_INT_SWAP(len, buf_, offset_); - offset_ += 4; - - READ_INT_SWAP(type, buf_, offset_); - offset_ += 4; - - switch (type.value) { - case PNG_CHUNCK('I', 'H', 'D', 'R'): { - uint32_t idx = 0; - littleEndianUint32 val; - READ_INT_SWAP(val, buf_, (offset_ + idx)); - width_ = val.value, idx += 4; - READ_INT_SWAP(val, buf_, (offset_ + idx)); - height_ = val.value, idx += 4; - - bpp_ = static_cast(buf_[offset_ + idx++]); - colorType_ = static_cast(buf_[offset_ + idx++]); - compressType_ = static_cast(buf_[offset_ + idx++]); - filterType_ = static_cast(buf_[offset_ + idx++]); - interlaceType_ = static_cast(buf_[offset_ + idx++]); - - offset_ += sizeof(uint32_t) + len.value; // passing CRC 4 bytes too - break; - } - case PNG_CHUNCK('g', 'A', 'M', 'A'): { - littleEndianUint32 encodedGamma; - READ_INT_SWAP(encodedGamma, buf_, offset_); - gamma_ = encodedGamma.value / PNG_INTEGER_ENCODING_FACTOR; - offset_ += sizeof(uint32_t) + len.value; - break; - } - case PNG_CHUNCK('c', 'H', 'R', 'M'): { - littleEndianUint32 val; - ASSERT(len.value == (2 * 4 * 4), "cHRM Chunk length is not 16(%d)", - len.value); - for (int idx = 0; idx < 4; idx++) { - READ_INT_SWAP(val, buf_, (offset_ + idx * 8)); - chrm_[idx].x = val.value / PNG_INTEGER_ENCODING_FACTOR; - READ_INT_SWAP(val, buf_, (offset_ + idx * 8 + 4)); - chrm_[idx].y = val.value / PNG_INTEGER_ENCODING_FACTOR; - } - hasChrm_ = true; - offset_ += sizeof(uint32_t) + len.value; - break; - } - case PNG_CHUNCK('s', 'R', 'G', 'B'): { - has_sRGB = true; - ASSERT(len.value == 1, "sRGB length error"); - offset_ += sizeof(uint32_t) + len.value; - break; - } - case PNG_CHUNCK('i', 'C', 'C', 'P'): - LOGI("====iCCP: %s, compression Method %d", &buf_[offset_], - buf_[offset_ + - strlen(reinterpret_cast(&buf_[offset_])) + 1]); - has_iCCP = true; - offset_ += sizeof(uint32_t) + len.value; - break; - default: - LOGV("====Unprocessed CHUNK %c%c%c%c", type.bytes[3], type.bytes[2], - type.bytes[1], type.bytes[0]); - [[fallthrough]]; - case PNG_CHUNCK('I', 'D', 'A', 'T'): - [[fallthrough]]; - case PNG_CHUNCK('i', 'T', 'X', 't'): - [[fallthrough]]; - case PNG_CHUNCK('t', 'T', 'X', 't'): - [[fallthrough]]; - case PNG_CHUNCK('z', 'T', 'X', 't'): - [[fallthrough]]; - case PNG_CHUNCK('t', 'I', 'M', 'E'): - [[fallthrough]]; - case PNG_CHUNCK('I', 'E', 'N', 'D'): - offset_ += sizeof(uint32_t) + len.value; // CRC + data_size - break; - } - } - - if (has_sRGB) { - CIE_POINT defaultsRGBValues[] = { - {.31270f, .32900f}, - {.640000f, .33f}, - {.3f, .6f}, - {.15f, .06f}, - }; - memcpy(chrm_, defaultsRGBValues, sizeof(defaultsRGBValues)); - gamma_ = .45455f; - hasChrm_ = true; - } - - if (hasChrm_) { - UpdateNPM(); - } - - /* - * shortcut: if SRGB / iCCP present, assume to be P3 iamge - */ - if (has_sRGB || has_iCCP) { - hasChrm_ = false; // When no cHRM present, assume to be P3 colorspace - } - valid_ = true; -} - -float PNGHeader::GetGamma() const { return gamma_; } - -/* - * Is the picture coded in display_ P3 space? - * Taking agressive path: - * 1) if has cHRM chunk - * 2) values are closer to sRGB than to P3 reference points - * Otherwise, all assumed to be P3 space - */ -#define UNSIGNED_DELTA(x, y) ((x) > (y) ? (x) - (y) : (y) - (x)) -bool PNGHeader::IsP3Image(void) const { - if (!hasChrm_) { - return true; - } - CIE_POINT p3[] = { - {.31270f, .32900f}, // white - {.68000f, .32000f}, // red - {.26500f, .69000f}, // green - {.15000f, .06000f}, // blue - }; - - CIE_POINT srgb[] = { - {.31270f, .3290f}, - {.64000f, .3300f}, - {.30000f, .6000f}, - {.15000f, .0600f}, - }; - // calculate distance to P3 reference points and sRGB ref points - float toP3 = 0.0f, toSRGB = 0.0f; - for (int32_t idx = 1; idx < 4; idx++) { - toP3 += (chrm_[idx].x - p3[idx].x) * (chrm_[idx].x - p3[idx].x); - toP3 += (chrm_[idx].y - p3[idx].y) * (chrm_[idx].y - p3[idx].y); - - toSRGB += (chrm_[idx].x - srgb[idx].x) * (chrm_[idx].x - srgb[idx].x); - toSRGB += (chrm_[idx].y - srgb[idx].y) * (chrm_[idx].y - srgb[idx].y); - } - - if (toSRGB > toP3) { - return true; - } - return false; -} - -/* - * Calculate NPM, refer to SMPTE RP-177-1993 - */ -void PNGHeader::UpdateNPM(void) { - if (!hasChrm_) return; - - mathfu::mat3 npm(chrm_[1].x, chrm_[1].y, 1.0f - chrm_[1].x - chrm_[1].y, - chrm_[2].x, chrm_[2].y, 1.0f - chrm_[2].x - chrm_[2].y, - chrm_[3].x, chrm_[3].y, 1.0f - chrm_[3].x - chrm_[3].y); - mathfu::vec3 w(chrm_[0].x / chrm_[0].y, 1.0f, - (1.0f - chrm_[0].x - chrm_[0].y) / chrm_[0].y); - - mathfu::vec3 c = npm.Inverse() * w; - mathfu::mat3 diagMat = mathfu::mat3::Identity(); - diagMat(0, 0) = c[0], diagMat(1, 1) = c[1], diagMat(2, 2) = c[2]; - - NPM_ = npm * diagMat; -} - -bool PNGHeader::HasNPM(void) const { return hasChrm_; } - -const mathfu::mat3* PNGHeader::NPM(void) { - ASSERT(hasChrm_, "File does not have NPM info"); - return &NPM_; -} diff --git a/display-p3/image-view/src/main/cpp/simple_png.h b/display-p3/image-view/src/main/cpp/simple_png.h deleted file mode 100644 index dbeaf3b76..000000000 --- a/display-p3/image-view/src/main/cpp/simple_png.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef __SIMPLE_PNG_H__ -#define __SIMPLE_PNG_H__ - -#include - -#include -#include - -#include "android_debug.h" - -#pragma pack(push, 1) - -struct CIE_POINT { - float x, y; -}; - -#define REF_WHITE_IDX 0 -#define REF_RED_IDX 1 -#define REF_GREEN_IDX 2 -#define REF_BLUE_IDX 3 - -#define PNG_INTEGER_ENCODING_FACTOR 100000.0f -/* - * Default Gamma if image file does not have Gamma - */ -#define DEFAULT_IMAGE_GAMMA (1.0f / 2.2f) - -class PNGHeader { - public: - explicit PNGHeader(std::string& name, uint8_t* buf, uint64_t len); - ~PNGHeader() { buf_ = nullptr, offset_ = 0; } - - float GetGamma(void) const; - bool IsP3Image(void) const; - bool HasNPM(void) const; - const mathfu::mat3* NPM(void); - - private: - void UpdateNPM(void); - - std::string name_; - uint8_t* buf_; - uint64_t length_; - uint64_t offset_; - float gamma_; - - // header info: - uint32_t width_, height_, bpp_, colorType_; - uint32_t compressType_, filterType_, interlaceType_; - CIE_POINT chrm_[4]; - bool hasChrm_; - mathfu::mat3 NPM_; - bool valid_; -}; - -#pragma pack(pop) - -#endif // __SIMPLE_PNG_H__ diff --git a/display-p3/image-view/src/main/java/com/example/widecolor/WideColorActivity.java b/display-p3/image-view/src/main/java/com/example/widecolor/WideColorActivity.java deleted file mode 100644 index fd70ac0f2..000000000 --- a/display-p3/image-view/src/main/java/com/example/widecolor/WideColorActivity.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.widecolor; - -import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.app.NativeActivity; -import android.content.Context; -import android.os.Bundle; -import android.os.Handler; -import android.view.Display; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.Surface; -import android.view.View; -import android.view.ViewGroup.MarginLayoutParams; -import android.view.WindowManager; -import android.view.WindowManager.LayoutParams; -import android.widget.LinearLayout; -import android.widget.PopupWindow; -import android.widget.TextView; - -public class WideColorActivity extends NativeActivity { - final int ONE_SECOND = 1000; - final int DISPLAY_FOREVER = -1; - - final int LEGEND_P3_IMAGE_BIT = 0x01; - final int LEGEND_SRGB_IMAGE_BIT = 0x02; - final int LEGEND_FILENAME_BIT = 0x04; - final int LEGEND_DISPLAY_ALL = LEGEND_P3_IMAGE_BIT | LEGEND_SRGB_IMAGE_BIT | - LEGEND_FILENAME_BIT; - - View _popupView; - TextView _p3Image, _sRGBImage, _fileName; - LinearLayout _mainLayout; - volatile PopupWindow _popupWindow; - volatile boolean _dismissPending; - Handler _handler; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - //Hide toolbar - setImmersiveSticky(); - View decorView = getWindow().getDecorView(); - decorView.setOnSystemUiVisibilityChangeListener - (new View.OnSystemUiVisibilityChangeListener() { - @Override - public void onSystemUiVisibilityChange(int visibility) { - setImmersiveSticky(); - } - }); - - LayoutInflater layoutInflater - = (LayoutInflater)getBaseContext() - .getSystemService(LAYOUT_INFLATER_SERVICE); - _popupView = layoutInflater.inflate(R.layout.widgets, null); - _p3Image = (TextView)_popupView.findViewById(R.id.textViewP3); - _sRGBImage = (TextView)_popupView.findViewById(R.id.textViewSRGB); - _fileName = (TextView)_popupView.findViewById(R.id.textViewWelcome); - - _mainLayout = new LinearLayout(this); - MarginLayoutParams params = new MarginLayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); - params.setMargins(0, 0, 0, 0); - setContentView(_mainLayout, params); - _popupWindow = null; - - _handler = new Handler(); - _dismissPending = false; - } - - @TargetApi(26) - protected void onResume() { - super.onResume(); - setImmersiveSticky(); - } - - protected void onPause() - { - super.onPause(); - } - - // Our popup window, you will call it from your C/C++ code later - @TargetApi(26) - void setImmersiveSticky() { - View decorView = getWindow().getDecorView(); - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); - } - - /** - * Enable/Disable popupWindow. The popupWindow would display for - * ONE_SECOND, then dismissed; if swiping is faster than ONE_SECOND - * the latest one is displayed, but with less time. - * @param mask is a bitmask of 3 TextViews ( P3, sRGB, and fileName) - * @param file is the file name to be displayed - * @param duration is time to display 3 TextViews in milisecond. - */ - void DisplayLegend(final int mask, final String file, int duration) { - if (_dismissPending) { - if (file != null) { - _fileName.setText(file); - } - return; - } - if (_popupWindow == null) { - _popupWindow = new PopupWindow( - _popupView, - LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); - // Show our UI over NativeActivity window - _popupWindow.showAtLocation(_mainLayout, Gravity.BOTTOM | Gravity.START, 0, 0); - _popupWindow.update(); - } - - _p3Image.setVisibility(((mask & LEGEND_P3_IMAGE_BIT) != 0) ? View.VISIBLE : View.INVISIBLE); - _sRGBImage.setVisibility(((mask & LEGEND_SRGB_IMAGE_BIT) != 0) ? View.VISIBLE : View.INVISIBLE); - if (file != null) { - _fileName.setText(file); - } - _fileName.setVisibility(((mask & LEGEND_FILENAME_BIT) != 0)? View.VISIBLE: View.INVISIBLE); - - if (duration != DISPLAY_FOREVER) { - _handler.postDelayed(new Runnable() { - final PopupWindow popupWindow = _popupWindow; - @Override - public void run() { - popupWindow.dismiss(); - _dismissPending = false; - } - }, duration); - _popupWindow = null; - _dismissPending = true; - } - } - @SuppressLint("InflateParams") - public void EnableUI(final int mask) - { - if( _popupWindow != null ) - return; - - this.runOnUiThread(new Runnable() { - @Override - public void run() { - // Show our UI over NativeActivity window - DisplayLegend(LEGEND_FILENAME_BIT, null, DISPLAY_FOREVER); - }}); - } - - public void EnableRenderUI(final String file) { - this.runOnUiThread(new Runnable() { - @Override - public void run() { - DisplayLegend(LEGEND_DISPLAY_ALL, file, DISPLAY_FOREVER); - }}); - } - - public void UpdateUI(final int mask, final String file) - { - boolean displaying = (mask & 0x07) != 0; - if ((mask & LEGEND_DISPLAY_ALL) == 0) { - return; - } - - this.runOnUiThread(new Runnable() { - @Override - public void run() { - int newMask = mask; - if (file != null) { - newMask |= LEGEND_FILENAME_BIT; - } - DisplayLegend(newMask, file, ONE_SECOND); - }}); - } - - public int GetRotation() { - int rotation = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) - .getDefaultDisplay() - .getRotation(); - int angle = 0; - switch (rotation) { - case (Surface.ROTATION_90) : - angle = 90; - break; - case (Surface.ROTATION_180) : - angle = 180; - break; - case (Surface.ROTATION_270): - angle = 270; - break; - case (Surface.ROTATION_0) : - default: - angle = 0; - break; - } - return angle; - } -} - - diff --git a/display-p3/image-view/src/main/res/layout/widgets.xml b/display-p3/image-view/src/main/res/layout/widgets.xml deleted file mode 100644 index 748ca8163..000000000 --- a/display-p3/image-view/src/main/res/layout/widgets.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - diff --git a/display-p3/image-view/src/main/res/mipmap-hdpi/ic_launcher.png b/display-p3/image-view/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index a35fe2803..000000000 Binary files a/display-p3/image-view/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/display-p3/image-view/src/main/res/mipmap-mdpi/ic_launcher.png b/display-p3/image-view/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index 4dc47d1ee..000000000 Binary files a/display-p3/image-view/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/display-p3/image-view/src/main/res/mipmap-xhdpi/ic_launcher.png b/display-p3/image-view/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index 4659a5106..000000000 Binary files a/display-p3/image-view/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/display-p3/image-view/src/main/res/mipmap-xxhdpi/ic_launcher.png b/display-p3/image-view/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 4cd2842a7..000000000 Binary files a/display-p3/image-view/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/display-p3/image-view/src/main/res/values/strings.xml b/display-p3/image-view/src/main/res/values/strings.xml deleted file mode 100644 index 742a58e2a..000000000 --- a/display-p3/image-view/src/main/res/values/strings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - WideColor - P3 View - sRGB View - Loading Images ... - diff --git a/display-p3/screenshot.png b/display-p3/screenshot.png deleted file mode 100644 index bd16d2f98..000000000 Binary files a/display-p3/screenshot.png and /dev/null differ diff --git a/settings.gradle b/settings.gradle index 1fd4e5cd2..4fe2ea4f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,7 +25,6 @@ include(":audio-echo:app") include(":bitmap-plasma:app") include(":camera:basic") include(":camera:texture-view") -include(":display-p3:image-view") include(":endless-tunnel:app") include(":exceptions:app") include(":gles3jni:app")