| /* | |
| * Copyright (C) 2025 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 LOG_TAG "OoprClient OOPR" | |
| #include <android/ipcrenderbuffer/OoprClient.h> | |
| #include <com_android_graphics_libgui_flags.h> | |
| #include <gui/ISurfaceComposer.h> | |
| #include <gui/TraceUtils.h> | |
| #include <inttypes.h> | |
| #include <log/log.h> | |
| #include <private/gui/ComposerService.h> | |
| namespace android { | |
| bool OoprClient::sEnableOOPR = false; | |
| OoprClient* OoprClient::getInstance() { | |
| if (!sEnableOOPR) { | |
| return nullptr; | |
| } | |
| static OoprClient sInstance; | |
| return &sInstance; | |
| } | |
| OoprClient::OoprClient() { | |
| setRenderResourceToken(sp<BBinder>::make()); | |
| } | |
| OoprClient::~OoprClient() = default; | |
| void OoprClient::enableOutOfProcessRendering() { | |
| if (com_android_graphics_libgui_flags_out_of_process_rendering()) { | |
| sEnableOOPR = true; | |
| ALOGI("Enabled OOPR"); | |
| } else { | |
| LOG_ALWAYS_FATAL("Flag com.android.graphics.libgui.flags.out_of_process_rendering " | |
| "is disabled!"); | |
| } | |
| } | |
| sp<IBinder> OoprClient::getDefaultRenderResourceToken() { | |
| return getRenderResourceToken(); | |
| } | |
| bool OoprClient::isEnabled() const { | |
| return sEnableOOPR; | |
| } | |
| void OoprClient::createBitmap(uint64_t bitmapId) { | |
| OoprClientCache::createBitmap(OoprBitmapHandle{bitmapId}); | |
| } | |
| void OoprClient::destroyBitmap(uint64_t bitmapId) { | |
| OoprClientCache::destroyBitmap(OoprBitmapHandle{bitmapId}); | |
| } | |
| void OoprClient::registerHardwareBitmap(uint64_t bitmapId, const sk_sp<SkImage>& image, | |
| const sp<GraphicBuffer>& buffer) { | |
| OoprBitmapHandle handle{bitmapId}; | |
| setBitmapGraphicBuffer(handle, buffer); | |
| bindSkImage(image, handle); | |
| } | |
| sk_sp<SkImage> OoprClient::registerHeapBitmap(uint64_t bitmapId, const SkBitmap& skBitmap) { | |
| sk_sp<SkImage> image = SkImages::RasterFromBitmapNoCopy(skBitmap); | |
| OoprBitmapHandle handle{bitmapId}; | |
| setBitmapHeapBitmap(handle, skBitmap); | |
| bindSkImage(image, handle); | |
| return image; | |
| } | |
| void OoprClient::createNode(uint64_t nodeId) { | |
| OoprClientCache::createNode(OoprNodeHandle{nodeId}); | |
| } | |
| void OoprClient::destroyNode(uint64_t nodeId) { | |
| OoprClientCache::destroyNode(OoprNodeHandle{nodeId}); | |
| } | |
| void OoprClient::bindNodeSurface(uint64_t nodeId, SkSurface* layerSurface) { | |
| bindSkImage(layerSurface->makeImageSnapshot(), OoprNodeHandle{nodeId}); | |
| } | |
| OoprFilterResult OoprClient::setNodeFilter(uint64_t nodeId, SkSurface* layerSurface, | |
| const SkImageFilter* filter, | |
| const SkIRect& subset, | |
| const SkIRect& clipBounds) { | |
| SkPaint paint; | |
| paint.setImageFilter(sk_ref_sp(filter)); | |
| SkIRect outBounds = filter->filterBounds(subset, SkMatrix::I(), | |
| SkImageFilter::kForward_MapDirection, &clipBounds); | |
| SkIPoint calculatedOffset = SkIPoint::Make(outBounds.x(), outBounds.y()); | |
| OoprNodeHandle handle{nodeId}; | |
| setNodeSurfaceFilter(handle, subset, clipBounds, paint); | |
| return OoprFilterResult{ | |
| .snapshot = layerSurface->makeImageSnapshot(), | |
| .outSubset = SkIRect::MakeWH(outBounds.width(), outBounds.height()), | |
| .outOffset = calculatedOffset, | |
| }; | |
| } | |
| } // namespace android |