skia2/include/utils/SkCamera.h

155 lines
3.8 KiB
C
Raw Normal View History

/*
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
* Copyright 2006 The Android Open Source Project
*
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Inspired by Rob Johnson's most excellent QuickDraw GX sample code
#ifndef SkCamera_DEFINED
#define SkCamera_DEFINED
#include "../private/SkNoncopyable.h"
#include "SkMatrix.h"
class SkCanvas;
struct SkUnit3D {
SkScalar fX, fY, fZ;
void set(SkScalar x, SkScalar y, SkScalar z) {
fX = x; fY = y; fZ = z;
}
static SkScalar Dot(const SkUnit3D&, const SkUnit3D&);
static void Cross(const SkUnit3D&, const SkUnit3D&, SkUnit3D* cross);
};
struct SkPoint3D {
SkScalar fX, fY, fZ;
void set(SkScalar x, SkScalar y, SkScalar z) {
fX = x; fY = y; fZ = z;
}
SkScalar normalize(SkUnit3D*) const;
};
typedef SkPoint3D SkVector3D;
struct SkMatrix3D {
SkScalar fMat[3][4];
void reset();
void setRow(int row, SkScalar a, SkScalar b, SkScalar c, SkScalar d = 0) {
SkASSERT((unsigned)row < 3);
fMat[row][0] = a;
fMat[row][1] = b;
fMat[row][2] = c;
fMat[row][3] = d;
}
void setRotateX(SkScalar deg);
void setRotateY(SkScalar deg);
void setRotateZ(SkScalar deg);
void setTranslate(SkScalar x, SkScalar y, SkScalar z);
void preRotateX(SkScalar deg);
void preRotateY(SkScalar deg);
void preRotateZ(SkScalar deg);
void preTranslate(SkScalar x, SkScalar y, SkScalar z);
void setConcat(const SkMatrix3D& a, const SkMatrix3D& b);
void mapPoint(const SkPoint3D& src, SkPoint3D* dst) const;
void mapVector(const SkVector3D& src, SkVector3D* dst) const;
void mapPoint(SkPoint3D* v) const {
this->mapPoint(*v, v);
}
void mapVector(SkVector3D* v) const {
this->mapVector(*v, v);
}
};
class SkPatch3D {
public:
SkPatch3D();
void reset();
void transform(const SkMatrix3D&, SkPatch3D* dst = nullptr) const;
// dot a unit vector with the patch's normal
SkScalar dotWith(SkScalar dx, SkScalar dy, SkScalar dz) const;
SkScalar dotWith(const SkVector3D& v) const {
return this->dotWith(v.fX, v.fY, v.fZ);
}
// deprecated, but still here for animator (for now)
void rotate(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {}
void rotateDegrees(SkScalar /*x*/, SkScalar /*y*/, SkScalar /*z*/) {}
private:
public: // make public for SkDraw3D for now
SkVector3D fU, fV;
SkPoint3D fOrigin;
friend class SkCamera3D;
};
class SkCamera3D {
public:
SkCamera3D();
void reset();
void update();
void patchToMatrix(const SkPatch3D&, SkMatrix* matrix) const;
SkPoint3D fLocation; // origin of the camera's space
SkPoint3D fAxis; // view direction
SkPoint3D fZenith; // up direction
SkPoint3D fObserver; // eye position (may not be the same as the origin)
private:
mutable SkMatrix fOrientation;
mutable bool fNeedToUpdate;
void doUpdate() const;
};
class SK_API Sk3DView : SkNoncopyable {
public:
Sk3DView();
~Sk3DView();
void save();
void restore();
void translate(SkScalar x, SkScalar y, SkScalar z);
void rotateX(SkScalar deg);
void rotateY(SkScalar deg);
void rotateZ(SkScalar deg);
Generate Android Framework host-side Skia (linux) Bug: b/118742766 Update gn_to_bp to write an Android.bp file that will build a host-side Skia library. Switch some methods from SK_BUILD_FOR_ANDROID to SK_BUILD_FOR_ANDROID_FRAMEWORK. Prior reviews were done at ag/5482397. gn_to_bp.py: - Run GN twice - once for android and once for linux - Disable GPU (depends on a to-be-written host side GL target) and HEIF (which relies on Android hardware) on linux - TODO: Turn on GPU on linux - Split sources into everywhere, android-only, and linux-only. It seems that Android.bp does not allow using the same cpp file in multiple targets. - note that we currently *only* divide out the sources. The cflags are the same (except for a couple manual ones) and include directories are mostly the same (again, except for manual ones). Android has a "gpu" include directory, which I don't expect to make a difference to the linux build, which isn't using GPU (yet). - Use the same "custom empty" font manager on the host as on Android - Write separate SkUserConfig files; one for android and one for linux. This allows libskia to force libraries that use it to use the right defines by setting export_include_dirs. - Add extra checks to SkUserConfig.h to ensure we have only the appropriate SK_BUILD_FOR macro defined - Add host_supported: true for libskia gn_to_bp_utils.py: - Switch SkUserConfig.h from include guards to pragma once so it is easier to append to the end. This matches how Android generally includes headers. BUILD.gn: - Add skia_use_fixed_gamma_text so host build can use the same SK_GAMMA defines as the device. SkPreConfig.h: - Stop making SK_BUILD_FOR_ANDROID_FRAMEWORK imply SK_BUILD_FOR_ANDROID. The host build needs the former defined but not the latter. SkRegion.cpp/.h: - Make toString() SK_BUILD_FOR_ANDROID_FRAMEWORK so it can be called on the host. SkCamera.h/.cpp: - Switch methods to SK_BUILD_FOR_ANDROID_FRAMEWORK so they can be called on the host. - Make getCameraLocation*() const. They are logically const, and this allows removing a const_cast + TODO in hwui. Change-Id: I771f825d06380e01c0488fd1c00df1d8a2454dc0 Reviewed-on: https://skia-review.googlesource.com/c/171231 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
2018-11-15 20:54:59 +00:00
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
void setCameraLocation(SkScalar x, SkScalar y, SkScalar z);
Generate Android Framework host-side Skia (linux) Bug: b/118742766 Update gn_to_bp to write an Android.bp file that will build a host-side Skia library. Switch some methods from SK_BUILD_FOR_ANDROID to SK_BUILD_FOR_ANDROID_FRAMEWORK. Prior reviews were done at ag/5482397. gn_to_bp.py: - Run GN twice - once for android and once for linux - Disable GPU (depends on a to-be-written host side GL target) and HEIF (which relies on Android hardware) on linux - TODO: Turn on GPU on linux - Split sources into everywhere, android-only, and linux-only. It seems that Android.bp does not allow using the same cpp file in multiple targets. - note that we currently *only* divide out the sources. The cflags are the same (except for a couple manual ones) and include directories are mostly the same (again, except for manual ones). Android has a "gpu" include directory, which I don't expect to make a difference to the linux build, which isn't using GPU (yet). - Use the same "custom empty" font manager on the host as on Android - Write separate SkUserConfig files; one for android and one for linux. This allows libskia to force libraries that use it to use the right defines by setting export_include_dirs. - Add extra checks to SkUserConfig.h to ensure we have only the appropriate SK_BUILD_FOR macro defined - Add host_supported: true for libskia gn_to_bp_utils.py: - Switch SkUserConfig.h from include guards to pragma once so it is easier to append to the end. This matches how Android generally includes headers. BUILD.gn: - Add skia_use_fixed_gamma_text so host build can use the same SK_GAMMA defines as the device. SkPreConfig.h: - Stop making SK_BUILD_FOR_ANDROID_FRAMEWORK imply SK_BUILD_FOR_ANDROID. The host build needs the former defined but not the latter. SkRegion.cpp/.h: - Make toString() SK_BUILD_FOR_ANDROID_FRAMEWORK so it can be called on the host. SkCamera.h/.cpp: - Switch methods to SK_BUILD_FOR_ANDROID_FRAMEWORK so they can be called on the host. - Make getCameraLocation*() const. They are logically const, and this allows removing a const_cast + TODO in hwui. Change-Id: I771f825d06380e01c0488fd1c00df1d8a2454dc0 Reviewed-on: https://skia-review.googlesource.com/c/171231 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
2018-11-15 20:54:59 +00:00
SkScalar getCameraLocationX() const;
SkScalar getCameraLocationY() const;
SkScalar getCameraLocationZ() const;
#endif
void getMatrix(SkMatrix*) const;
void applyToCanvas(SkCanvas*) const;
SkScalar dotWithNormal(SkScalar dx, SkScalar dy, SkScalar dz) const;
private:
struct Rec {
Rec* fNext;
SkMatrix3D fMatrix;
};
Rec* fRec;
Rec fInitialRec;
SkCamera3D fCamera;
};
#endif