Loading core/jni/android/graphics/Picture.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ Canvas* Picture::beginRecording(int width, int height) { mWidth = width; mHeight = height; SkCanvas* canvas = mRecorder->beginRecording(SkIntToScalar(width), SkIntToScalar(height)); return Canvas::create_canvas(canvas); return Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer); } void Picture::endRecording() { Loading core/jni/android/graphics/pdf/PdfDocument.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "CreateJavaOutputStreamAdaptor.h" #include "SkColorSpaceXformCanvas.h" #include "SkDocument.h" #include "SkPicture.h" #include "SkPictureRecorder.h" Loading Loading @@ -94,8 +95,10 @@ public: SkCanvas* canvas = document->beginPage(page->mWidth, page->mHeight, &(page->mContentRect)); std::unique_ptr<SkCanvas> toSRGBCanvas = SkCreateColorSpaceXformCanvas(canvas, SkColorSpace::MakeSRGB()); canvas->drawPicture(page->mPicture); toSRGBCanvas->drawPicture(page->mPicture); document->endPage(); } Loading Loading @@ -128,7 +131,7 @@ static jlong nativeStartPage(JNIEnv* env, jobject thiz, jlong documentPtr, PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); SkCanvas* canvas = document->startPage(pageWidth, pageHeight, contentLeft, contentTop, contentRight, contentBottom); return reinterpret_cast<jlong>(Canvas::create_canvas(canvas)); return reinterpret_cast<jlong>(Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer)); } static void nativeFinishPage(JNIEnv* env, jobject thiz, jlong documentPtr) { Loading libs/hwui/SkiaCanvas.cpp +18 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "hwui/MinikinUtils.h" #include "pipeline/skia/AnimatedDrawables.h" #include <SkColorSpaceXformCanvas.h> #include <SkDrawable.h> #include <SkDeque.h> #include <SkDrawFilter.h> Loading @@ -44,18 +45,22 @@ Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { return new SkiaCanvas(bitmap); } Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) { return new SkiaCanvas(skiaCanvas); Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB) { return new SkiaCanvas(skiaCanvas, xformToSRGB); } SkiaCanvas::SkiaCanvas() {} SkiaCanvas::SkiaCanvas(SkCanvas* canvas) : mCanvas(canvas) {} SkiaCanvas::SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB) : mCanvas(canvas) { LOG_ALWAYS_FATAL_IF(XformToSRGB::kImmediate == xformToSRGB); } SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap)); mCanvas = mCanvasOwned.get(); mCanvasWrapper = SkCreateColorSpaceXformCanvas(mCanvasOwned.get(), SkColorSpace::MakeSRGB()); mCanvas = mCanvasWrapper.get(); } SkiaCanvas::~SkiaCanvas() {} Loading Loading @@ -92,19 +97,22 @@ private: }; void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { SkCanvas* newCanvas = new SkCanvas(bitmap); std::unique_ptr<SkCanvas> newCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap)); std::unique_ptr<SkCanvas> newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), SkColorSpace::MakeSRGB()); if (!bitmap.isNull()) { // Copy the canvas matrix & clip state. newCanvas->setMatrix(mCanvas->getTotalMatrix()); newCanvasWrapper->setMatrix(mCanvas->getTotalMatrix()); ClipCopier copier(newCanvas); ClipCopier copier(newCanvasWrapper.get()); mCanvas->replayClips(&copier); } // deletes the previously owned canvas (if any) mCanvasOwned = std::unique_ptr<SkCanvas>(newCanvas); mCanvas = newCanvas; mCanvasOwned = std::move(newCanvas); mCanvasWrapper = std::move(newCanvasWrapper); mCanvas = mCanvasWrapper.get(); // clean up the old save stack mSaveStack.reset(nullptr); Loading libs/hwui/SkiaCanvas.h +6 −1 Original line number Diff line number Diff line Loading @@ -37,8 +37,12 @@ public: * @param canvas SkCanvas to handle calls made to this SkiaCanvas. Must * not be NULL. This constructor does not take ownership, so the caller * must guarantee that it remains valid while the SkiaCanvas is valid. * @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB * color space before drawing. This makes sense for software rendering. * For the picture case, it may make more sense to leave bitmaps as is, * and handle the xform when replaying the picture. */ explicit SkiaCanvas(SkCanvas* canvas); explicit SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB); virtual ~SkiaCanvas(); Loading Loading @@ -181,6 +185,7 @@ private: class Clip; std::unique_ptr<SkCanvas> mCanvasWrapper; // might own a wrapper on the canvas std::unique_ptr<SkCanvas> mCanvasOwned; // might own a canvas we allocated SkCanvas* mCanvas; // we do NOT own this canvas, it must survive us // unless it is the same as mCanvasOwned.get() Loading libs/hwui/hwui/Canvas.h +12 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,15 @@ public: static WARN_UNUSED_RESULT Canvas* create_recording_canvas(int width, int height, uirenderer::RenderNode* renderNode = nullptr); enum class XformToSRGB { // Transform any Bitmaps to the sRGB color space before drawing. kImmediate, // Draw the Bitmap as is. This likely means that we are recording and that the // transform can be handled at playback time. kDefer, }; /** * Create a new Canvas object which delegates to an SkCanvas. * Loading @@ -100,10 +109,12 @@ public: * delegated to this object. This function will call ref() on the * SkCanvas, and the returned Canvas will unref() it upon * destruction. * @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB * color space before drawing. * @return new non-null Canvas Object. The type of DisplayList produced by this canvas is * determined based on Properties::getRenderPipelineType(). */ static Canvas* create_canvas(SkCanvas* skiaCanvas); static Canvas* create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB); /** * Provides a Skia SkCanvas interface that acts as a proxy to this Canvas. Loading Loading
core/jni/android/graphics/Picture.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ Canvas* Picture::beginRecording(int width, int height) { mWidth = width; mHeight = height; SkCanvas* canvas = mRecorder->beginRecording(SkIntToScalar(width), SkIntToScalar(height)); return Canvas::create_canvas(canvas); return Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer); } void Picture::endRecording() { Loading
core/jni/android/graphics/pdf/PdfDocument.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "CreateJavaOutputStreamAdaptor.h" #include "SkColorSpaceXformCanvas.h" #include "SkDocument.h" #include "SkPicture.h" #include "SkPictureRecorder.h" Loading Loading @@ -94,8 +95,10 @@ public: SkCanvas* canvas = document->beginPage(page->mWidth, page->mHeight, &(page->mContentRect)); std::unique_ptr<SkCanvas> toSRGBCanvas = SkCreateColorSpaceXformCanvas(canvas, SkColorSpace::MakeSRGB()); canvas->drawPicture(page->mPicture); toSRGBCanvas->drawPicture(page->mPicture); document->endPage(); } Loading Loading @@ -128,7 +131,7 @@ static jlong nativeStartPage(JNIEnv* env, jobject thiz, jlong documentPtr, PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr); SkCanvas* canvas = document->startPage(pageWidth, pageHeight, contentLeft, contentTop, contentRight, contentBottom); return reinterpret_cast<jlong>(Canvas::create_canvas(canvas)); return reinterpret_cast<jlong>(Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer)); } static void nativeFinishPage(JNIEnv* env, jobject thiz, jlong documentPtr) { Loading
libs/hwui/SkiaCanvas.cpp +18 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "hwui/MinikinUtils.h" #include "pipeline/skia/AnimatedDrawables.h" #include <SkColorSpaceXformCanvas.h> #include <SkDrawable.h> #include <SkDeque.h> #include <SkDrawFilter.h> Loading @@ -44,18 +45,22 @@ Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { return new SkiaCanvas(bitmap); } Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) { return new SkiaCanvas(skiaCanvas); Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB) { return new SkiaCanvas(skiaCanvas, xformToSRGB); } SkiaCanvas::SkiaCanvas() {} SkiaCanvas::SkiaCanvas(SkCanvas* canvas) : mCanvas(canvas) {} SkiaCanvas::SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB) : mCanvas(canvas) { LOG_ALWAYS_FATAL_IF(XformToSRGB::kImmediate == xformToSRGB); } SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap)); mCanvas = mCanvasOwned.get(); mCanvasWrapper = SkCreateColorSpaceXformCanvas(mCanvasOwned.get(), SkColorSpace::MakeSRGB()); mCanvas = mCanvasWrapper.get(); } SkiaCanvas::~SkiaCanvas() {} Loading Loading @@ -92,19 +97,22 @@ private: }; void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { SkCanvas* newCanvas = new SkCanvas(bitmap); std::unique_ptr<SkCanvas> newCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap)); std::unique_ptr<SkCanvas> newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), SkColorSpace::MakeSRGB()); if (!bitmap.isNull()) { // Copy the canvas matrix & clip state. newCanvas->setMatrix(mCanvas->getTotalMatrix()); newCanvasWrapper->setMatrix(mCanvas->getTotalMatrix()); ClipCopier copier(newCanvas); ClipCopier copier(newCanvasWrapper.get()); mCanvas->replayClips(&copier); } // deletes the previously owned canvas (if any) mCanvasOwned = std::unique_ptr<SkCanvas>(newCanvas); mCanvas = newCanvas; mCanvasOwned = std::move(newCanvas); mCanvasWrapper = std::move(newCanvasWrapper); mCanvas = mCanvasWrapper.get(); // clean up the old save stack mSaveStack.reset(nullptr); Loading
libs/hwui/SkiaCanvas.h +6 −1 Original line number Diff line number Diff line Loading @@ -37,8 +37,12 @@ public: * @param canvas SkCanvas to handle calls made to this SkiaCanvas. Must * not be NULL. This constructor does not take ownership, so the caller * must guarantee that it remains valid while the SkiaCanvas is valid. * @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB * color space before drawing. This makes sense for software rendering. * For the picture case, it may make more sense to leave bitmaps as is, * and handle the xform when replaying the picture. */ explicit SkiaCanvas(SkCanvas* canvas); explicit SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB); virtual ~SkiaCanvas(); Loading Loading @@ -181,6 +185,7 @@ private: class Clip; std::unique_ptr<SkCanvas> mCanvasWrapper; // might own a wrapper on the canvas std::unique_ptr<SkCanvas> mCanvasOwned; // might own a canvas we allocated SkCanvas* mCanvas; // we do NOT own this canvas, it must survive us // unless it is the same as mCanvasOwned.get() Loading
libs/hwui/hwui/Canvas.h +12 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,15 @@ public: static WARN_UNUSED_RESULT Canvas* create_recording_canvas(int width, int height, uirenderer::RenderNode* renderNode = nullptr); enum class XformToSRGB { // Transform any Bitmaps to the sRGB color space before drawing. kImmediate, // Draw the Bitmap as is. This likely means that we are recording and that the // transform can be handled at playback time. kDefer, }; /** * Create a new Canvas object which delegates to an SkCanvas. * Loading @@ -100,10 +109,12 @@ public: * delegated to this object. This function will call ref() on the * SkCanvas, and the returned Canvas will unref() it upon * destruction. * @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB * color space before drawing. * @return new non-null Canvas Object. The type of DisplayList produced by this canvas is * determined based on Properties::getRenderPipelineType(). */ static Canvas* create_canvas(SkCanvas* skiaCanvas); static Canvas* create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB); /** * Provides a Skia SkCanvas interface that acts as a proxy to this Canvas. Loading