| /* | |
| * Copyright (C) 2024 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 "RenderBufferOps OOPR" | |
| #pragma clang diagnostic push | |
| #pragma clang diagnostic ignored "-Wunused-parameter" | |
| #define ATRACE_TAG ATRACE_TAG_GRAPHICS | |
| #include <SkColorFilter.h> | |
| #include <SkPixelRef.h> | |
| #include <SkSurface.h> | |
| #include <gui/TraceUtils.h> | |
| #include <include/core/SkPath.h> | |
| #include <include/core/SkPathBuilder.h> | |
| #include <include/gpu/graphite/Image.h> | |
| #include <include/gpu/graphite/Recorder.h> | |
| #include <include/pathops/SkPathOps.h> | |
| #include <src/image/SkSurface_Raster.h> | |
| #include "SkFontScanner_FreeType.h" | |
| #include "src/core/SkCanvasPriv.h" | |
| #include "src/core/SkReadBuffer.h" | |
| // #include "src/core/SkVerticesPriv.h" | |
| #include "src/core/SkWriteBuffer.h" | |
| #include <android/ipcrenderbuffer/RenderBufferOps.h> | |
| #define IPCRENDERBUFFER_UNIMPLEMENTED_IS_FATAL 0 | |
| #ifdef IPCRENDERRBUFFER_UNIMPLEMENTED_IS_FATAL | |
| #define IPCRENDERBUFFER_UNIMPLEMENTED \ | |
| LOG_ALWAYS_FATAL("Not implemented %s at %s:%d", __PRETTY_FUNCTION__, __FILE__, __LINE__) | |
| #else | |
| #define IPCRENDERBUFFER_UNIMPLEMENTED \ | |
| ALOGE("Not implemented %s at %s:%d", __PRETTY_FUNCTION__, __FILE__, __LINE__) | |
| #endif | |
| // #define TRACE_IPC_CANVAS 1 | |
| #define OOPR_TRACE_CALL() ATRACE_FORMAT("OOPR_%s", __func__) | |
| #ifndef TRACE_IPC_CANVAS | |
| #define IPC_CANVAS_TRACE_CALL (void)0 | |
| #else | |
| #define IPC_CANVAS_TRACE_CALL OOPR_TRACE_CALL() | |
| #endif | |
| namespace android { | |
| constexpr bool DUMP_OPS = false; | |
| std::string to_string(OoprNodeHandle handle) { | |
| return "Node(" + std::to_string(handle.id) + ")"; | |
| } | |
| std::string to_string(OoprBitmapHandle handle) { | |
| return "Bitmap(" + std::to_string(handle.id) + ")"; | |
| } | |
| std::string to_string(OoprImageRef ref) { | |
| if (ref.kind == OoprImageRefKind::NodeImage) { | |
| return to_string(ref.nodeImage); | |
| } else { | |
| return to_string(ref.bitmap); | |
| } | |
| } | |
| OoprNodeProxy* findProxy(OoprClientCache* cache, OoprNodeHandle handle) { | |
| auto it = cache->nodes.find(handle); | |
| if (it == cache->nodes.end()) { | |
| ALOGE("failed: handle %s not found in client cache", to_string(handle).c_str()); | |
| return nullptr; | |
| } | |
| return &it->second; | |
| } | |
| sk_sp<SkSurface> OoprClientCache::setNodeSurface(OoprNodeHandle handle, int32_t width, | |
| int32_t height) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lock(mLock); | |
| OoprNodeProxy* node = findProxy(this, handle); | |
| if (!node) return nullptr; | |
| if (node->mSurface && node->mSurface->width() == width && | |
| node->mSurface->height() == height) { | |
| return node->mSurface; | |
| } | |
| static uint32_t sDummyBuffer[1]; | |
| SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | |
| // We use a dummy PixelRef wrapping a tiny buffer to avoid physical memory allocation. | |
| // By setting the PixelRef to immutable and using the SkSurface_Raster constructor | |
| // that takes a PixelRef, we signal to Skia that the surface "owns" the pixels. | |
| // This allows makeImageSnapshot() to share the PixelRef instead of performing a | |
| // deep copy, which avoids the SIGSEGV that would occur if it tried to copy the | |
| // full dimensions from our tiny buffer. | |
| auto pr = sk_make_sp<SkPixelRef>(width, height, sDummyBuffer, info.minRowBytes()); | |
| pr->setImmutable(); | |
| node->mSurface = sk_make_sp<SkSurface_Raster>(info, std::move(pr), nullptr); | |
| node->flags |= OoprNodeProxy::eSurfaceDirty; | |
| return node->mSurface; | |
| } | |
| void OoprClientCache::setNodeSurfaceFilter(OoprNodeHandle handle, const SkIRect& subset, | |
| const SkIRect& clipBounds, const SkPaint& paint) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lock(mLock); | |
| OoprNodeProxy* node = findProxy(this, handle); | |
| if (!node) return; | |
| node->subset = subset; | |
| node->clipBounds = clipBounds; | |
| node->paint = paint; | |
| node->flags |= OoprNodeProxy::eSurfaceFilterDirty; | |
| } | |
| void OoprClientCache::createNode(OoprNodeHandle handle) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lock(mLock); | |
| nodes[handle] = { | |
| .flags = OoprNodeProxy::eShouldCreate, | |
| }; | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("Creating node proxy, handle=%s", to_string(handle).c_str()); | |
| } | |
| } | |
| void OoprClientCache::createBitmap(OoprBitmapHandle bitmap) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lg(mLock); | |
| OoprBitmapProxy& bmpProxy = bitmaps[bitmap]; | |
| bmpProxy.flags |= OoprBitmapProxy::eShouldCreate; | |
| } | |
| void OoprClientCache::destroyBitmap(OoprBitmapHandle bitmap) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lg(mLock); | |
| OoprBitmapProxy& bmpProxy = bitmaps[bitmap]; | |
| bmpProxy.flags |= OoprBitmapProxy::eShouldErase; | |
| } | |
| void OoprClientCache::setBitmapHeapBitmap(OoprBitmapHandle bitmap, const SkBitmap& skBitmap) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lg(mLock); | |
| OoprBitmapProxy& bmpProxy = bitmaps[bitmap]; | |
| uint32_t genId = skBitmap.getGenerationID(); | |
| if (bmpProxy.mLastBitmapGenId == genId) { | |
| return; | |
| } | |
| bmpProxy.mHeapBitmap = skBitmap; | |
| bmpProxy.mLastBitmapGenId = genId; | |
| bmpProxy.flags |= OoprBitmapProxy::eHeapBitmapDirty; | |
| } | |
| void OoprClientCache::setBitmapGraphicBuffer(OoprBitmapHandle bitmap, | |
| const sp<GraphicBuffer>& buffer) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lg(mLock); | |
| OoprBitmapProxy& bmpProxy = bitmaps[bitmap]; | |
| bmpProxy.mBuffer = buffer; | |
| bmpProxy.flags |= OoprBitmapProxy::eBufferDirty; | |
| } | |
| void OoprClientCache::bindSkImage(sk_sp<SkImage> from, OoprBitmapHandle to) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lg(mLock); | |
| OoprBitmapProxy& bmpProxy = bitmaps[to]; | |
| if (bmpProxy.boundImage != 0) { | |
| mappings.erase(bmpProxy.boundImage); | |
| } | |
| mappings[from->uniqueID()] = OoprImageRef{.kind = OoprImageRefKind::Bitmap, .bitmap = to}; | |
| bmpProxy.boundImage = from->uniqueID(); | |
| } | |
| void OoprClientCache::eraseBitmapMappings(const OoprBitmapProxy& proxy) { | |
| if (proxy.boundImage != 0) { | |
| mappings.erase(proxy.boundImage); | |
| } | |
| } | |
| void OoprClientCache::flushToCanvasAndBuildTransaction(IPCRecordingCanvas* canvas, | |
| gui::OoprTransaction& outTransaction) { | |
| std::lock_guard<std::mutex> lg(mLock); | |
| outTransaction.renderResourceToken = mToken; | |
| for (auto&& [handle, bmpProxy] : bitmaps) { | |
| if (bmpProxy.flags & OoprBitmapProxy::eShouldCreate) { | |
| canvas->createBitmap(handle); | |
| } | |
| if (bmpProxy.flags & OoprBitmapProxy::eShouldErase) { | |
| canvas->destroyBitmap(handle); | |
| } | |
| if (bmpProxy.flags & OoprBitmapProxy::eBufferDirty) { | |
| if (bmpProxy.mBuffer) { | |
| gui::OoprTransaction::HardwareBitmapBinding binding; | |
| binding.id = handle.id; | |
| binding.buffer = bmpProxy.mBuffer; | |
| outTransaction.bitmapBindings.push_back(binding); | |
| } else { | |
| ALOGE("flushToCanvasAndBuildTransaction: buffer is null for bitmap %s", | |
| to_string(handle).c_str()); | |
| } | |
| canvas->setBitmapGraphicBuffer(handle); | |
| } | |
| if (bmpProxy.flags & OoprBitmapProxy::eHeapBitmapDirty) { | |
| canvas->setBitmapHeapBitmap(handle, bmpProxy.mHeapBitmap); | |
| } | |
| bmpProxy.flags &= OoprBitmapProxy::eShouldErase; | |
| } | |
| std::erase_if(bitmaps, [this](const auto& pair) { | |
| if (pair.second.flags & OoprBitmapProxy::eShouldErase) { | |
| this->eraseBitmapMappings(pair.second); | |
| return true; | |
| } | |
| return false; | |
| }); | |
| for (auto&& [handle, nodeProxy] : nodes) { | |
| if (nodeProxy.flags & OoprNodeProxy::eShouldCreate) { | |
| canvas->createNode(handle); | |
| } | |
| if (nodeProxy.flags & OoprNodeProxy::eShouldErase) { | |
| canvas->destroyNode(handle); | |
| } | |
| if (nodeProxy.flags & OoprNodeProxy::eSurfaceDirty) { | |
| if (nodeProxy.mSurface) { | |
| canvas->setNodeSurface(handle, nodeProxy.mSurface->width(), | |
| nodeProxy.mSurface->height()); | |
| } | |
| } | |
| if (nodeProxy.flags & OoprNodeProxy::eSurfaceFilterDirty) { | |
| canvas->setNodeSurfaceFilter(handle, nodeProxy.subset, nodeProxy.clipBounds, | |
| nodeProxy.paint); | |
| } | |
| nodeProxy.flags &= OoprNodeProxy::eShouldErase; | |
| } | |
| std::erase_if(nodes, [this](const auto& pair) { | |
| if (pair.second.flags & OoprNodeProxy::eShouldErase) { | |
| this->eraseNodeMappings(pair.second); | |
| return true; | |
| } | |
| return false; | |
| }); | |
| logMetricsLocked(); | |
| } | |
| void OoprClientCache::destroyNode(OoprNodeHandle handle) { | |
| OOPR_TRACE_CALL(); | |
| std::lock_guard<std::mutex> lock(mLock); | |
| OoprNodeProxy& node = nodes[handle]; | |
| node.flags |= OoprNodeProxy::eShouldErase; | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("Flagging node proxy for erase, handle=%s", to_string(handle).c_str()); | |
| } | |
| }; | |
| void OoprClientCache::bindSkImage(sk_sp<SkImage> from, OoprNodeHandle to) { | |
| ATRACE_CALL(); | |
| std::lock_guard<std::mutex> lock(mLock); | |
| OoprNodeProxy& node = nodes[to]; | |
| uint32_t prevBoundImage = node.boundImage; | |
| if (prevBoundImage) { | |
| mappings.erase(prevBoundImage); | |
| } | |
| mappings[from->uniqueID()] = OoprImageRef{.kind = OoprImageRefKind::NodeImage, .nodeImage = to}; | |
| nodes[to].boundImage = from->uniqueID(); | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("Bound SkImage to node proxy, image.uniqueID=%u node.handle=%s", from->uniqueID(), | |
| to_string(to).c_str()); | |
| } | |
| } | |
| void OoprClientCache::eraseNodeMappings(const OoprNodeProxy& node) { | |
| if (node.boundImage) { | |
| mappings.erase(node.boundImage); | |
| } | |
| } | |
| OoprClientStats OoprClientCache::getStatsLocked() const { | |
| return OoprClientStats{ | |
| .nodeCount = nodes.size(), | |
| .bitmapCount = bitmaps.size(), | |
| .mappingCount = mappings.size(), | |
| .typefaceCount = typefaces.size(), | |
| }; | |
| } | |
| OoprClientStats OoprClientCache::getStats() const { | |
| std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(mLock)); | |
| return getStatsLocked(); | |
| } | |
| void OoprClientCache::logMetricsLocked() const { | |
| OoprClientStats stats = getStatsLocked(); | |
| ATRACE_INT64("oopr_client_nodes", (int64_t)stats.nodeCount); | |
| ATRACE_INT64("oopr_client_bitmaps", (int64_t)stats.bitmapCount); | |
| ATRACE_INT64("oopr_client_mappings", (int64_t)stats.mappingCount); | |
| ATRACE_INT64("oopr_client_typefaces", (int64_t)stats.typefaceCount); | |
| } | |
| void OoprClientCache::logMetrics() const { | |
| std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(mLock)); | |
| logMetricsLocked(); | |
| } | |
| OoprServerStats OoprServerCache::getStatsLocked() const { | |
| return OoprServerStats{ | |
| .nodeCount = nodes.size(), | |
| .bitmapCount = bitmaps.size(), | |
| .typefaceCount = typefaces.size(), | |
| .pendingBitmapBindingsCount = mPendingBitmapBindings.size(), | |
| }; | |
| } | |
| OoprServerStats OoprServerCache::getStats() const { | |
| std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(mLock)); | |
| return getStatsLocked(); | |
| } | |
| void OoprServerCache::logMetricsLocked() const { | |
| OoprServerStats stats = getStatsLocked(); | |
| ATRACE_INT64("oopr_server_nodes", (int64_t)stats.nodeCount); | |
| ATRACE_INT64("oopr_server_bitmaps", (int64_t)stats.bitmapCount); | |
| ATRACE_INT64("oopr_server_typefaces", (int64_t)stats.typefaceCount); | |
| ATRACE_INT64("oopr_server_pending_bitmaps", (int64_t)stats.pendingBitmapBindingsCount); | |
| } | |
| void OoprServerCache::logMetrics() const { | |
| std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(mLock)); | |
| logMetricsLocked(); | |
| } | |
| struct ShmemPaint { | |
| RSpan<uint8_t> data; | |
| }; | |
| std::string rectToString(const SkRect& rect); | |
| std::string skmatrixToString(const SkM44& matrix); | |
| std::string shmemPaintToString(const ShmemPaint& paint); | |
| std::string opToString(const IPCRenderBufferOp* op); | |
| std::string opTypeToString(uint32_t type); | |
| struct NodeImageFilterData { | |
| SkIRect subset = SkIRect::MakeEmpty(); | |
| SkIPoint offset = SkIPoint::Make(0, 0); | |
| }; | |
| struct NodeImageResolveResult { | |
| sk_sp<SkImage> image; | |
| std::optional<NodeImageFilterData> filter; | |
| }; | |
| static NodeImageResolveResult resolveImageRef(OoprImageRef ref, OoprServerCache* cache, | |
| skgpu::graphite::Recorder* recorder) { | |
| NodeImageResolveResult result; | |
| if (ref.kind == OoprImageRefKind::Bitmap) { | |
| auto it = cache->bitmaps.find(ref.bitmap); | |
| if (it != cache->bitmaps.end()) { | |
| if (!it->second.image) { | |
| if (it->second.graphicBuffer) { | |
| it->second.image = | |
| cache->funcs.getOrCreateBackendTexture(it->second.graphicBuffer); | |
| if (!it->second.image) { | |
| ALOGE("resolveImageRef failed: getOrCreateBackendTexture returned null for " | |
| "graphicBuffer of %s", | |
| to_string(ref.bitmap).c_str()); | |
| } | |
| } else if (!it->second.heapBitmap.drawsNothing()) { | |
| sk_sp<SkImage> rasterImg = SkImages::RasterFromBitmap(it->second.heapBitmap); | |
| if (rasterImg) { | |
| it->second.image = SkImages::TextureFromImage(recorder, rasterImg.get()); | |
| } | |
| if (!it->second.image) { | |
| ALOGE("resolveImageRef failed: TextureFromImage returned null for " | |
| "heapBitmap of %s", | |
| to_string(ref.bitmap).c_str()); | |
| } | |
| } else { | |
| ALOGE("resolveImageRef failed: %s has neither graphicBuffer nor valid " | |
| "heapBitmap in cache %p (cache bitmaps size=%zu)", | |
| to_string(ref.bitmap).c_str(), cache, cache->bitmaps.size()); | |
| } | |
| } | |
| result.image = it->second.image; | |
| } else { | |
| ALOGE("resolveImageRef failed: %s not found in server cache %p " | |
| "(cache bitmaps size=%zu)", | |
| to_string(ref.bitmap).c_str(), cache, cache->bitmaps.size()); | |
| } | |
| } else if (ref.kind == OoprImageRefKind::NodeImage) { | |
| auto it = cache->nodes.find(ref.nodeImage); | |
| if (it != cache->nodes.end()) { | |
| result.image = it->second.image; | |
| if (!result.image) { | |
| ALOGE("resolveImageRef failed: image is null for %s", | |
| to_string(ref.nodeImage).c_str()); | |
| } | |
| if (it->second.filter) { | |
| result.filter = NodeImageFilterData{ | |
| .subset = it->second.filter->outSubset, | |
| .offset = it->second.filter->outOffset, | |
| }; | |
| } | |
| } else { | |
| ALOGE("resolveImageRef failed: %s not found in server cache", | |
| to_string(ref.nodeImage).c_str()); | |
| } | |
| } else { | |
| ALOGE("resolveImageRef failed: unknown OoprImageRefKind %u", | |
| static_cast<uint32_t>(ref.kind)); | |
| } | |
| return result; | |
| } | |
| SkPaint fromShmemPaint(const ShmemPaint& paint, OoprServerCache* cache, | |
| skgpu::graphite::Recorder* recorder) { | |
| if (!paint.data.data) { | |
| return SkPaint(); | |
| } | |
| SkReadBuffer reader(paint.data.data.get(), paint.data.size); | |
| reader.setAllowSkSL(true); | |
| struct DeserialContext { | |
| OoprServerCache* cache; | |
| skgpu::graphite::Recorder* recorder; | |
| }; | |
| DeserialContext deserialCtx{cache, recorder}; | |
| SkDeserialProcs procs; | |
| procs.fImageCtx = &deserialCtx; | |
| procs.fImageDataProc = | |
| [](sk_sp<SkData> data, std::optional<SkAlphaType>, void* ctx) -> sk_sp<SkImage> { | |
| if (!data || data->size() != sizeof(OoprImageRef)) { | |
| return nullptr; | |
| } | |
| OoprImageRef nodeImage; | |
| memcpy(&nodeImage, data->data(), sizeof(nodeImage)); | |
| auto* dCtx = static_cast<DeserialContext*>(ctx); | |
| // TODO: do we need to compose a shader to apply the image filter offset? | |
| NodeImageResolveResult result = resolveImageRef(nodeImage, dCtx->cache, dCtx->recorder); | |
| return result.image; | |
| }; | |
| reader.setDeserialProcs(procs); | |
| return SkPaintPriv::Unflatten(reader); | |
| } | |
| bool toShmemPaint(RenderCommandBuffer& region, const SkPaint& paint, ShmemPaint& outPaint, | |
| OoprClientCache* clientCache) { | |
| SkSerialProcs procs; | |
| procs.fImageCtx = clientCache; | |
| procs.fImageProc = [](SkImage* img, void* ctx) -> sk_sp<const SkData> { | |
| OoprImageRef nodeImage = {}; | |
| OoprClientCache* cache = static_cast<OoprClientCache*>(ctx); | |
| auto it = cache->mappings.find(img->uniqueID()); | |
| if (it != cache->mappings.end()) { | |
| nodeImage = it->second; | |
| } | |
| return SkData::MakeWithCopy(&nodeImage, sizeof(nodeImage)); | |
| }; | |
| SkBinaryWriteBuffer writer(procs); | |
| SkPaintPriv::Flatten(paint, writer); | |
| sk_sp<SkData> data = writer.snapshotAsData(); | |
| if (!data) { | |
| ALOGE("Failed to snapshot SkData from SkPaint"); | |
| return false; | |
| } | |
| if (!SetRSpan(outPaint.data, region, (const uint8_t*)nullptr, data->size())) { | |
| return false; | |
| } | |
| if (data->size() > 0) { | |
| memcpy(outPaint.data.data.get(), data->data(), data->size()); | |
| } | |
| return true; | |
| } | |
| #define X(ty) \ | |
| struct ty; \ | |
| void setOpType(ty* op) { \ | |
| ((IPCRenderBufferOp*)op)->type = kOoprOpType_##ty; \ | |
| } | |
| OOPR_OP_TYPES | |
| #undef X | |
| template <typename T> | |
| T* allocOpHelper(RenderCommandBuffer& region, RList<IPCRenderBufferOp>* list) { | |
| T* op = region.alloc<T>(); | |
| if (!op) { | |
| LOG_ALWAYS_FATAL("Failed to allocate %zu bytes for op in command buffer", sizeof(T)); | |
| } | |
| setOpType(op); | |
| list->pushBack(op); | |
| return op; | |
| } | |
| template <typename T> | |
| T* allocOp(RenderCommandBuffer& region) { | |
| return allocOpHelper<T>(region, region.getWritePtr()->mCanvasOpRecordingList.get()); | |
| } | |
| template <typename T> | |
| T* allocSceneOp(RenderCommandBuffer& region) { | |
| return allocOpHelper<T>(region, ®ion.getWritePtr()->mSceneOps); | |
| } | |
| template <typename T> | |
| T* allocCleanupOp(RenderCommandBuffer& region) { | |
| return allocOpHelper<T>(region, ®ion.getWritePtr()->mCleanupOps); | |
| } | |
| #define OP_REQUIRE(expr) \ | |
| ({ \ | |
| if (!(expr)) { \ | |
| ALOGE("%s:%s:%d: Expression was false: %s", __FILE__, __func__, __LINE__, #expr); \ | |
| return nullptr; \ | |
| } \ | |
| }) | |
| struct SaveOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->save(); } | |
| std::string toString() const { return std::string("SaveOp"); } | |
| }; | |
| SaveOp* createSaveOp(RenderCommandBuffer& region) { | |
| SaveOp* op = allocOp<SaveOp>(region); | |
| OP_REQUIRE(op); | |
| return op; | |
| } | |
| struct RestoreOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->restore(); } | |
| std::string toString() const { return std::string("RestoreOp"); } | |
| }; | |
| RestoreOp* createRestoreOp(RenderCommandBuffer& region) { | |
| RestoreOp* op = allocOp<RestoreOp>(region); | |
| OP_REQUIRE(op); | |
| return op; | |
| } | |
| struct SaveLayerOp : IPCRenderBufferOp { | |
| SkRect bounds; | |
| ShmemPaint paint; | |
| bool hasBounds; | |
| bool hasPaint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_SaveLayer"); | |
| const SkRect* boundsPtr = hasBounds ? &bounds : nullptr; | |
| SkPaint p; | |
| const SkPaint* paintPtr = | |
| hasPaint ? &(p = fromShmemPaint(paint, ctx.cache, ctx.recorder)) : nullptr; | |
| ctx.canvas->saveLayer(boundsPtr, paintPtr); | |
| } | |
| std::string toString() const { return std::string("SaveLayerOp"); } | |
| }; | |
| SaveLayerOp* createSaveLayerOp(RenderCommandBuffer& region, const SkRect* bounds, | |
| const SkPaint* paint, OoprClientCache* clientCache) { | |
| SaveLayerOp* op = allocOp<SaveLayerOp>(region); | |
| OP_REQUIRE(op); | |
| if (bounds) { | |
| op->bounds = *bounds; | |
| op->hasBounds = true; | |
| } else { | |
| op->hasBounds = false; | |
| } | |
| if (paint) { | |
| OP_REQUIRE(toShmemPaint(region, *paint, op->paint, clientCache)); | |
| op->hasPaint = true; | |
| } else { | |
| op->hasPaint = false; | |
| } | |
| return op; | |
| } | |
| struct SaveBehindOp : IPCRenderBufferOp { | |
| SkRect subset; | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkAndroidFrameworkUtils::SaveBehind(ctx.canvas, subset.isEmpty() ? nullptr : &subset); | |
| } | |
| std::string toString() const { | |
| return std::string("SaveBehindOp subset: ") + rectToString(subset); | |
| } | |
| }; | |
| SaveBehindOp* createSaveBehindOp(RenderCommandBuffer& region, const SkRect& subset) { | |
| SaveBehindOp* op = allocOp<SaveBehindOp>(region); | |
| OP_REQUIRE(op); | |
| if (subset.isEmpty()) { | |
| op->subset.setEmpty(); | |
| } else { | |
| op->subset = subset; | |
| } | |
| return op; | |
| } | |
| struct ConcatOp : IPCRenderBufferOp { | |
| SkM44 matrix; | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->concat(matrix); } | |
| std::string toString() const { | |
| return std::string("ConcatOp matrix: ") + skmatrixToString(matrix); | |
| } | |
| }; | |
| ConcatOp* createConcatOp(RenderCommandBuffer& region, const SkM44& matrix) { | |
| ConcatOp* op = allocOp<ConcatOp>(region); | |
| OP_REQUIRE(op); | |
| op->matrix = matrix; | |
| return op; | |
| } | |
| struct SetMatrixOp : IPCRenderBufferOp { | |
| SkM44 matrix; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->setMatrix(SkM44(ctx.rootMatrix) * matrix); | |
| } | |
| std::string toString() const { | |
| return std::string("SetMatrixOp matrix: ") + skmatrixToString(matrix); | |
| } | |
| }; | |
| SetMatrixOp* createSetMatrixOp(RenderCommandBuffer& region, const SkM44& matrix) { | |
| SetMatrixOp* op = allocOp<SetMatrixOp>(region); | |
| OP_REQUIRE(op); | |
| op->matrix = matrix; | |
| return op; | |
| } | |
| struct ScaleOp : IPCRenderBufferOp { | |
| SkScalar sx, sy; | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->scale(sx, sy); } | |
| std::string toString() const { | |
| return std::string("ScaleOp sx: ") + std::to_string(sx) + std::string(" sy: ") + | |
| std::to_string(sy); | |
| } | |
| }; | |
| ScaleOp* createScaleOp(RenderCommandBuffer& region, SkScalar sx, SkScalar sy) { | |
| ScaleOp* op = allocOp<ScaleOp>(region); | |
| OP_REQUIRE(op); | |
| op->sx = sx; | |
| op->sy = sy; | |
| return op; | |
| } | |
| struct TranslateOp : IPCRenderBufferOp { | |
| SkScalar dx, dy; | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->translate(dx, dy); } | |
| std::string toString() const { | |
| return std::string("TranslateOp dx: ") + std::to_string(dx) + std::string(" dy: ") + | |
| std::to_string(dy); | |
| } | |
| }; | |
| TranslateOp* createTranslateOp(RenderCommandBuffer& region, SkScalar dx, SkScalar dy) { | |
| TranslateOp* op = allocOp<TranslateOp>(region); | |
| OP_REQUIRE(op); | |
| op->dx = dx; | |
| op->dy = dy; | |
| return op; | |
| } | |
| struct ClipPathOp : IPCRenderBufferOp { | |
| SkClipOp op; | |
| bool aa; | |
| RSpan<uint8_t> pathData; | |
| void execute(const OoprExecuteContext& ctx) { | |
| const SkPath path = | |
| SkPath::ReadFromMemory(pathData.data.get(), pathData.size).value_or(SkPath()); | |
| ctx.canvas->clipPath(path, op, aa); | |
| } | |
| std::string toString() const { return "ClipPathOp"; } | |
| }; | |
| ClipPathOp* createClipPathOp(RenderCommandBuffer& region, const SkPath& path, SkClipOp op, | |
| bool aa) { | |
| ClipPathOp* opData = allocOp<ClipPathOp>(region); | |
| OP_REQUIRE(opData); | |
| size_t pathSize = path.writeToMemory(nullptr); | |
| OP_REQUIRE(SetRSpan<uint8_t>(opData->pathData, region, nullptr, pathSize)); | |
| path.writeToMemory(opData->pathData.data.get()); | |
| opData->op = op; | |
| opData->aa = aa; | |
| return opData; | |
| } | |
| struct ClipRectOp : IPCRenderBufferOp { | |
| SkRect rect; | |
| SkClipOp op; | |
| bool aa; | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->clipRect(rect, op, aa); } | |
| std::string toString() const { | |
| return std::string("ClipRectOp: rect: ") + rectToString(rect) + std::string(" op: ") + | |
| std::to_string((int)op) + std::string(" aa: ") + std::to_string(aa); | |
| } | |
| }; | |
| ClipRectOp* createClipRectOp(RenderCommandBuffer& region, const SkRect& rect, SkClipOp op, | |
| bool aa) { | |
| ClipRectOp* opData = allocOp<ClipRectOp>(region); | |
| OP_REQUIRE(opData); | |
| opData->rect = rect; | |
| opData->op = op; | |
| opData->aa = aa; | |
| return opData; | |
| } | |
| struct ClipRRectOp : IPCRenderBufferOp { | |
| SkRRect rrect; | |
| SkClipOp op; | |
| bool aa; | |
| void execute(const OoprExecuteContext& ctx) { ctx.canvas->clipRRect(rrect, op, aa); } | |
| std::string toString() const { | |
| std::string rectAsString = std::string(rrect.dumpToString(false).c_str()); | |
| return std::string("ClipRRectOp: rrect: ") + rectAsString + std::string(" op: ") + | |
| std::to_string((int)op) + std::string(" aa: ") + std::to_string(aa); | |
| } | |
| }; | |
| ClipRRectOp* createClipRRectOp(RenderCommandBuffer& region, const SkRRect& rrect, SkClipOp op, | |
| bool aa) { | |
| ClipRRectOp* opData = allocOp<ClipRRectOp>(region); | |
| OP_REQUIRE(opData); | |
| opData->rrect = rrect; | |
| opData->op = op; | |
| opData->aa = aa; | |
| return opData; | |
| } | |
| struct ClipRegionOp : IPCRenderBufferOp { | |
| SkClipOp op; | |
| RSpan<uint8_t> regionData; | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkRegion region; | |
| region.readFromMemory(regionData.data.get(), regionData.size); | |
| ctx.canvas->clipRegion(region, op); | |
| } | |
| std::string toString() const { return "ClipRegionOp"; } | |
| }; | |
| ClipRegionOp* createClipRegionOp(RenderCommandBuffer& region, const SkRegion& r, SkClipOp op) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return nullptr; | |
| } | |
| struct ClipShaderOp : IPCRenderBufferOp { | |
| SkClipOp op; | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "ClipShaderOp"; } | |
| }; | |
| ClipShaderOp* createClipShaderOp(RenderCommandBuffer& region, const sk_sp<SkShader>& /*shader*/, | |
| SkClipOp op) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return nullptr; | |
| } | |
| struct ResetClipOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkAndroidFrameworkUtils::ResetClip(ctx.canvas); | |
| if (!ctx.rootClip.isEmpty()) { | |
| SkMatrix ctm = ctx.canvas->getTotalMatrix(); | |
| ctx.canvas->setMatrix(SkMatrix::I()); | |
| ctx.canvas->clipRect(ctx.rootClip, SkClipOp::kIntersect, false); | |
| ctx.canvas->setMatrix(ctm); | |
| } | |
| } | |
| std::string toString() const { return "ResetClipOp"; } | |
| }; | |
| ResetClipOp* createResetClipOp(RenderCommandBuffer& region) { | |
| ResetClipOp* op = allocOp<ResetClipOp>(region); | |
| OP_REQUIRE(op); | |
| return op; | |
| } | |
| struct DrawPaintOp : IPCRenderBufferOp { | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawPaint(fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawPaintOp" + shmemPaintToString(paint); } | |
| }; | |
| DrawPaintOp* createDrawPaintOp(RenderCommandBuffer& region, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawPaintOp* op = allocOp<DrawPaintOp>(region); | |
| OP_REQUIRE(op); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawBehindOp : IPCRenderBufferOp { | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkCanvasPriv::DrawBehind(ctx.canvas, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawBehindOp"; } | |
| }; | |
| DrawBehindOp* createDrawBehindOp(RenderCommandBuffer& region, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawBehindOp* op = allocOp<DrawBehindOp>(region); | |
| OP_REQUIRE(op); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawShadowRecOp : IPCRenderBufferOp { | |
| RSpan<uint8_t> pathData; | |
| SkDrawShadowRec rec; | |
| void execute(const OoprExecuteContext& ctx) { | |
| const SkPath path = | |
| SkPath::ReadFromMemory(pathData.data.get(), pathData.size).value_or(SkPath()); | |
| ctx.canvas->private_draw_shadow_rec(path, rec); | |
| } | |
| std::string toString() const { return "DrawShadowRecOp"; } | |
| }; | |
| DrawShadowRecOp* createDrawShadowRecOp(RenderCommandBuffer& region, const SkPath& path, | |
| const SkDrawShadowRec& rec) { | |
| DrawShadowRecOp* op = allocOp<DrawShadowRecOp>(region); | |
| OP_REQUIRE(op); | |
| size_t pathSize = path.writeToMemory(nullptr); | |
| OP_REQUIRE(SetRSpan<uint8_t>(op->pathData, region, nullptr, pathSize)); | |
| path.writeToMemory(op->pathData.data.get()); | |
| op->rec = rec; | |
| return op; | |
| } | |
| struct DrawPathOp : IPCRenderBufferOp { | |
| ShmemPaint paint; | |
| RSpan<uint8_t> pathData; | |
| void execute(const OoprExecuteContext& ctx) { | |
| const SkPath path = | |
| SkPath::ReadFromMemory(pathData.data.get(), pathData.size).value_or(SkPath()); | |
| ctx.canvas->drawPath(path, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawPathOp"; } | |
| }; | |
| DrawPathOp* createDrawPathOp(RenderCommandBuffer& region, const SkPath& path, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawPathOp* op = allocOp<DrawPathOp>(region); | |
| OP_REQUIRE(op); | |
| size_t pathSize = path.writeToMemory(nullptr); | |
| OP_REQUIRE(SetRSpan<uint8_t>(op->pathData, region, nullptr, pathSize)); | |
| path.writeToMemory(op->pathData.data.get()); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawRectOp : IPCRenderBufferOp { | |
| SkRect rect; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawRect(rect, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { | |
| return std::string("DrawRectOp rect(") + rectToString(rect) + ") " + | |
| std::string(" paint: ") + shmemPaintToString(paint); | |
| } | |
| }; | |
| DrawRectOp* createDrawRectOp(RenderCommandBuffer& region, const SkRect& r, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawRectOp* op = allocOp<DrawRectOp>(region); | |
| OP_REQUIRE(op); | |
| op->rect = r; | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawRegionOp : IPCRenderBufferOp { | |
| RSpan<uint8_t> regionData; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkRegion region; | |
| region.readFromMemory(regionData.data.get(), regionData.size); | |
| ctx.canvas->drawRegion(region, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawRegionOp"; } | |
| }; | |
| DrawRegionOp* createDrawRegionOp(RenderCommandBuffer& region, const SkRegion& r, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawRegionOp* op = allocOp<DrawRegionOp>(region); | |
| OP_REQUIRE(op); | |
| size_t regionSize = r.writeToMemory(nullptr); | |
| OP_REQUIRE(SetRSpan<uint8_t>(op->regionData, region, nullptr, regionSize)); | |
| r.writeToMemory(op->regionData.data.get()); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawOvalOp : IPCRenderBufferOp { | |
| SkRect oval; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawOval(oval, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return std::string("DrawOvalOp") + rectToString(oval); } | |
| }; | |
| DrawOvalOp* createDrawOvalOp(RenderCommandBuffer& region, const SkRect& o, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawOvalOp* op = allocOp<DrawOvalOp>(region); | |
| OP_REQUIRE(op); | |
| op->oval = o; | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DrawArcOp : IPCRenderBufferOp { | |
| SkRect oval; | |
| SkScalar startAngle; | |
| SkScalar sweepAngle; | |
| bool useCenter; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawArc(oval, startAngle, sweepAngle, useCenter, | |
| fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { | |
| return std::string("DrawArcOp") + rectToString(oval) + std::string(" startAngle: ") + | |
| std::to_string(startAngle) + std::string(" sweepAngle: ") + | |
| std::to_string(sweepAngle) + std::string(" useCenter: ") + | |
| std::to_string(useCenter); | |
| } | |
| }; | |
| DrawArcOp* createDrawArcOp(RenderCommandBuffer& region, const SkRect& oval, SkScalar startAngle, | |
| SkScalar sweepAngle, bool useCenter, const SkPaint& paint, | |
| OoprClientCache* clientCache) { | |
| DrawArcOp* op = allocOp<DrawArcOp>(region); | |
| OP_REQUIRE(op); | |
| OP_REQUIRE(toShmemPaint(region, paint, op->paint, clientCache)); | |
| op->oval = oval; | |
| op->startAngle = startAngle; | |
| op->sweepAngle = sweepAngle; | |
| op->useCenter = useCenter; | |
| return op; | |
| } | |
| struct DrawRRectOp : IPCRenderBufferOp { | |
| SkRRect rrect; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawRRect(rrect, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { | |
| return std::string("DrawRRectOp") + std::string(rrect.dumpToString(false).c_str()); | |
| } | |
| }; | |
| DrawRRectOp* createDrawRRectOp(RenderCommandBuffer& region, const SkRRect& rr, const SkPaint& p, | |
| OoprClientCache* clientCache) { | |
| DrawRRectOp* op = allocOp<DrawRRectOp>(region); | |
| OP_REQUIRE(op); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, clientCache)); | |
| op->rrect = rr; | |
| return op; | |
| } | |
| struct DrawAnnotationOp : IPCRenderBufferOp { | |
| SkRect rect; | |
| RSpan<char> key; | |
| RSpan<uint8_t> value; | |
| void execute(const OoprExecuteContext& ctx) { | |
| sk_sp<SkData> data; | |
| if (value.size > 0) { | |
| data = SkData::MakeWithCopy(value.data.get(), value.size); | |
| } | |
| ctx.canvas->drawAnnotation(rect, key.data.get(), data.get()); | |
| } | |
| std::string toString() const { return "DrawAnnotationOp"; } | |
| }; | |
| DrawAnnotationOp* createDrawAnnotationOp(RenderCommandBuffer& region, const SkRect& rect, | |
| const char* key, SkData* data) { | |
| DrawAnnotationOp* op = allocOp<DrawAnnotationOp>(region); | |
| OP_REQUIRE(op); | |
| op->rect = rect; | |
| size_t keyLen = key ? strlen(key) + 1 : 0; | |
| OP_REQUIRE(SetRSpan(op->key, region, key, keyLen)); | |
| if (data) { | |
| OP_REQUIRE(SetRSpan(op->value, region, (const uint8_t*)data->data(), data->size())); | |
| } else { | |
| op->value.size = 0; | |
| op->value.data = nullptr; | |
| } | |
| return op; | |
| } | |
| struct DrawDrawableOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "DrawDrawableOp"; } | |
| }; | |
| DrawDrawableOp* createDrawDrawableOp(RenderCommandBuffer& region, SkDrawable* drawable, | |
| const SkMatrix* matrix) { | |
| DrawDrawableOp* op = allocOp<DrawDrawableOp>(region); | |
| OP_REQUIRE(op); | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return op; | |
| } | |
| struct DrawPictureOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "DrawPictureOp"; } | |
| }; | |
| DrawPictureOp* createDrawPictureOp(RenderCommandBuffer& region, const SkPicture* picture, | |
| const SkMatrix* matrix, const SkPaint* paint) { | |
| DrawPictureOp* op = allocOp<DrawPictureOp>(region); | |
| OP_REQUIRE(op); | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return op; | |
| } | |
| struct DrawImageOp : IPCRenderBufferOp { | |
| OoprImageRef nodeImage; | |
| SkScalar left; | |
| SkScalar top; | |
| SkSamplingOptions sampling; | |
| ShmemPaint paint; | |
| bool hasPaint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| NodeImageResolveResult result = resolveImageRef(nodeImage, ctx.cache, ctx.recorder); | |
| if (!result.image) { | |
| return; | |
| } | |
| SkScalar drawX = left; | |
| SkScalar drawY = top; | |
| if (result.filter) { | |
| drawX = result.filter->offset.x(); | |
| drawY = result.filter->offset.y(); | |
| } | |
| SkPaint p; | |
| const SkPaint* paintPtr = | |
| hasPaint ? &(p = fromShmemPaint(paint, ctx.cache, ctx.recorder)) : nullptr; | |
| ctx.canvas->drawImage(result.image, drawX, drawY, sampling, paintPtr); | |
| } | |
| std::string toString() const { return "DrawImageOp"; } | |
| }; | |
| std::optional<OoprImageRef> findImageRef(const SkImage* image, OoprClientCache* cache) { | |
| if (!image) return std::nullopt; | |
| std::lock_guard<std::mutex> lock(cache->mLock); | |
| auto it = cache->mappings.find(image->uniqueID()); | |
| if (it == cache->mappings.end()) { | |
| return std::nullopt; | |
| } | |
| return it->second; | |
| } | |
| DrawImageOp* createDrawImageOp(RenderCommandBuffer& region, const SkImage* image, SkScalar left, | |
| SkScalar top, const SkSamplingOptions& sampling, | |
| const SkPaint* paint, OoprClientCache* clientCache) { | |
| std::optional<OoprImageRef> optImageRef = findImageRef(image, clientCache); | |
| if (!optImageRef) { | |
| return nullptr; | |
| } | |
| DrawImageOp* op = allocOp<DrawImageOp>(region); | |
| OP_REQUIRE(op); | |
| op->nodeImage = *optImageRef; | |
| op->left = left; | |
| op->top = top; | |
| op->sampling = sampling; | |
| if (paint) { | |
| OP_REQUIRE(toShmemPaint(region, *paint, op->paint, clientCache)); | |
| op->hasPaint = true; | |
| } else { | |
| op->hasPaint = false; | |
| } | |
| return op; | |
| } | |
| // TODO(b/448196792): Implement hardware bitmap support | |
| struct DrawImageRectOp : IPCRenderBufferOp { | |
| OoprImageRef nodeImage; | |
| SkRect src; | |
| SkRect dst; | |
| SkSamplingOptions sampling; | |
| ShmemPaint paint; | |
| bool hasPaint; | |
| SkCanvas::SrcRectConstraint constraint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| NodeImageResolveResult result = resolveImageRef(nodeImage, ctx.cache, ctx.recorder); | |
| if (!result.image) { | |
| return; | |
| } | |
| SkRect drawSrc = src; | |
| SkRect drawDst = dst; | |
| if (result.filter) { | |
| drawSrc = SkRect::Make(result.filter->subset); | |
| drawDst = SkRect::MakeXYWH(result.filter->offset.x(), result.filter->offset.y(), | |
| drawSrc.width(), drawSrc.height()); | |
| } | |
| SkPaint p; | |
| const SkPaint* paintPtr = | |
| hasPaint ? &(p = fromShmemPaint(paint, ctx.cache, ctx.recorder)) : nullptr; | |
| ctx.canvas->drawImageRect(result.image, drawSrc, drawDst, sampling, paintPtr, constraint); | |
| } | |
| std::string toString() const { return "DrawImageRectOp"; } | |
| }; | |
| DrawImageRectOp* createDrawImageRectOp(RenderCommandBuffer& region, const SkImage* image, | |
| const SkRect& src, const SkRect& dst, | |
| const SkSamplingOptions& sampling, const SkPaint* paint, | |
| SkCanvas::SrcRectConstraint constraint, | |
| OoprClientCache* clientCache) { | |
| std::optional<OoprImageRef> optImageRef = findImageRef(image, clientCache); | |
| if (!optImageRef) return nullptr; | |
| DrawImageRectOp* op = allocOp<DrawImageRectOp>(region); | |
| OP_REQUIRE(op); | |
| op->nodeImage = *optImageRef; | |
| op->src = src; | |
| op->dst = dst; | |
| op->sampling = sampling; | |
| if (paint) { | |
| OP_REQUIRE(toShmemPaint(region, *paint, op->paint, clientCache)); | |
| op->hasPaint = true; | |
| } else { | |
| op->hasPaint = false; | |
| } | |
| op->constraint = constraint; | |
| return op; | |
| } | |
| struct UploadTypefaceOp : IPCRenderBufferOp { | |
| uint32_t fontId; | |
| RSpan<uint8_t> data; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_FORMAT("OOPR_expensive_server_UploadTypeface id=%u", fontId); | |
| if (data.data.get() && data.size > 0) { | |
| SkMemoryStream stream(data.data.get(), data.size); | |
| sk_sp<SkTypeface> tf = SkTypeface::MakeDeserialize(&stream, nullptr); | |
| if (tf) { | |
| ctx.cache->typefaces[fontId] = tf; | |
| } else { | |
| ALOGE("Failed to deserialize Typeface for font id %u", fontId); | |
| } | |
| } | |
| } | |
| std::string toString() const { | |
| return std::string("UploadTypefaceOp id=") + std::to_string(fontId) + | |
| std::string(" size=") + std::to_string(data.size); | |
| } | |
| }; | |
| void createUploadTypefaceOp(RenderCommandBuffer& region, uint32_t fontId, const SkData* data) { | |
| ATRACE_FORMAT("OOPR_expensive_client_UploadTypeface id=%u (%zu bytes)", fontId, data->size()); | |
| UploadTypefaceOp* op = allocSceneOp<UploadTypefaceOp>(region); | |
| op->fontId = fontId; | |
| if (!SetRSpan(op->data, region, (const uint8_t*)data->data(), data->size())) { | |
| LOG_ALWAYS_FATAL("Failed to allocate %zu bytes in command buffer for font id %u", | |
| data->size(), fontId); | |
| } | |
| } | |
| struct ShmemTypeface { | |
| RSpan<char> name; | |
| int weight; | |
| int width; | |
| SkFontStyle::Slant slant; | |
| }; | |
| struct SerializeTypefaceContext { | |
| RenderCommandBuffer& region; | |
| OoprClientCache* cache; | |
| }; | |
| SkSerialReturnType serializeTypeFace(SkTypeface* tf, void* ctx) { | |
| if (!tf) { | |
| return nullptr; | |
| } | |
| SerializeTypefaceContext* stc = reinterpret_cast<SerializeTypefaceContext*>(ctx); | |
| RenderCommandBuffer& region = stc->region; | |
| OoprClientCache* cache = stc->cache; | |
| uint32_t id = tf->uniqueID(); | |
| if (cache->typefaces.count(id) == 0) { | |
| auto data = tf->serialize(SkTypeface::SerializeBehavior::kDoIncludeData); | |
| if (!data || data->size() == 0) { | |
| LOG_ALWAYS_FATAL("Failed to serialize Typeface data for font id %u", id); | |
| } | |
| createUploadTypefaceOp(region, id, data.get()); | |
| cache->typefaces.insert(id); | |
| } | |
| return SkData::MakeWithCopy(&id, sizeof(id)); | |
| } | |
| sk_sp<SkTypeface> deserializeTypeFace(SkStream& stream, void* ctx) { | |
| auto* cache = reinterpret_cast<OoprServerCache*>(ctx); | |
| if (!cache) { | |
| ALOGE("Trying to draw text with no resource cache!"); | |
| return nullptr; | |
| } | |
| uint32_t id; | |
| if (stream.read(&id, sizeof(id)) != sizeof(id)) { | |
| return nullptr; | |
| } | |
| auto it = cache->typefaces.find(id); | |
| if (it != cache->typefaces.end()) { | |
| return it->second; | |
| } | |
| ALOGE("Typeface id %u expected to be cached but not found", id); | |
| return nullptr; | |
| } | |
| struct DrawTextBlobOp : IPCRenderBufferOp { | |
| ShmemPaint paint; | |
| SkScalar x; | |
| SkScalar y; | |
| RSpan<uint8_t> blobData; | |
| void execute(const OoprExecuteContext& ctx) { | |
| SkDeserialProcs procs; | |
| procs.fTypefaceCtx = ctx.cache; | |
| procs.fTypefaceStreamProc = deserializeTypeFace; | |
| sk_sp<SkTextBlob> blob = SkTextBlob::Deserialize(blobData.data.get(), blobData.size, procs); | |
| if (blob) { | |
| ctx.canvas->drawTextBlob(blob, x, y, fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } else { | |
| ALOGE("Failed to deserialize text blob"); | |
| } | |
| } | |
| std::string toString() const { return "DrawTextBlobOp"; } | |
| }; | |
| DrawTextBlobOp* createDrawTextBlobOp(RenderCommandBuffer& region, const SkTextBlob* blob, | |
| SkScalar x_in, SkScalar y_in, const SkPaint& p, | |
| OoprClientCache* cache) { | |
| SkSerialProcs procs; | |
| SerializeTypefaceContext ctx = {region, cache}; | |
| procs.fTypefaceCtx = &ctx; | |
| procs.fTypefaceProc = serializeTypeFace; | |
| auto data = blob->serialize(procs); | |
| OP_REQUIRE(data); | |
| DrawTextBlobOp* op = allocOp<DrawTextBlobOp>(region); | |
| OP_REQUIRE(op); | |
| OP_REQUIRE(toShmemPaint(region, p, op->paint, cache)); | |
| op->x = x_in; | |
| op->y = y_in; | |
| OP_REQUIRE(SetRSpan<uint8_t>(op->blobData, region, (const uint8_t*)data->data(), data->size())); | |
| return op; | |
| } | |
| struct DrawPatchOp : IPCRenderBufferOp { | |
| RSpan<SkPoint> points; | |
| RSpan<SkColor> colors; | |
| RSpan<SkPoint> texCoords; | |
| SkBlendMode mode; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawPatch(points.data.get(), colors.data.get(), texCoords.data.get(), mode, | |
| fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawPatchOp"; } | |
| }; | |
| DrawPatchOp* createDrawPatchOp(RenderCommandBuffer& region, const SkPoint inPoints[12], | |
| const SkColor inColors[4], const SkPoint inTexCoords[4], | |
| SkBlendMode inMode, const SkPaint& inPaint, | |
| OoprClientCache* clientCache) { | |
| DrawPatchOp* op = allocOp<DrawPatchOp>(region); | |
| OP_REQUIRE(op); | |
| op->mode = inMode; | |
| OP_REQUIRE(toShmemPaint(region, inPaint, op->paint, clientCache)); | |
| OP_REQUIRE(SetRSpan(op->points, region, inPoints, 12)); | |
| OP_REQUIRE(SetRSpan(op->colors, region, inColors, 4)); | |
| OP_REQUIRE(SetRSpan(op->texCoords, region, inTexCoords, 4)); | |
| return op; | |
| } | |
| struct DrawPointsOp : IPCRenderBufferOp { | |
| SkCanvas::PointMode mode; | |
| RSpan<SkPoint> points; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ctx.canvas->drawPoints(mode, {points.data.get(), points.size}, | |
| fromShmemPaint(paint, ctx.cache, ctx.recorder)); | |
| } | |
| std::string toString() const { return "DrawPointsOp"; } | |
| }; | |
| DrawPointsOp* createDrawPointsOp(RenderCommandBuffer& region, SkCanvas::PointMode mode, | |
| size_t count, const SkPoint* points, const SkPaint& paint, | |
| OoprClientCache* clientCache) { | |
| DrawPointsOp* op = allocOp<DrawPointsOp>(region); | |
| OP_REQUIRE(op); | |
| op->mode = mode; | |
| OP_REQUIRE(toShmemPaint(region, paint, op->paint, clientCache)); | |
| OP_REQUIRE(SetRSpan(op->points, region, points, count)); | |
| return op; | |
| } | |
| struct DrawVerticesOp : IPCRenderBufferOp { | |
| SkBlendMode mode; | |
| ShmemPaint paint; | |
| RSpan<uint8_t> verticesData; | |
| void execute(const OoprExecuteContext&) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| #if 0 | |
| SkReadBuffer readBuffer(verticesData.data.get(), verticesData.size); | |
| sk_sp<SkVertices> vertices = SkVerticesPriv::Decode(readBuffer); | |
| if (vertices) { | |
| c->drawVertices(vertices, mode, fromShmemPaint(paint, cache)); | |
| } | |
| #endif | |
| } | |
| std::string toString() const { return "DrawVerticesOp"; } | |
| }; | |
| DrawVerticesOp* createDrawVerticesOp(RenderCommandBuffer& region, const SkVertices* vertices, | |
| SkBlendMode mode, const SkPaint& paint, | |
| OoprClientCache* clientCache) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return nullptr; | |
| #if 0 | |
| DrawVerticesOp* op = allocOp<DrawVerticesOp>(region); | |
| OP_REQUIRE(op); | |
| op->mode = mode; | |
| OP_REQUIRE(toShmemPaint(region, paint, op->paint, clientCache)); | |
| SkBinaryWriteBuffer writeBuffer(SkSerialProcs{}); | |
| vertices->priv().encode(writeBuffer); | |
| auto data = writeBuffer.snapshotAsData(); | |
| OP_REQUIRE(SetRSpan<uint8_t>(op->verticesData, region, | |
| reinterpret_cast<const uint8_t*>(data->data()), data->size())); | |
| return op; | |
| #endif | |
| } | |
| /*struct DrawMeshOp { | |
| DrawMeshOp(const Mesh& mesh, const SkPaint& paint) { | |
| ALOGE("Not implemented %s", __FUNCTION__); | |
| } | |
| };*/ | |
| struct DrawSkMeshOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "DrawSkMeshOp"; } | |
| }; | |
| DrawSkMeshOp* createDrawSkMeshOp(RenderCommandBuffer& region, const SkMesh& mesh, | |
| sk_sp<SkBlender> blender, const SkPaint& paint, | |
| OoprClientCache* clientCache) { | |
| DrawSkMeshOp* op = allocOp<DrawSkMeshOp>(region); | |
| OP_REQUIRE(op); | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return op; | |
| } | |
| struct DrawAtlasOp : IPCRenderBufferOp { | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "DrawAtlasOp"; } | |
| }; | |
| DrawAtlasOp* createDrawAtlasOp(RenderCommandBuffer& region, const SkImage* atlas, | |
| const SkRSXform* xform, const SkRect* tex, const SkColor* colors, | |
| int count, SkBlendMode mode, const SkSamplingOptions& sampling, | |
| const SkRect* cull, const SkPaint* paint) { | |
| DrawAtlasOp* op = allocOp<DrawAtlasOp>(region); | |
| OP_REQUIRE(op); | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return op; | |
| } | |
| struct DrawProxySurfaceControlOp : IPCRenderBufferOp { | |
| int proxyId; | |
| void execute(const OoprExecuteContext&) { IPCRENDERBUFFER_UNIMPLEMENTED; } | |
| std::string toString() const { return "DrawProxySurfaceControlOp"; } | |
| }; | |
| DrawProxySurfaceControlOp* createDrawProxySurfaceControlOp(RenderCommandBuffer& region, int id) { | |
| DrawProxySurfaceControlOp* op = allocOp<DrawProxySurfaceControlOp>(region); | |
| OP_REQUIRE(op); | |
| op->proxyId = id; | |
| return op; | |
| } | |
| struct CreateNodeOp : IPCRenderBufferOp { | |
| OoprNodeHandle handle; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_CreateNode"); | |
| ctx.cache->nodes.try_emplace(handle); | |
| } | |
| std::string toString() const { return std::string("CreateNodeOp handle=") + to_string(handle); } | |
| }; | |
| CreateNodeOp* createCreateNodeOp(RenderCommandBuffer& region, OoprNodeHandle handle) { | |
| ATRACE_NAME("OOPR_expensive_client_CreateNode"); | |
| CreateNodeOp* op = allocSceneOp<CreateNodeOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| return op; | |
| } | |
| struct SetNodeSurfaceOp : IPCRenderBufferOp { | |
| OoprNodeHandle handle; | |
| int32_t width; | |
| int32_t height; | |
| void execute(const OoprExecuteContext& ctx) { | |
| auto it = ctx.cache->nodes.find(handle); | |
| if (it == ctx.cache->nodes.end()) { | |
| ALOGE("Failed to find node corresponding to handle=%s for SetNodeSurfaceOp", | |
| to_string(handle).c_str()); | |
| return; | |
| } | |
| OoprNode& node = it->second; | |
| if (node.surface && node.surface->width() == width && | |
| node.surface->height() == height) { | |
| return; | |
| } | |
| sk_sp<SkSurface> surface = ctx.cache->funcs.createHardwareSurface(width, height); | |
| if (!surface) { | |
| ALOGE("Failed to create surface for SetNodeSurfaceOp handle=%s", | |
| to_string(handle).c_str()); | |
| return; | |
| } | |
| node.surface = surface; | |
| node.image.reset(); | |
| node.filterDirty = true; | |
| } | |
| std::string toString() const { | |
| return std::string("SetNodeSurfaceOp handle=") + to_string(handle) + | |
| " w=" + std::to_string(width) + " h=" + std::to_string(height); | |
| } | |
| }; | |
| SetNodeSurfaceOp* createSetNodeSurfaceOp(RenderCommandBuffer& region, OoprNodeHandle handle, | |
| int32_t width, int32_t height) { | |
| ATRACE_FORMAT("OOPR_expensive_client_SetNodeSurface %dx%d", width, height); | |
| SetNodeSurfaceOp* op = allocSceneOp<SetNodeSurfaceOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| op->width = width; | |
| op->height = height; | |
| return op; | |
| } | |
| static void updateNodeSnapshotIfRequired(OoprNode& node, OoprServerCache* cache) { | |
| if (!node.surface) { | |
| return; | |
| } | |
| if (!node.filter) { | |
| if (!node.image) { | |
| node.image = node.surface->makeTemporaryImage(); | |
| } | |
| return; | |
| } | |
| if (!node.filterDirty && node.image) { | |
| return; | |
| } | |
| auto& filter = *node.filter; | |
| sk_sp<SkImage> snapshot = node.surface->makeTemporaryImage(); | |
| if (!snapshot) { | |
| return; | |
| } | |
| skgpu::graphite::Recorder* recorder = node.surface->recorder(); | |
| if (!recorder) { | |
| ALOGE("updateNodeSnapshotIfRequired: node surface has no Graphite recorder"); | |
| return; | |
| } | |
| ATRACE_NAME("OOPR_MakeWithFilter"); | |
| sk_sp<SkImage> filtered = | |
| SkImages::MakeWithFilter(recorder, snapshot, filter.paint.getImageFilter(), | |
| filter.subset, filter.clipBounds, | |
| &filter.outSubset, &filter.outOffset); | |
| if (!filtered) { | |
| ALOGE("updateNodeSnapshotIfRequired: failed to create filter image"); | |
| return; | |
| } | |
| // TODO(b/549741762): Make an exact 1:1 copy of the full filtered image texture to prevent | |
| // scratch pool recycling in Graphite until MakeWithFilter returns non-budgeted images. | |
| sk_sp<SkImage> copy = filtered->makeSubset(recorder, filtered->bounds(), {}); | |
| if (copy) { | |
| node.image = std::move(copy); | |
| } else { | |
| ALOGE("updateNodeSnapshotIfRequired: failed to copy filter image"); | |
| node.image = std::move(filtered); | |
| } | |
| node.filterDirty = false; | |
| } | |
| struct SetNodeSurfaceFilterOp : IPCRenderBufferOp { | |
| OoprNodeHandle handle; | |
| SkIRect subset; | |
| SkIRect clipBounds; | |
| ShmemPaint paint; | |
| void execute(const OoprExecuteContext& ctx) { | |
| auto it = ctx.cache->nodes.find(handle); | |
| if (it == ctx.cache->nodes.end()) { | |
| ALOGE("Failed to find node corresponding to handle=%s", to_string(handle).c_str()); | |
| return; | |
| } | |
| OoprNode& node = it->second; | |
| if (!node.surface) { | |
| ALOGE("SetNodeSurfaceFilterOp: node %s has no surface", to_string(handle).c_str()); | |
| return; | |
| } | |
| skgpu::graphite::Recorder* recorder = node.surface->recorder(); | |
| if (!recorder) { | |
| ALOGE("SetNodeSurfaceFilterOp: node %s surface has no Graphite recorder", | |
| to_string(handle).c_str()); | |
| return; | |
| } | |
| node.filter = OoprNodeFilter{ | |
| .paint = fromShmemPaint(paint, ctx.cache, recorder), | |
| .subset = subset, | |
| .clipBounds = clipBounds, | |
| .outSubset = SkIRect::MakeEmpty(), | |
| .outOffset = SkIPoint::Make(0, 0), | |
| }; | |
| node.filterDirty = true; | |
| } | |
| std::string toString() const { | |
| return std::string("SetNodeSurfaceFilterOp handle=") + to_string(handle); | |
| } | |
| }; | |
| SetNodeSurfaceFilterOp* createSetNodeSurfaceFilterOp(RenderCommandBuffer& region, | |
| OoprNodeHandle handle, const SkIRect& subset, | |
| const SkIRect& clipBounds, | |
| const SkPaint& paint, | |
| OoprClientCache* clientCache) { | |
| SetNodeSurfaceFilterOp* op = allocSceneOp<SetNodeSurfaceFilterOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| op->subset = subset; | |
| op->clipBounds = clipBounds; | |
| OP_REQUIRE(toShmemPaint(region, paint, op->paint, clientCache)); | |
| return op; | |
| } | |
| struct DestroyNodeOp : IPCRenderBufferOp { | |
| OoprNodeHandle handle; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_DestroyNode"); | |
| ctx.cache->nodes.erase(handle); | |
| } | |
| std::string toString() const { | |
| return std::string("DestroyNodeOp handle=") + to_string(handle); | |
| } | |
| }; | |
| DestroyNodeOp* createDestroyNodeOp(RenderCommandBuffer& region, OoprNodeHandle handle) { | |
| ATRACE_NAME("OOPR_expensive_client_DestroyNode"); | |
| DestroyNodeOp* op = allocCleanupOp<DestroyNodeOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| return op; | |
| } | |
| struct CreateBitmapOp : IPCRenderBufferOp { | |
| OoprBitmapHandle handle; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_CreateBitmap"); | |
| auto [it, inserted] = ctx.cache->bitmaps.insert({handle, OoprBitmap{}}); | |
| if (!inserted) { | |
| ALOGE("Bitmap already exists handle=%s", to_string(handle).c_str()); | |
| } | |
| } | |
| std::string toString() const { | |
| return std::string("CreateBitmapOp handle=") + to_string(handle); | |
| } | |
| }; | |
| CreateBitmapOp* createCreateBitmapOp(RenderCommandBuffer& region, OoprBitmapHandle handle) { | |
| ATRACE_NAME("OOPR_expensive_client_CreateBitmap"); | |
| CreateBitmapOp* op = allocSceneOp<CreateBitmapOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| return op; | |
| } | |
| struct SetBitmapHeapBitmapOp : IPCRenderBufferOp { | |
| OoprBitmapHandle handle; | |
| RSpan<uint8_t> pixels; | |
| int32_t width; | |
| int32_t height; | |
| uint32_t colorType; | |
| uint32_t alphaType; | |
| size_t rowBytes; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_FORMAT("OOPR_expensive_server_SetBitmapHeapBitmap %dx%d", width, height); | |
| auto it = ctx.cache->bitmaps.find(handle); | |
| if (it == ctx.cache->bitmaps.end()) { | |
| ALOGE("Failed to find bitmap corresponding to handle=%s", to_string(handle).c_str()); | |
| return; | |
| } | |
| SkImageInfo info = SkImageInfo::Make(width, height, static_cast<SkColorType>(colorType), | |
| static_cast<SkAlphaType>(alphaType)); | |
| SkBitmap bitmap; | |
| if (!bitmap.tryAllocPixels(info, rowBytes)) { | |
| ALOGE("Failed to allocate pixels for bitmap handle=%s", to_string(handle).c_str()); | |
| return; | |
| } | |
| size_t byteSize = bitmap.computeByteSize(); | |
| if (pixels.data.get() && byteSize > 0) { | |
| memcpy(bitmap.getPixels(), pixels.data.get(), std::min<size_t>(byteSize, pixels.size)); | |
| } | |
| it->second.heapBitmap = bitmap; | |
| it->second.graphicBuffer.clear(); | |
| it->second.image.reset(); | |
| } | |
| std::string toString() const { | |
| return std::string("SetBitmapHeapBitmapOp handle=") + to_string(handle); | |
| } | |
| }; | |
| SetBitmapHeapBitmapOp* createSetBitmapHeapBitmapOp(RenderCommandBuffer& region, | |
| OoprBitmapHandle handle, | |
| const SkBitmap& skBitmap) { | |
| ATRACE_FORMAT("OOPR_expensive_client_SetBitmapHeapBitmap %dx%d (%zu bytes)", skBitmap.width(), | |
| skBitmap.height(), skBitmap.computeByteSize()); | |
| SetBitmapHeapBitmapOp* op = allocSceneOp<SetBitmapHeapBitmapOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| op->width = skBitmap.width(); | |
| op->height = skBitmap.height(); | |
| op->colorType = static_cast<uint32_t>(skBitmap.colorType()); | |
| op->alphaType = static_cast<uint32_t>(skBitmap.alphaType()); | |
| op->rowBytes = skBitmap.rowBytes(); | |
| size_t byteSize = skBitmap.computeByteSize(); | |
| if (byteSize > 0) { | |
| OP_REQUIRE(SetRSpan(op->pixels, region, static_cast<const uint8_t*>(skBitmap.getPixels()), | |
| byteSize)); | |
| } | |
| return op; | |
| } | |
| struct SetBitmapGraphicBufferOp : IPCRenderBufferOp { | |
| OoprBitmapHandle handle; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_SetBitmapGraphicBuffer"); | |
| auto it = ctx.cache->bitmaps.find(handle); | |
| if (it == ctx.cache->bitmaps.end()) { | |
| ALOGE("Failed to find bitmap corresponding to handle=%s", to_string(handle).c_str()); | |
| return; | |
| } | |
| auto pendingBinding = ctx.cache->mPendingBitmapBindings.find(handle); | |
| if (pendingBinding == ctx.cache->mPendingBitmapBindings.end()) { | |
| ALOGE("Pending GraphicBuffer not found handle=%s", to_string(handle).c_str()); | |
| return; | |
| } | |
| it->second.graphicBuffer = pendingBinding->second; | |
| ctx.cache->mPendingBitmapBindings.erase(pendingBinding); | |
| it->second.heapBitmap.reset(); | |
| it->second.image.reset(); | |
| } | |
| std::string toString() const { | |
| return std::string("SetBitmapGraphicBufferOp handle=") + to_string(handle); | |
| } | |
| }; | |
| SetBitmapGraphicBufferOp* createSetBitmapGraphicBufferOp(RenderCommandBuffer& region, | |
| OoprBitmapHandle handle) { | |
| ATRACE_NAME("OOPR_expensive_client_SetBitmapGraphicBuffer"); | |
| SetBitmapGraphicBufferOp* op = allocSceneOp<SetBitmapGraphicBufferOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| return op; | |
| } | |
| struct DestroyBitmapOp : IPCRenderBufferOp { | |
| OoprBitmapHandle handle; | |
| void execute(const OoprExecuteContext& ctx) { | |
| ATRACE_NAME("OOPR_expensive_server_DestroyBitmap"); | |
| ctx.cache->bitmaps.erase(handle); | |
| } | |
| std::string toString() const { | |
| return std::string("DestroyBitmapOp handle=") + to_string(handle); | |
| } | |
| }; | |
| DestroyBitmapOp* createDestroyBitmapOp(RenderCommandBuffer& region, OoprBitmapHandle handle) { | |
| ATRACE_NAME("OOPR_expensive_client_DestroyBitmap"); | |
| DestroyBitmapOp* op = allocCleanupOp<DestroyBitmapOp>(region); | |
| OP_REQUIRE(op); | |
| op->handle = handle; | |
| return op; | |
| } | |
| void executeOps(const RList<IPCRenderBufferOp>* opList, const OoprExecuteContext& ctx) { | |
| for (const IPCRenderBufferOp* childOp = opList->mHead; childOp; childOp = childOp->next) { | |
| switch (childOp->type) { | |
| #define X(ty) \ | |
| case kOoprOpType_##ty: \ | |
| ((ty*)childOp)->execute(ctx); \ | |
| break; | |
| OOPR_OP_TYPES | |
| #undef X | |
| default: | |
| ALOGE("Unexpected op in RenderCommandBuffer %d", (int)childOp->type); | |
| } | |
| } | |
| } | |
| bool renderCommandBufferToCanvas(OoprServerCache* cache, | |
| const RenderCommandBufferConsumer* consumer, | |
| SkCanvas* canvas, uint64_t targetFrameId, | |
| OoprRenderFuncs funcs, float alpha) { | |
| std::lock_guard<std::mutex> lock(cache->mLock); | |
| cache->funcs = funcs; | |
| const IpcRenderRegion* ipcRegion = consumer->getRenderRegion(); | |
| if (ipcRegion->mCmds.isEmpty()) { | |
| return false; | |
| } | |
| uint64_t currentFrameId = ipcRegion->mCmds.getLo() + 1; | |
| ATRACE_FORMAT("OOPR_renderCommandBufferToCanvas target=%" PRIu64 " actual=%" PRIu64, | |
| targetFrameId, currentFrameId); | |
| if (targetFrameId != currentFrameId) { | |
| ALOGE("Expected frameId=%" PRIu64 ", actual frameId=%" PRIu64, targetFrameId, | |
| currentFrameId); | |
| } | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("Beginning Server Frame %" PRIu64 " ---------------------------------", | |
| currentFrameId); | |
| } | |
| const OoprFrame* frame = ipcRegion->mCmds.getReadPtr(); | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("DrawingOps:"); | |
| } | |
| OoprExecuteContext drawCtx = OoprExecuteContext::forCanvas(cache, canvas); | |
| bool needsLayer = false; | |
| if (canvas) { | |
| if (alpha != 1.0f) { | |
| needsLayer = true; | |
| ATRACE_BEGIN("OOPR_isolateLayer_alpha"); | |
| canvas->saveLayerAlphaf(nullptr, alpha); | |
| } else if (frame->mRequiresIsolation) { | |
| needsLayer = true; | |
| ATRACE_BEGIN("OOPR_isolateLayer"); | |
| canvas->saveLayer(nullptr, nullptr); | |
| } | |
| } | |
| if (!needsLayer) { | |
| ATRACE_BEGIN("OOPR_direct"); | |
| } | |
| executeOps(&frame->mDrawingOps, drawCtx); | |
| if (needsLayer) { | |
| canvas->restore(); | |
| } | |
| ATRACE_END(); | |
| if constexpr (DUMP_OPS) { | |
| ALOGI("Ending Server Frame %" PRIu64 " ---------------------------------", | |
| currentFrameId); | |
| } | |
| return true; | |
| } | |
| static void executeOffscreenPass(const OoprOffscreenPass* pass, OoprServerCache* cache) { | |
| auto it = cache->nodes.find(pass->handle); | |
| if (it == cache->nodes.end()) { | |
| ALOGE("Offscreen pass node %" PRIu64 " missing from cache!", pass->handle.id); | |
| return; | |
| } | |
| OoprNode& node = it->second; | |
| if (!node.surface) { | |
| ALOGE("Offscreen pass node %" PRIu64 " has no surface!", pass->handle.id); | |
| return; | |
| } | |
| OoprExecuteContext layerCtx = OoprExecuteContext::forCanvas(cache, node.surface->getCanvas()); | |
| executeOps(&pass->drawingOps, layerCtx); | |
| node.image = node.surface->makeTemporaryImage(); | |
| node.filterDirty = true; | |
| } | |
| void drainRenderCommandBuffer(OoprServerCache* cache, RenderCommandBufferConsumer* consumer, | |
| uint64_t targetFrameId, OoprRenderFuncs funcs) { | |
| std::lock_guard<std::mutex> lock(cache->mLock); | |
| cache->funcs = funcs; | |
| IpcRenderRegion* ipcRegion = consumer->getRenderRegion(); | |
| ATRACE_FORMAT("OOPR_drainRenderCommandBuffer %" PRIu64, targetFrameId); | |
| OoprExecuteContext updateCtx = OoprExecuteContext::forCanvas(cache, nullptr); | |
| while (!ipcRegion->mCmds.isEmpty()) { | |
| uint64_t currentFrameId = ipcRegion->mCmds.getLo() + 1; | |
| if (currentFrameId > targetFrameId) { | |
| break; | |
| } | |
| const OoprFrame* frame = ipcRegion->mCmds.getReadPtr(); | |
| if (currentFrameId > ipcRegion->mCmds.getLastDrainedFrameId()) { | |
| ATRACE_FORMAT("OOPR_drainOps %" PRIu64, currentFrameId); | |
| { | |
| ATRACE_NAME("OOPR_sceneOps"); | |
| executeOps(&frame->mSceneOps, updateCtx); | |
| } | |
| { | |
| ATRACE_NAME("OOPR_offscreenPasses"); | |
| for (const auto* pass = frame->mOffscreenPasses.mHead.get(); pass; | |
| pass = pass->next.get()) { | |
| executeOffscreenPass(pass, cache); | |
| } | |
| } | |
| { | |
| ATRACE_NAME("OOPR_updateNodeSnapshots"); | |
| for (auto it = cache->nodes.begin(); it != cache->nodes.end(); ++it) { | |
| updateNodeSnapshotIfRequired(it->second, cache); | |
| } | |
| } | |
| ipcRegion->mCmds.setLastDrainedFrameId(currentFrameId); | |
| } | |
| if (currentFrameId < targetFrameId) { | |
| ATRACE_FORMAT("OOPR_skipFrame %" PRIu64, currentFrameId); | |
| // We skip mDrawingOps because they have no side effect | |
| executeOps(&frame->mCleanupOps, updateCtx); | |
| ipcRegion->mCmds.pop(); | |
| } else { | |
| // Target frame: keep in queue for drawing | |
| break; | |
| } | |
| } | |
| cache->logMetricsLocked(); | |
| } | |
| std::string shmemPaintToString(const ShmemPaint& paint) { | |
| return std::string("ShmemPaint(size=") + std::to_string(paint.data.size) + ")"; | |
| } | |
| std::string opToString(const IPCRenderBufferOp* op) { | |
| switch (op->type) { | |
| #define X(ty) \ | |
| case kOoprOpType_##ty: \ | |
| return ((ty*)op)->toString(); | |
| OOPR_OP_TYPES | |
| #undef X | |
| default: | |
| return "Unknown OP"; | |
| } | |
| } | |
| std::string opTypeToString(uint32_t type) { | |
| switch (type) { | |
| #define X(ty) \ | |
| case kOoprOpType_##ty: \ | |
| return #ty; | |
| OOPR_OP_TYPES | |
| #undef X | |
| default: | |
| return "Unknown op type " + std::to_string(type); | |
| } | |
| } | |
| void dumpPaintToLog(const SkPaint& paint) { | |
| ALOGE("SkPaint Details:"); | |
| ALOGE(" AntiAlias: %s", paint.isAntiAlias() ? "true" : "false"); | |
| ALOGE(" Dither: %s", paint.isDither() ? "true" : "false"); | |
| ALOGE(" Style: %u", (unsigned int)paint.getStyle()); | |
| ALOGE(" Color: 0x%08X", paint.getColor()); | |
| ALOGE(" Alpha: %f", paint.getAlphaf()); | |
| ALOGE(" StrokeWidth: %f", paint.getStrokeWidth()); | |
| ALOGE(" StrokeMiter: %f", paint.getStrokeMiter()); | |
| ALOGE(" StrokeCap: %u", (unsigned int)paint.getStrokeCap()); | |
| ALOGE(" StrokeJoin: %u", (unsigned int)paint.getStrokeJoin()); | |
| if (auto shader = paint.refShader()) { | |
| ALOGE(" Shader: Present"); | |
| } else { | |
| ALOGE(" Shader: None"); | |
| } | |
| if (auto colorFilter = paint.refColorFilter()) { | |
| ALOGE(" ColorFilter: Present"); | |
| } else { | |
| ALOGE(" ColorFilter: None"); | |
| } | |
| if (auto blendMode = paint.asBlendMode()) { | |
| ALOGE(" BlendMode: %u", (unsigned int)blendMode.value()); | |
| } else if (auto blender = paint.refBlender()) { | |
| ALOGE(" Blender: Present"); | |
| } else { | |
| ALOGE(" BlendMode: None"); | |
| } | |
| ALOGE(" Nothing to Draw: %s", paint.nothingToDraw() ? "true" : "false"); | |
| } | |
| std::string skmatrixToString(const SkM44& matrix) { | |
| return std::to_string(matrix.rc(0, 0)) + std::string(" ") + std::to_string(matrix.rc(0, 1)) + | |
| std::string(" ") + std::to_string(matrix.rc(0, 2)) + std::string(" ") + | |
| std::to_string(matrix.rc(0, 3)) + std::string(" ") + std::to_string(matrix.rc(1, 0)) + | |
| std::string(" ") + std::to_string(matrix.rc(1, 1)) + std::string(" ") + | |
| std::to_string(matrix.rc(1, 2)) + std::string(" ") + std::to_string(matrix.rc(1, 3)) + | |
| std::string(" ") + std::to_string(matrix.rc(2, 0)) + std::string(" ") + | |
| std::to_string(matrix.rc(2, 1)) + std::string(" ") + std::to_string(matrix.rc(2, 2)) + | |
| std::string(" ") + std::to_string(matrix.rc(2, 3)) + std::string(" ") + | |
| std::to_string(matrix.rc(3, 0)) + std::string(" ") + std::to_string(matrix.rc(3, 1)) + | |
| std::string(" ") + std::to_string(matrix.rc(3, 2)) + std::string(" ") + | |
| std::to_string(matrix.rc(3, 3)); | |
| } | |
| std::string rectToString(const SkRect& rect) { | |
| return std::to_string(rect.fLeft) + std::string(std::string(" ")) + std::to_string(rect.fTop) + | |
| std::string(std::string(" ")) + std::to_string(rect.fRight) + | |
| std::string(std::string(" ")) + std::to_string(rect.fBottom); | |
| } | |
| IPCRecordingCanvas::IPCRecordingCanvas(OoprClientCache& resourceCache) | |
| : INHERITED(512, 512), mResourceCache(resourceCache) { | |
| mRenderCommandBufferProducer = std::make_shared<RenderCommandBufferProducer>(); | |
| } | |
| bool IPCRecordingCanvas::startRecording(int width, int height) { | |
| OOPR_TRACE_CALL(); | |
| IPC_CANVAS_TRACE_CALL; | |
| if (DUMP_OPS) { | |
| ALOGI("Beginning Client Frame %" PRIu64 " ---------------------------------", | |
| mRenderCommandBufferProducer->getProducerFrameId() + 1); | |
| } | |
| assert(!mIsRecording); | |
| if (!mRenderCommandBufferProducer->startRecording(width, height)) return false; | |
| this->resetCanvas(width, height); | |
| mIsRecording = true; | |
| return true; | |
| } | |
| void IPCRecordingCanvas::endRecording() { | |
| OOPR_TRACE_CALL(); | |
| IPC_CANVAS_TRACE_CALL; | |
| assert(mIsRecording); | |
| mRenderCommandBufferProducer->endRecording(); | |
| mIsRecording = false; | |
| if (DUMP_OPS) { | |
| ALOGI("Ending Client Frame %" PRIu64 " ---------------------------------", | |
| mRenderCommandBufferProducer->getProducerFrameId()); | |
| } | |
| } | |
| void IPCRecordingCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { | |
| IPC_CANVAS_TRACE_CALL; | |
| if (matrix) { | |
| SkAutoCanvasRestore acr(this, true); | |
| this->concat(*matrix); | |
| drawable->draw(this, nullptr); | |
| } else { | |
| drawable->draw(this, nullptr); | |
| } | |
| } | |
| static bool isDestructiveBlendMode(SkBlendMode mode) { | |
| switch (mode) { | |
| case SkBlendMode::kClear: | |
| case SkBlendMode::kSrc: | |
| case SkBlendMode::kSrcIn: | |
| case SkBlendMode::kDstIn: | |
| case SkBlendMode::kSrcOut: | |
| case SkBlendMode::kDstOut: | |
| case SkBlendMode::kDstATop: | |
| case SkBlendMode::kXor: | |
| return true; | |
| default: | |
| return false; | |
| } | |
| } | |
| static void checkBlendModeIsolation(OoprFrame* frame, SkBlendMode mode) { | |
| if (isDestructiveBlendMode(mode) && frame->mCanvasOpRecordingList == &frame->mDrawingOps) { | |
| frame->mRequiresIsolation = true; | |
| } | |
| } | |
| void IPCRecordingCanvas::checkPaintIsolation(const SkPaint* paint) { | |
| if (!paint) return; | |
| if (auto bm = paint->asBlendMode()) { | |
| OoprFrame* frame = mRenderCommandBufferProducer->getRenderRegion()->mCmds.getWritePtr(); | |
| checkBlendModeIsolation(frame, *bm); | |
| } | |
| } | |
| #define OOPR_CHECK_CALL(...) \ | |
| ({ \ | |
| IPC_CANVAS_TRACE_CALL; \ | |
| assert(mIsRecording); \ | |
| auto op_ = (__VA_ARGS__); \ | |
| if (!op_) { \ | |
| ALOGE("%s : Failed create op", __func__); \ | |
| } else { \ | |
| if constexpr (DUMP_OPS) { \ | |
| ALOGI("Recorded %s", opToString(op_).c_str()); \ | |
| } \ | |
| } \ | |
| }) | |
| void IPCRecordingCanvas::willSave() { | |
| OOPR_CHECK_CALL(createSaveOp(getCmdBuffer())); | |
| } | |
| SkCanvas::SaveLayerStrategy IPCRecordingCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { | |
| checkPaintIsolation(rec.fPaint); | |
| OOPR_CHECK_CALL(createSaveLayerOp(getCmdBuffer(), rec.fBounds, rec.fPaint, &mResourceCache)); | |
| return SkCanvas::kNoLayer_SaveLayerStrategy; | |
| } | |
| void IPCRecordingCanvas::willRestore() { | |
| OOPR_CHECK_CALL(createRestoreOp(getCmdBuffer())); | |
| } | |
| bool IPCRecordingCanvas::onDoSaveBehind(const SkRect* subset) { | |
| OOPR_CHECK_CALL(createSaveBehindOp(getCmdBuffer(), subset ? *subset : SkRect::MakeEmpty())); | |
| return true; | |
| } | |
| void IPCRecordingCanvas::didConcat44(const SkM44& m) { | |
| OOPR_CHECK_CALL(createConcatOp(getCmdBuffer(), m)); | |
| } | |
| void IPCRecordingCanvas::didSetM44(const SkM44& m) { | |
| OOPR_CHECK_CALL(createSetMatrixOp(getCmdBuffer(), m)); | |
| } | |
| void IPCRecordingCanvas::didScale(SkScalar sx, SkScalar sy) { | |
| OOPR_CHECK_CALL(createScaleOp(getCmdBuffer(), sx, sy)); | |
| } | |
| void IPCRecordingCanvas::didTranslate(SkScalar tx, SkScalar ty) { | |
| OOPR_CHECK_CALL(createTranslateOp(getCmdBuffer(), tx, ty)); | |
| } | |
| void IPCRecordingCanvas::onClipRect(const SkRect& r, SkClipOp o, ClipEdgeStyle s) { | |
| OOPR_CHECK_CALL(createClipRectOp(getCmdBuffer(), r, o, s == kSoft_ClipEdgeStyle)); | |
| } | |
| void IPCRecordingCanvas::onClipRRect(const SkRRect& r, SkClipOp o, ClipEdgeStyle s) { | |
| OOPR_CHECK_CALL(createClipRRectOp(getCmdBuffer(), r, o, s == kSoft_ClipEdgeStyle)); | |
| } | |
| void IPCRecordingCanvas::onClipPath(const SkPath& p, SkClipOp o, ClipEdgeStyle s) { | |
| OOPR_CHECK_CALL(createClipPathOp(getCmdBuffer(), p, o, s == kSoft_ClipEdgeStyle)); | |
| } | |
| void IPCRecordingCanvas::onClipShader(sk_sp<SkShader> shader, SkClipOp clipOp) { | |
| OOPR_CHECK_CALL(createClipShaderOp(getCmdBuffer(), shader, clipOp)); | |
| } | |
| void IPCRecordingCanvas::onClipRegion(const SkRegion& r, SkClipOp o) { | |
| OOPR_CHECK_CALL(createClipRegionOp(getCmdBuffer(), r, o)); | |
| } | |
| void IPCRecordingCanvas::onResetClip() { | |
| OOPR_CHECK_CALL(createResetClipOp(getCmdBuffer())); | |
| } | |
| void IPCRecordingCanvas::onDrawPaint(const SkPaint& p) { | |
| checkPaintIsolation(p); | |
| OOPR_CHECK_CALL(createDrawPaintOp(getCmdBuffer(), p, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawBehind(const SkPaint& p) { | |
| checkPaintIsolation(p); | |
| OOPR_CHECK_CALL(createDrawBehindOp(getCmdBuffer(), p, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawPathOp(getCmdBuffer(), path, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawRectOp(getCmdBuffer(), rect, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawRegionOp(getCmdBuffer(), region, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawOvalOp(getCmdBuffer(), oval, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, | |
| bool useCenter, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawArcOp(getCmdBuffer(), oval, startAngle, sweepAngle, useCenter, paint, | |
| &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawRRect(const SkRRect& rect, const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawRRectOp(getCmdBuffer(), rect, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | |
| const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawTextBlobOp(getCmdBuffer(), blob, x, y, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawImage2(const SkImage* image, SkScalar x, SkScalar y, | |
| const SkSamplingOptions& sampling, const SkPaint* paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL( | |
| createDrawImageOp(getCmdBuffer(), image, x, y, sampling, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawImageRect2(const SkImage* image, const SkRect& src, | |
| const SkRect& dst, const SkSamplingOptions& sampling, | |
| const SkPaint* paint, SrcRectConstraint constraint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawImageRectOp(getCmdBuffer(), image, src, dst, sampling, paint, | |
| constraint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], | |
| const SkPoint texCoords[4], SkBlendMode mode, | |
| const SkPaint& paint) { | |
| OoprFrame* frame = mRenderCommandBufferProducer->getRenderRegion()->mCmds.getWritePtr(); | |
| checkBlendModeIsolation(frame, mode); | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawPatchOp(getCmdBuffer(), cubics, colors, texCoords, mode, paint, | |
| &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], | |
| const SkPaint& paint) { | |
| checkPaintIsolation(paint); | |
| OOPR_CHECK_CALL(createDrawPointsOp(getCmdBuffer(), mode, count, pts, paint, &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { | |
| OOPR_CHECK_CALL(createDrawShadowRecOp(getCmdBuffer(), path, rec)); | |
| } | |
| void IPCRecordingCanvas::beginRenderTarget(OoprNodeHandle handle) { | |
| OOPR_TRACE_CALL(); | |
| OoprFrame* frame = mRenderCommandBufferProducer->getRenderRegion()->mCmds.getWritePtr(); | |
| OoprOffscreenPass* pass = getCmdBuffer().alloc<OoprOffscreenPass>(); | |
| if (!pass) { | |
| ALOGE("beginRenderTarget: failed to allocate OoprOffscreenPass"); | |
| return; | |
| } | |
| *pass = {}; | |
| pass->handle = handle; | |
| frame->mOffscreenPasses.pushBack(pass); | |
| frame->mCanvasOpRecordingList = &pass->drawingOps; | |
| } | |
| void IPCRecordingCanvas::endRenderTarget() { | |
| OOPR_TRACE_CALL(); | |
| OoprFrame* frame = mRenderCommandBufferProducer->getRenderRegion()->mCmds.getWritePtr(); | |
| frame->mCanvasOpRecordingList = &frame->mDrawingOps; | |
| } | |
| void IPCRecordingCanvas::createNode(OoprNodeHandle handle) { | |
| OOPR_CHECK_CALL(createCreateNodeOp(getCmdBuffer(), handle)); | |
| } | |
| void IPCRecordingCanvas::setNodeSurface(OoprNodeHandle handle, int32_t width, int32_t height) { | |
| OOPR_CHECK_CALL(createSetNodeSurfaceOp(getCmdBuffer(), handle, width, height)); | |
| } | |
| void IPCRecordingCanvas::setNodeSurfaceFilter(OoprNodeHandle handle, const SkIRect& subset, | |
| const SkIRect& clipBounds, const SkPaint& paint) { | |
| OOPR_CHECK_CALL(createSetNodeSurfaceFilterOp(getCmdBuffer(), handle, subset, clipBounds, paint, | |
| &mResourceCache)); | |
| } | |
| void IPCRecordingCanvas::createBitmap(OoprBitmapHandle bitmap) { | |
| OOPR_CHECK_CALL(createCreateBitmapOp(getCmdBuffer(), bitmap)); | |
| } | |
| void IPCRecordingCanvas::setBitmapHeapBitmap(OoprBitmapHandle bitmap, const SkBitmap& bitmapData) { | |
| OOPR_CHECK_CALL(createSetBitmapHeapBitmapOp(getCmdBuffer(), bitmap, bitmapData)); | |
| } | |
| void IPCRecordingCanvas::setBitmapGraphicBuffer(OoprBitmapHandle bitmap) { | |
| OOPR_CHECK_CALL(createSetBitmapGraphicBufferOp(getCmdBuffer(), bitmap)); | |
| } | |
| void IPCRecordingCanvas::destroyBitmap(OoprBitmapHandle bitmap) { | |
| OOPR_CHECK_CALL(createDestroyBitmapOp(getCmdBuffer(), bitmap)); | |
| } | |
| void IPCRecordingCanvas::destroyNode(OoprNodeHandle handle) { | |
| OOPR_CHECK_CALL(createDestroyNodeOp(getCmdBuffer(), handle)); | |
| } | |
| void IPCRecordingCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode, | |
| const SkPaint& paint) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| void IPCRecordingCanvas::onDrawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| void IPCRecordingCanvas::onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], | |
| const SkColor[], int, SkBlendMode, const SkSamplingOptions&, | |
| const SkRect*, const SkPaint*) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| void IPCRecordingCanvas::onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| void IPCRecordingCanvas::onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| void IPCRecordingCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { | |
| OOPR_CHECK_CALL(createDrawAnnotationOp(getCmdBuffer(), rect, key, value)); | |
| } | |
| void IPCRecordingCanvas::onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, | |
| SkFilterMode, const SkPaint*) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| } | |
| sk_sp<SkSurface> IPCRecordingCanvas::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) { | |
| IPCRENDERBUFFER_UNIMPLEMENTED; | |
| return nullptr; | |
| } | |
| } // namespace android | |
| #pragma clang diagnostic pop |